Code map: the folder tree
Code version: DeepInfer @ 9bd9cf2 · 2026-10-21
Purpose#
This page is a map of the whole repository. Use it to find where a part of DeepInfer lives before you read its code. Click a folder to open it. Each folder shows its number of files, its number of lines, a short description and links to the pages that explain it.
- Total: 342 files and 63,629 text lines at commit
9bd9cf2. - The engine package
deepinfer/has 223 files and 47,174 lines: three quarters of all lines. - The C++ code in
csrc/has 33 files and 5,908 lines. - The kernel libraries are not in the repository.
vendor/holds six empty git submodules.
The folder tree#
Counts include all files below a folder. "Lines" are text lines, as wc -l counts them. Images count as files with 0 lines.
DeepInfer/342 files · 63,629 lines
The repository root. 14 files at the top level (889 lines): the build entry
build.sh,setup.py, theMakefile, fourrequirements*.txtfiles,pyproject.toml,README.md,CONTRIBUTING.md,LICENSE,.gitmodules,.gitignoreand.clang-format.deepinfer/223 files · 47,174 linesPython
The Python package. It holds all code that runs at inference time, except the C++ extension and the kernel libraries. Start with entrypoints/llm.py and engine/llm_engine.py: the LLMEngine class.
(top-level files)16 files · 2,467 lines
config.pyholds the four config classes:ModelConfig,CacheConfig,ParallelConfigandSchedulerConfig(deepinfer/config.py:19,deepinfer/config.py:125,deepinfer/config.py:150,deepinfer/config.py:185).environ.pydefines everyDEEPINFER_*variable (deepinfer/environ.py:97).platform.pyhides the NVIDIA and Ascend differences.sequence.pyre-exports the C++Sequenceand definesSamplerOutput(deepinfer/sequence.py:14-20,deepinfer/sequence.py:172).Pages: config.py · environ.py · platform.py · sequence.py · sampling_params.py · shared_memory.py · Environment variables
_C/4 files · 819 lines
Type stubs (
.pyi) for the C++ extensiondeepinfer._C.engine.pyilists every C++ class and function that Python can call (deepinfer/_C/engine.pyi:8).Pages: _C/engine.pyi · C++ engine API · The Python and C++ boundary
entrypoints/2 files · 198 lines
The user API: the class
LLMwithgenerate()(deepinfer/entrypoints/llm.py:23). This release has offline inference only.Pages: entrypoints/llm.py · Offline API and the step loop · Tour: Life of a request
engine/6 files · 1,957 lines
LLMEngine,EngineArgs,EngineType, the statistics logger and a profiling HTTP server (deepinfer/engine/stats_logger.py:1,deepinfer/engine/profile_server.py:1).Pages: engine/llm_engine.py: the LLMEngine class · engine/stats_logger.py · Offline API and the step loop
worker/10 files · 2,805 lines
One
Workerper device. It sets up the process, loads the model, owns the KV cache tensors and runs each step: forward, post-process, sample (deepinfer/worker/base.py:4,deepinfer/worker/worker.py:4).ModelRunnerprepares the inputs and replays CUDA graphs.Pages: worker/base.py · worker/worker.py · worker/model_runner.py · worker/cache_engine.py · worker/cuda_graph_runner.py · CUDA graphs · Zero-overhead scheduling (ZOS)
model_executor/157 files · 35,307 lines
The model, its layers, its kernels and the parallel communication. This is the largest folder.
(top-level files)7 files · 611 lines
Model selection and loading (
deepinfer/model_executor/model_loader.py:4), model metadata such as the block size of 128 tokens (deepinfer/model_executor/model_metadata_utils.py:133-135), and sampling inputs.Pages: model_loader.py · Weight loading
models/34 files · 7,051 lines
The DeepSeek-V4.1 model. The registry has one architecture,
DeepseekV41ForCausalLM, and maps it to the vision-language classDeepseekVLForCausalLM(deepinfer/model_executor/models/__init__.py:15-17).Pages: deepseek.py · decoder_layer.py · deepseek_vl.py · Model map · Inside one decoder layer
v4_modules/24 files · 5,197 lines
The parts of one layer: attention, compressed KV, the sparse indexer, mHC, MoE and Engram. The files have four roles: parameter containers, runtime forward code, tensor operators, and topology from the config (
deepinfer/model_executor/models/v4_modules/__init__.py:3-20).Pages: v4_modules/attn.py · v4_modules/mla_attn.py · v4_modules/index_attn.py · v4_modules/compress.py · v4_modules/cross_layer.py · v4_modules/hc.py · v4_modules/mlp.py · v4_modules/engram.py
Concepts: MLA attention · Sparse attention with an indexer · KV compression · mHC residual mixing · MoE routing · Mega-MoE · Engram n-gram memory
mtp/2 files · 392 lines
The DFlash draft model for speculative decoding, with a confidence head (
deepinfer/model_executor/models/mtp/dflash.py:46,deepinfer/model_executor/models/mtp/dflash.py:82).DeepseekForCausalLMmakes it asMTP_module(deepinfer/model_executor/models/deepseek.py:302).Pages: mtp/dflash.py · Speculative decoding · DSpark confidence scheduling
vision_encoder/4 files · 394 lines
The ViT image encoder and the aligner that maps image features into the language model (
deepinfer/model_executor/models/vision_encoder/vit.py:1).Pages: vision_encoder/vit.py · Vision encoder (VL)
layers/102 files · 24,996 lines
Shared layers: the sampler (
deepinfer/model_executor/layers/sampler.py:4), FP8 linear layers, rotary embedding, norms and the pool for draft-token data. Most lines are kernels intilelang_ops/.Pages: sampler.py · linear.py · The sampler · Low-precision formats
tilelang_ops/93 files · 23,331 lines
TileLang kernels. The 33 top-level files (10,945 lines) are mostly interface files, plus shared helpers and the dispatcher
ops.py, which loadscuda/orasc/(deepinfer/model_executor/layers/tilelang_ops/ops.py:13-22).__init__.pyis empty.Pages: tilelang_ops/ · TileLang kernels · Hardware platforms: NVIDIA and Ascend
- cuda/ 30 files · 4,968 lines — kernels for NVIDIA (
deepinfer/model_executor/layers/tilelang_ops/cuda/). - asc/ 30 files · 7,418 lines — kernels for Ascend (
deepinfer/model_executor/layers/tilelang_ops/asc/).
- cuda/ 30 files · 4,968 lines — kernels for NVIDIA (
input_metadata/5 files · 1,151 lines
Python classes that hold the input tensors of one step, for example
InputMetadataV4(deepinfer/model_executor/input_metadata/input_metadata.py:218). The C++ code incsrc/engine/input_metadata/fills most of them.Pages: input_metadata/ · Input metadata (varlen batching)
parallel_utils/6 files · 706 lines
Process groups for data, context and expert parallelism (
deepinfer/model_executor/parallel_utils/parallel_state.py:196), tensor broadcasts, and the owner of all communication buffers of the model (deepinfer/model_executor/parallel_utils/userbuffer.py:54-55).Pages: parallel_state.py · userbuffer.py · Context parallelism (mirror CP) · Expert parallelism (dispatch/combine)
eplb/3 files · 792 lines
Expert load balancing. Translated docstrings: "MoE load-balancing policy: recompute the placement of physical experts from token statistics" (
deepinfer/model_executor/eplb/policy.py:2) and "move expert weights in place by the old and new physical-to-logical map" (deepinfer/model_executor/eplb/shuffle.py:2).Pages: eplb/ · Expert load balancing (EPLB)
hugging_face/8 files · 1,375 lines
Reads the Hugging Face checkpoint: the config (
deepinfer/hugging_face/config.py:1), the tokenizer (deepinfer/hugging_face/tokenizer.py:1) and the safetensors weights (deepinfer/hugging_face/weights.py:1).Pages: hugging_face/weights.py · Weight loading
ve/9 files · 979 lines
Image pre-processing for the vision encoder ("VE").
MultimodalProcessorruns it in child processes (deepinfer/ve/multimodal_processor.py:93-103).Pages: ve/ (images) · Vision encoder (VL)
structure_output/5 files · 595 lines
Grammar matchers for structured outputs (regex, JSON schema, EBNF). They use the
xgrammarlibrary (deepinfer/structure_output/compiler.py:6-7).Pages: structure_output/ · Structured outputs
distributed/2 files · 461 lines
A message queue over a ring buffer in shared memory, for broadcasts between processes on one machine (
deepinfer/distributed/shm_broadcast.py:33,deepinfer/distributed/shm_broadcast.py:162).Pages: distributed/shm_broadcast.py
npu_ops/4 files · 211 lines
Ascend only. An import hook replaces two vendor functions with NPU versions (
deepinfer/npu_ops/__init__.py:1-12).Pages: npu_ops/ · Hardware platforms: NVIDIA and Ascend
csrc/33 files · 5,908 linesC++
The C++ source of the extension module
deepinfer._C.setup.pycompiles it with pybind11 (setup.py:22-34). The 4 top-level files (290 lines) are the module entry (csrc/pybind.cpp:8-14) and the device helpers for CUDA and Ascend.Pages: The Python and C++ boundary · C++ engine API
engine/22 files · 5,216 lines
The engine core in C++: the scheduler (
scheduler.hpp, 1,329 lines), sequences, the block manager, ZOS input preparation, sampling inputs, request outputs, a FLOPs estimator, and the pybind11 bindings.Pages: scheduler.hpp · sequence.hpp · block_manager.hpp · zos.cpp · prepare_sample.cpp · outputs.hpp · The scheduler · Paged KV cache and block manager
input_metadata/5 files · 1,073 lines
Builds the per-step input tensors for prefill and decode (
csrc/engine/input_metadata/prepare_tensor_input_v4.cpp:20-22).Pages: prepare_tensor_input_v4.cpp · Input metadata (varlen batching)
- graph_timer/ 4 files · 254 lines — timing probes inside CUDA graphs, for CUDA and Ascend (
csrc/pybind.cpp:14). - utils/ 3 files · 148 lines — small headers: a lock wrapper, logging, an object pool (
csrc/utils/).
deep_cluster/8 files · 656 linesPython
Finds the hardware without PyTorch.
hardware/(5 files, 548 lines) detects NVIDIA or Ascend devices from device files (deep_cluster/hardware/__init__.py:1).topology/(2 files, 108 lines) binds processes to NUMA nodes (deep_cluster/topology/__init__.py:1).setup.pyalso uses it (setup.py:10).Pages: deep_cluster/ · Hardware discovery (deep_cluster) · Hardware platforms: NVIDIA and Ascend
examples/18 files · 3,286 lines
Scripts that run the engine.
offline_inference.pyis the README example (README.md:72)._launch.pystarts one process per data-parallel rank (examples/_launch.py:26-50).benchmark.pydrivesllm.llm_engine.step()directly. Sub-folders:sweep/(3 files, 405 lines) for throughput-latency curves,yoco/(3 files, 1,111 lines) to compare the YOCO modes,images/(2 JPEG test images).Pages: Tour: Life of a request · YOCO and SWA bounded replay
eval/17 files · 2,003 lines
Accuracy benchmarks AIME 2026, HLE and GPQA Diamond. Generation and scoring are separate steps (
eval/README.md:3-11). The scripts reuseexamples/_config.pyto make the engine.common/has 7 files (562 lines).tests/20 files · 3,207 lines
pytest tests.
models/(9 files, 1,172 lines) runs the whole model, for example batch invariance and the sampler.worker/(2, 828),engine/(3, 490),distributed/(2, 289) andve/(1, 189) test single parts. Kernel tests are not here: 28 files intilelang_ops/hold their owntest_functions, andconftest.pythere skips a test when the backend has no such kernel (deepinfer/model_executor/layers/tilelang_ops/conftest.py:100-113).scripts/4 files · 194 lines
Build scripts.
build_vendor.shbuilds the vendor libraries (scripts/build_vendor.sh:7-22).build.shbuildscsrc/intodeepinfer/_so/<accelerator>-<arch>/(scripts/build.sh:11-29). Two more scripts format the C++ code and make the.pyistubs.doc/5 files · 312 lines
The deployment Q&A (
inference_deployment_qa.md) and four images: the architecture picture and three performance charts.Pages: FAQ
vendor/0 files here · 6 submodulesnot checked out
Six git submodules: DeepSelect, FlashMLA, DeepEP, DeepGEMM, DeepEP-Ascend and DeepGEMM-Ascend (
.gitmodules). A plain clone leaves the folders empty. This site explains only how DeepInfer calls these libraries, not how they work inside. Two more kernel libraries come from pip:tilelang==0.1.15andtile-kernels==2.1.0(requirements.txt:16-17).
How the folders depend on each other#
Read panel 1 from the top. The arrows go from the code that imports to the code that it imports. No arrow points up: deepinfer/ does not import examples/, eval/ or tests/. 77 files in deepinfer/ import tilelang or tile_kernels, and 18 files import a vendor library: 86 files in all, because some files import both.
Panel 2 shows ./build.sh. It installs the Python requirements, builds the vendor wheels, then builds the C++ extension (build.sh:13-25).
How the numbers were measured#
The counts come from the checkout at commit 9bd9cf2, without the .git folder. Run these commands in the repository root to check them:
find . -path ./.git -prune -o -type f -print | wc -l # 342 files
find deepinfer -type f | wc -l # 223 files
find deepinfer -type f -print0 | xargs -0 grep -Il "" | tr '\n' '\0' | xargs -0 cat | wc -l # 47174 text lines
The import counts come from grep -rlE "^\s*(from|import) (tilelang|tile_kernels)" deepinfer and the same search for deep_ep, deep_gemm, flash_mla and deep_select.