models: Qwen3.8-27B, GLM-5.3 and DeepSeek-V4.1-Flash, experimental (CPU-verified)

SA
9h ago
+24679-106

What and why

Three new model families, each experimental: CPU-verified, not yet run on Trainium2. Each one parses its released
config.json through the real dispatch and loader and matches an upstream reference on CPU, on reduced random
configurations. Nothing here has run on a device, and no device number is claimed. GLM-5.3-Flash is unchanged.

ModelArchitectureWhat landsChecked on CPU (fp32) against
Qwen3.8-27BQwen3_5ForConditionalGeneration (the released composite layout) and Qwen3_5ForCausalLM: Gated DeltaNet + gated attention, denseconfig, decoder and loader; GDN mixer with every state-slot form; gated attention with QK-norm and partial rotary; parserstransformers 5.17.0 qwen3_5. Mixers at 2e-5. One layer at the real head geometry. Shards at tp 2, 4 and 8. Every position's logits at 5e-5. Greedy through LLMEngine at tp 1 and 2 equals transformers. A prefix hit from a GDN state checkpoint equals cold. The released config and tensor names load 851 of 1,199 tensors, skipping exactly the 333 vision and 15 MTP tensors
GLM-5.3GlmMoeDsaForCausalLM: MLA with RoPE, DSA indexer with IndexShare, MoE, FP8config, decoder and loader; latent attention, indexer and IndexShare; exact top-k; MoE on the torch pathtransformers 5.17.0 glm_moe_dsa, on a reduced config where the sparse selection and IndexShare decide the result. Layers at 1e-4, with selections equal. Every position's logits at tp 1, 2 and 4. FP8 block-scaled checkpoints at 1e-4. Greedy through LLMEngine equals transformers. A prefix hit equals cold
DeepSeek-V4.1-FlashDeepseekV41ForCausalLM: window + compressed sparse attention, Engram, mHC, MoE with MXFP4 expertsconfig, decoder and Engram; engine adapter; checkpoint reader with an exact MXFP4→FP8 refit; parsersDeepSeek's released inference code at 2cba9e42, vendored byte for byte and run on CPU in fp32 through torch stand-ins for its 6 GPU kernels; the harness corrects one defect in it (below). The decoder follows the released activation roundings by default (FP8 before quantized linears and on window keys, FP4 on compressed latents and the indexer; TRNRT_DSV41_QUANTIZE=0 for full precision). Released mode: one-chunk prefill and decode bit-equal to the reference, chunk splits within 2.2e-7 of the peak logit, greedy equal. Full precision: logits within 1e-4 of peak (measured about 1e-6) across window and compression boundaries, chunk splits, Engram, the decoder at tp 2 and 4. Through LLMEngine: greedy equals the reference (also tp 2); a prefix hit and a resume from an in-chunk checkpoint equal cold; two requests together equal each alone. The reader equals DeepSeek's convert.py bit for bit and classifies all 96,085 released tensors

Shared pieces:

  • Family dispatch (trnrt/models/families.py). config.json's architecture picks the family, and its module is
    imported only then. GLM-5.3-Flash's parse and loader run first and are untouched.
  • A single-stream decoder base (trnrt/models/plain.py). It implements the runner contract for decoders without
    hyper-connections, so no Flash decoder file is generalised.
  • The engine serves a model with no recurrent state (GLM-5.3). The new SchedulerConfig.recurrent switch is off
    for such a model: it resumes the longest cached page-aligned prefix before the prompt's last token and takes no state
    checkpoints. It runs without the host cache tier, which restores prefixes from state checkpoints, and the engine logs
    that. Flash keeps recurrent=True and schedules as before, and a Flash truncation with no recurrent state is still
    refused.
  • Parsers and chat templates per family.
    • Qwen: qwen3 reasoning and qwen3_coder XML tool calls (vLLM-derived).
    • DeepSeek: deepseek_v41 reasoning and DSML tool calls (from DeepSeek's encoding.py).
    • GLM-5.3: GLM's existing parsers.
    • /model_info, the reasoning_effort check and the --served-model-name default follow the family. Flash
      still gets glm / glm45 / glm47.
    • On 6,000 random GLM-format inputs, the GLM parser streams and parses identically to the old one.
  • DeepSeek's reference has a defect, corrected in the test harness. The released reference reads a stale index
    key in a decode step that leaves a compression group open. The harness corrects it at run time without editing the
    vendored file, and a test pins both behaviours.

Size: about 24.5k lines added. About 6.8k of them are byte-identical vendored files and fixtures:

  • DeepSeek's model.py, engram.py and encoding.py;
  • chat templates and licence texts;
  • encoder goldens and checkpoint header records.

Commits

One per unit, then the review rounds (CodeRabbit, cubic and one Codex round with four focused checks, each finding
answered in its thread):

  1. models: family dispatch
  2. models: the single-stream base and its CPU harness
  3. engine: models with no recurrent state
  4. serve: the new parser formats
  5. serve: the family picks the parsers and templates
  6. models: GLM-5.3
  7. models: Qwen3.5
  8. models: the DeepSeek-V4.1-Flash checkpoint reader
  9. models: DeepSeek-V4.1-Flash
  10. kernels, models: opt-in device paths
  11. docs: the model families
  12. Review fixes. The ones that change behaviour:
    • models without recurrent state run without the host tier instead of refusing (every preset sets it);
    • a Flash truncation without recurrent state is refused as before;
    • an empty --served-model-name is kept;
    • GDN takes its batch form from the block table;
    • GLM-5.3 fused-expert FP8 scales are read, and its absent keys take transformers' defaults;
    • DeepSeek follows the released roundings by default, and its deferred flush has unique destinations;
    • the review also brought small fixes to the DSML parser, the tool and the checkpoint reader, and doc precision

Graphs

  • Host-side only
  • Touches frozen paths. GLM-5.3-Flash's graphs are not expected to move, but this is not proven by
    graph_equiv
    (see below).

Edits to existing frozen files, and nothing else under trnrt/models/ or trnrt/kernels/ changes:

FileEdit
trnrt/models/config.pyfrom_config_dict: an architecture outside glm5_next.ARCHITECTURES is looked up in families.py. Flash's branch is unchanged
trnrt/models/loader.pyload_model: an architecture outside ARCHITECTURES is loaded by its family module. Flash's path is unchanged

All other model and kernel code is new files, imported only through the registry: plain.py, the family modules and
kernels/moe_ep.py.

Non-frozen edits that Flash runs through:

  • engine/scheduler.py: the recurrent switch, default True.
  • engine/engine.py: passes recurrent; without recurrent state, a registered family runs without the host cache tier
    and anything else (a Flash truncation) is refused as before.
  • serve/{parsers,api,native}.py and __main__.py: --served-model-name defaults to the family's name, glm for
    Flash as before. No graph-shape default changes.

Proven locally:

  • Flash's ModelConfig from its config.json is field-for-field the pre-dispatch parse.
  • Importing trnrt, trnrt.models, its loader and decoder, and parsing Flash's config, loads neither the registry
    nor any family module (subprocess test, tests/test_model_families.py).
  • The existing scheduler, radix, checkpoint, host-cache, engine and Flash model tests pass unchanged.

Graph evidence: to run by a maintainer

Not run here. The capture needs a Linux x86_64 host with the Neuron SDK image, and this was built without one. The
commands compare base 8b1a3b03 with this branch's head, for each preset:

REV=eb9eb208eb0d988989d07a6a12d0fdeb5f52574a   # GLM-5.3-Flash
for side in base head; do
  git -C trnrt checkout -q $([ $side = base ] && echo 8b1a3b03 || echo origin/models/qwen38-glm53-dsv41)
  docker build -q -f trnrt/docker/Dockerfile --build-arg TRNRT_VERSION=0.2.0 \
    --build-arg TRNRT_REVISION=$(git -C trnrt rev-parse HEAD) -t trnrt:$side trnrt
done
for preset in latency balanced throughput; do
  for side in base head; do
    OUT=/data/geq/$preset/$side; mkdir -p $OUT/nki        # fresh roots: capture reuses what it finds
    t() { docker run --rm -e HF_TOKEN -v $OUT:$OUT -v $OUT/nki:/var/tmp/nki-intermediate-cache trnrt:$side "$@"; }
    t compile shapes zai-org/GLM-5.3-Flash --revision $REV --out $OUT
    t compile decisions --model zai-org/GLM-5.3-Flash --revision $REV --out $OUT
    t compile capture --out $OUT -- --model $OUT/shapes --preset $preset
  done
  python trnrt/tools/graph_equiv.py /data/geq/$preset/base /data/geq/$preset/head --ref-package trnrt   # expect EQUAL
  for r in $(seq 0 31); do   # and the same ordered cache-key list on every rank
    cmp -s /data/geq/$preset/base/capture/rank$r.json /data/geq/$preset/head/capture/rank$r.json \
      || echo "preset $preset rank $r: keys differ"
  done
done

Accuracy

These models have no device numbers. The CPU checks are summarised in the table above, and each test states its
dimensions, tp and tolerance. Full CPU suite on this tree (macOS, py3.13): 2519 passed, 478 skipped, 2 xfailed,
0 failed; CI's Tests (CPU) on Linux green.
One test was deselected: test_api_prompt_thread.py::test_another_stream_flows_while_a_prompt_renders, a timing test.
It fails 2/2 here on the untouched base 8b1a3b03 as well, under the same load, so CI on Linux is the check for it.

Needs a device run

Nothing below has run on Trainium2. The device-path pieces that can be checked on CPU are in, opt-in and off by
default
:

ModelWhat a bring-up needsIn this PR
Qwen3.8-27BCapture and compile on a CPU host. One engine of 8 ranks (24 query heads do not split over 16). The Gated DeltaNet prefill kernel. Prompt logprobs for a decode-vs-prefill gateTRNRT_QWEN_GDN_KERNEL=1 routes the GDN prefill through kernels/delta_rule.py; its emulate() matches the torch scan at 2.1e-5
GLM-5.3A MoE route at tp 64: public NKI MoE needs 2 × moe_intermediate / tp = 128 and gets 64. Per-piece compiler arguments for decode pieces. MTPTRNRT_GLM_MOE_EP=1, the expert-parallel layout (whole FP8 experts per rank, kernels/moe_ep.py). Its emulation matches the TP layout's greedy tokens at tp 2 and 4, logits within 0.05: the kernel rounds to bf16, and a near-tie between two experts' scores can flip a route. The kernel bodies are traced on a bounds-checking stub, never compiled. tools/check_moe_ep.py --hidden 6144 --inter 2048 --experts 4 --total-experts 256 --topk 8 --rows 16 128 512 checks them on a NeuronCore
DeepSeek-V4.1-FlashPrefill as layer runs: today one graph over all layers, so the indexer's selection never crosses a graph cut. Engram's in-graph hash uses int64 arithmetic. Experts kept FP8 or packed on the device: today dequantized from their FP8 refit. With the released roundings on, a rank's expert and output-projection slices must be whole 32-blocks, which the released expert width is not at 64 ranks (an expert-parallel layout, or TRNRT_DSV41_QUANTIZE=0). DSparkCache and state writes for prefill and decode at 2+ rows go through one flat index_copy_ per tensor at the end of the graph, grouped by string tags, because multi-row scatters of that kind were observed wrong on the device. On CPU this is bit-equal to immediate writes

Left out, because it would touch Flash's frozen runner or capture in ways not provable here:

  • piecewise decode and per-piece compiler arguments;
  • prompt logprobs through the engine;
  • compile-farm decisions and presets for the new models.

Guesses, open to Aman

Where the earlier, unpublished work on these models diverged, these are guesses. Each one is easy to change.

  • DeepSeek-V4.1-Flash head: the model comes from the main development line of that work. The parsers, the
    chat-template test and the encoding reference come from DeepSeek's released files. Product fixes taken from the
    later DeepSeek work:

    • the one-hot vocabulary head;
    • the NaN-safe top-k floor;
    • function-form torch.topk;
    • the deferred flat-copy cache writes with string-tag grouping.

    Nothing comes from the device-experiment work (its megakernels, probes and gates).

  • GLM-5.3 MoE route: expert-parallel (whole experts per rank), not slice-major. CPU runs the torch expert path.

  • Support level: every model lands as "Experimental: CPU-verified, not yet run on Trainium2".

Other notes

  • GLM-5.3's licence is not plain MIT. It is the "GLM-5.3 License": an MIT-style grant plus a security-review
    condition for Model-as-a-Service operators above $10B revenue. Copied verbatim to tests/fixtures/LICENSE-GLM-5.3.
    Its template and config fixtures are listed under it in THIRD_PARTY_NOTICES.md. Please confirm vendoring the
    fixtures under it is fine.
  • Flash's frozen quant.dequant / fit_e4m3_max infer the block width from the scale column count. That is
    wrong when K is more than one block but not a whole number of blocks. Flash's own shapes never hit this, and
    GLM-5.3 carries its own block-aware dequant. Flagged here, not fixed.
  • No model-request issue was opened (CONTRIBUTING asks for one). This PR carries the discussion instead.

Questions for Aman

  1. Device logs for each model: none of the three has a committed trn2 result. Anything you hold sets the first gate.
  2. Confirm the DeepSeek and GLM-5.3 guesses above.
  3. Who runs tools/graph_equiv.py on a Neuron host for the commands above?

Checklist

  • make check equivalent: pre-commit run --all-files clean, mypy clean (139 files), the CPU suite as above
  • Tests cover the change (613 new test cases: 3,002 collected against 2,389 on the base)
  • Docs updated: README model table, docs/MODELS.md (new), docs/ARCHITECTURE.md, docs/CONFIGURATION.md,
    docs/API.md, CHANGELOG.md, THIRD_PARTY_NOTICES.md

Summary by CodeRabbit

  • New Features
    • Added experimental support for Qwen3.8-27B, GLM-5.3, and DeepSeek-V4.1-Flash, validated against CPU references; device performance has not been verified.
    • Chat serving supports model-specific reasoning controls and tool-call formats, and reports parser details for the selected model.
    • Served-model names default to the loaded model’s architecture; explicit names remain supported.
    • Models without recurrent state can resume cached prefixes. Host caching is unavailable for these models; configured host-cache budgets are ignored with a warning.
    • Documented optional device paths for select models; these paths have not been tested on hardware.
  • Documentation
    • Added model support levels, family details, API behavior, and configuration guidance.