| Path | What it holds |
|---|---|
trnrt/__main__.py |
The CLI. serve runs the router plus N engines, engine runs one engine, compile runs the offline pipeline. The three builds (latency, balanced, throughput) and auto, which picks one from the users per engine. |
trnrt/config.py |
EngineConfig: seats, bucket ladders, pool sizes and decode kernel routes. These are graph shapes. |
trnrt/platform.py |
Trainium2 facts, the neuronx-cc argument set and the runtime environment. |
trnrt/metrics.py |
Prometheus text for each engine's /metrics. |
trnrt/serve/api.py |
The OpenAI-compatible server for one engine: request validation, chat template, streaming. |
trnrt/serve/native.py |
The native API on one engine: /generate, the info and load endpoints, /health_generate, /abort_request, /flush_cache. |
trnrt/serve/router.py |
The session-affine, prefix-aware router in front of the engines, with failover. |
trnrt/serve/benchmark_mode.py |
The benchmark mode's announcement: the warning, the /health block and the response header. |
benchmarks/ |
The published points' recipes: builds, serve and client scripts, scorers, accuracy checks. |
trnrt/serve/parsers.py |
GLM reasoning and tool-call parsing, streamed and whole. |
trnrt/serve/responses.py, anthropic.py |
The OpenAI Responses API and the Anthropic Messages API, translated into the chat path. |
trnrt/serve/stats.py, trnrt/serve/dashboard.py |
GET /v1/stats's request rates, latency percentiles and time series per engine, and the page GET /dashboard draws from them. |
trnrt/serve/prodlog.py |
The opt-in production log (TRNRT_PROD_DIR): request records and gauges on disk. |
trnrt/serve/prompt_cache.py |
The opt-in prompt token cache (TRNRT_PROMPT_CACHE_MB): a chat turn's prompt ids from the previous turn's. |
trnrt/engine/engine.py |
LLMEngine: model build, the step loop, start and close. |
trnrt/engine/scheduler.py |
Continuous batching, chunked prefill and prefix-cache restores. |
trnrt/engine/model_runner.py |
Pads each step into a compiled bucket and runs its graph. |
trnrt/engine/radix_cache.py, kv_pool.py, host_cache.py, host_arena.py, state_pool.py |
The prefix cache: a radix tree over FP8 KV pages, the page pool, the host-memory tier (with its moves batched by page run, and, under context-parallel attention, one shared copy of a page per context-parallel index in shared-memory arenas), and linear-attention state rows. |
trnrt/engine/spec_async.py, spec_synth.py |
Speculative decoding: the per-request board of device-side state the next step reads (accepted count, newest token, positions, state row, drafts), and the benchmark mode's synthetic acceptance. |
trnrt/engine/tp.py |
Tensor parallelism. Rank 0 drives, the other ranks follow, through shared memory or gloo. |
trnrt/engine/start_checks.py, start_lock.py, watchdog.py |
Host checks before start (free devices, contiguous host memory, every rank pinnable to its NUMA node), one engine starting at a time, and turning a device hang into a clean exit. |
trnrt/models/ |
GLM-5.3-Flash: the decoder, KDA linear attention, DSA sparse attention, mHC, the MoE, and FP8 loading. The experimental families (MODELS.md): families.py (architecture to family), plain.py (their single-stream decoder base), and each family's modules. |
trnrt/kernels/ |
NKI kernels: decode megakernels, prefill kernels, in-kernel collectives (MEGAKERNELS.md). |
trnrt/compile/ |
The offline pipeline: shapes from safetensors headers, capture of every graph, a neuronx-cc farm, NEFF strip. |
docker/ |
The image (base pinned by digest) and check_image.py, which checks every Neuron piece at build time. |
tools/ |
graph_equiv.py (this code builds the same graphs as a reference), check_mixed.py (on-device output checks), check_docs.py (doc links), bench_router_loop_gap.py (how long the router's event loop stalls under large requests). |
tests/ |
The CPU suite (DEVELOPMENT.md). |
- A client calls the router on
--port(default 8000). Asession_idpins the conversation to one engine. Without one, the router picks the engine that already holds the longest prefix of the prompt. - The engine's API (
serve/api.py) validates the request and renders the chat template. It then hands the request to the engine thread, the only thread that touches engine state. - The scheduler matches the prompt against the radix cache, including pages held in host memory. It then prefills the rest in chunks of up to 4,096 tokens and joins the request to the running decode batch.
- Each step,
ModelRunnerpads the batch to a compiled bucket. Rank 0 broadcasts the call and all 32 ranks run the same compiled graph. Sampling runs on the device. - Tokens stream back through the parser, which splits reasoning from content and tool calls.
A graph depends on the weights' shapes and dtypes, plus the MoE packing decisions that decisions reads from a few
weight values per layer. So trnrt compile builds every graph on a CPU host, from the checkpoint's config,
safetensors headers and those decisions, without downloading the weights:
| Step | Does |
|---|---|
shapes |
Writes a shape directory from the config and safetensors headers (a few MB). |
decisions |
Reads the MoE packing decisions with a few range reads per layer. |
capture |
Traces every graph on all 32 ranks, with the serving arguments. |
compile |
Runs neuronx-cc on each graph, as many at once as host memory admits. |
strip |
Drops the NEFFs' debug info, which two engines need to fit in host memory. |
At start-up an engine loads each graph from the cache. A missing graph fails the start rather than compiling on the serving host. A cache built for other engine arguments, another checkpoint revision, another TrnRT release or another Neuron SDK misses.
GLM-5.3-Flash was the first family; Qwen3.5 (Qwen3.8-27B), GLM-5.3 and DeepSeek-V4.1-Flash are experimental families built the way the table below describes (MODELS.md). The model-facing contract a family meets:
| Layer | GLM-5.3-Flash | Another family |
|---|---|---|
| Config | ModelConfig.from_config_dict tries glm5_next.config_from_hf first |
trnrt/models/families.py maps the architecture to its module, imported only then; the module's config_from_hf returns a ModelConfig subclass carrying its own fields |
| Weights | loader.ARCHITECTURES maps the architecture to DecoderForCausalLM, and the loader knows GLM's tensor names |
the module's load_model: Qwen3.5 and GLM-5.3 build on plain.load (the meta device, then each layer filled from the checkpoint); DeepSeek-V4.1-Flash reads its released format with its own reader (models/dsv41_ckpt.py) |
| Model | ModelRunner calls kv_shapes, bind_kv_cache, aux_kv_shapes, bind_aux_kv, state_shapes, token_state_shapes, forward_decode, forward_prefill, layer_kind and group_fn |
the same methods, from plain.PlainDecoder: by default one residual stream and flat layers whose arithmetic reads their own tensors, so group_fn traces runs of them as it does Flash's. A family may override that: DeepSeek-V4.1-Flash keeps four hyper-connection streams and its group_fn closes over its layers |
| Engine | engine.py sets the KDA and DSA decode routes and resumes prefixes from recurrent-state checkpoints |
a family with recurrent state uses the same checkpoints; one without (every layer attends over its KV cache) resumes the longest cached page-aligned prefix before the prompt's last token (SchedulerConfig.recurrent) and runs without the host cache tier, which restores from state checkpoints |
| Chat | serve/parsers.py parses GLM's reasoning and tool-call format |
families.Family names the reasoning and tool-call parsers and the default --served-model-name |
The router, the page pool, the sampler, tensor parallelism and the compile cache layout do not depend on the model.
The compile pipeline's load-time decisions (trnrt compile decisions) know GLM-5.3-Flash's MoE only. A new family is
imported lazily and edits none of GLM-5.3-Flash's traced files beyond the two host-side dispatch lines, so its graphs
and compile cache are expected to stay as they are; that holds as proven only once tools/graph_equiv.py and identical
cache-key lists show it, which a change to a shared traced file always needs. Open a
model request to discuss a family
before starting on one.