models: run Qwen3.8-27B, GLM-5.3 and DeepSeek-V4.1-Flash on Trainium2

Merged
AM
21h ago
+6770-354

Summary

v0.3.0 shipped three experimental model families that had only run on CPU. This PR runs them on a trn2.48xlarge, fixes
what that surfaced, adds device kernels for Qwen3.8-27B, and gives each family a build (--preset) holding the fastest
configuration that passed its correctness checks.

ModelBuildStatus after this PREvidence
Qwen3.8-27Bqwen38: 8 engines of tp 8, 262,144-token context, its device kernels, decode buckets 1-2 and 2 running an enginePreviewAll 64 layers, 8 in flight: agreement 0.979, mean |dlogprob| 0.0045 vs CPU fp32; recurrent state as close to fp32 as the torch forms; decode vs prefill to 200K tokens: mean 0.0048, p99 0.037, 0 divergences; GSM8K 97.42%; needle 3/3; AgentX at 8 / 16 / 32 users: 12.5 / 20.1 / 25.3 requests a minute, P90 24.8 / 25.4 / 24.2 tok/s per user, every point valid
GLM-5.3glm53: one tp-64 engine, expert-parallel MoE, FP8 KV, 4,096 tokensExperimental: correct at 4,096 tokensFirst 4 layers: mean |dlogprob| 0.026 vs CPU fp32; the whole model runs 16 requests at once, coherent text; decode step 84.8 / 366.2 ms at 1 / 16 rows; GSM8K pending (4,096 tokens cut thinking answers short)
DeepSeek-V4.1-Flashdsv41: one tp-64 engine, 4,096 tokens, experts on the XLA pathExperimental: correct at 4 layersFirst 4 layers: mean |dlogprob| 0.031 vs CPU fp32 (the CPU's own bf16 run: 0.067); the whole model waits on FP8 experts

Why the qwen38 build is configured this way

  • Kernels on. Each route passed its device check alone and together (all 64 layers vs CPU fp32; recurrent state; decode
    vs prefill to 200K tokens). At 8 rows they halve the decode step (52.95 -> 25.45 ms).
  • fp32 head. The bf16 head rounds near-tied logits into exact ties: agreement 0.926 with the bf16 head, 0.998 with
    the fp32 one.
  • Decode buckets 1 and 2, 2 running per engine. Three decode graphs cannot all execute in one engine on this compiler
    (docs/KNOWN_ISSUES.md); 1 and 2 rows ran clean in every order. 8 engines x 2 is 16 requests decoding a box.
  • 10 GiB KV an engine, 2,048-token prefill chunks. From a serving simulation of the AgentX request mix with the
    measured step costs (internal, not calibrated on Qwen; its answers move up to 10% with choices that should not matter).
    It predicted 9-13 requests / min and P90 27-30 tok/s per user at 8 users, 16-19 and 25-27 at 16, 26-30 and 24-25 at
    32; AgentX measured 12.5 / 24.8, 20.1 / 25.4 and 25.3 / 24.2. P90 at 8 users is below its range.
  • At 32 users the 16 seats queue the rest (first token p90 77 s). 4 running per engine is the lever there, once 4-row
    decode runs clean beside the other graphs (a build without the attention's early exit did, and is the next step).

Fixed

  • v0.3.0's experimental families could not start on a NeuronCore under any build: balanced and throughput applied
    GLM-5.3-Flash's device-only DSA routes to every model, and latency turned on MTP, which the plain decoder refuses.
    Each family now has its own build, and a model runs only its own builds on a NeuronCore.
  • GLM-5.3:
    • router top-k unsorted lowered to a full sort that neuronx-cc refuses on trn2 (NCC_EVRF029);
    • NaN / -inf rows sanitized before the device top-k, and its ids clamped;
    • rope rows stored evens-first, no strided head-axis slice;
    • replicated latent and indexer projections dequantized once at load;
    • the indexer selects through the exact NKI selection kernel (the bisection compiled for 25+ min and was inexact on
      device for wide-range scores);
    • prefill chunks of at most 1,024 rows (the 4,096-row pieces' per-head index scores did not fit HBM);
    • every graph at -O1 (IGCA103 / ILSR902 at -O2).
  • DeepSeek-V4.1-Flash:
    • the vocabulary head places its shard by a one-hot multiply;
    • the Engram ids are hashed on the host and reach the graphs as ngram_ids (no int64 hash in a graph); its key and
      value are two products of weights transposed at load, the transpose done on the host (a device tensor refused
      .contiguous() of a transposed slice);
    • the indexer selects by bisection, short rows taking their reachable entries;
    • a prefill chunk's padding rows sit at the chunk's first position;
    • mHC's collapse and expand sum one stream at a time above 512 rows;
    • deferred cache writes are one plain index_copy_ per tensor;
    • every graph at -O1, prefill graphs with the 30M instruction limit; experts on the XLA path in its build.
  • Qwen3.8-27B: the head's logits were bf16 and rounded near-ties into exact ties (all-64-layer agreement 0.926 -> 0.998 with an
    fp32 head).

Added

  • Qwen3.8-27B kernel routes, each behind its own knob and each checked on device with a 16-call chain and a planted error:
    • Gated DeltaNet decode: output within 2e-6 of fp32 at 1-16 rows; one-row steps keep the torch recurrence (108 vs 93 µs
      a layer);
    • head_dim-256 attention, prefill (nkilib attention_segmented_cte) and decode (attention_tkg), the decode stopping
      at the longest row's context (bitwise equal to the full window at 1, 2 and 4 rows; the cache passed as 64-token
      blocks, since the bundled exit is wrong past the first tile when the kernel shortens blocks itself);
    • an fp32-output vocabulary head (within 3.7e-7 of the largest logit);
    • a vocabulary-parallel sampler (each rank samples its shard; one small all-reduce combines the candidates).
      At 8 rows these cut the decode step from 52.95 to 25.45 ms; a row costs 0.77 ms against 4.64.
  • extra_compiler_args(kind, rows) and CC_REPLACE_OPT: per-graph compiler arguments for a model.
  • Prompt logprobs for the plain decoder (plp_targets), and check_mixed's scoring (--score, --compare-plp).

Proofs

  • GLM-5.3-Flash's graphs did not move: tools/graph_equiv.py against release 0.2.0's capture, EQUAL on balanced /
    throughput / latency (1,312 / 1,216 / 3,424 pairs, 122 / 110 / 269 distinct graphs, 0 differ), and at this PR's head
    every rank's ordered cache-key list is identical to that run's (32 ranks each).
  • Qwen3.8-27B's served graphs: at this head, the qwen38 build captures the same ordered keys as the build that served
    every number here, less its 4- and 8-row decode graphs (8 ranks, 392 keys, none added); the all-64-layer check's shape is
    identical to its run (136 keys).
  • CPU suite at the code head (62a7f2b), the maintainers' private trace patterns on: 3,343 passed, 41 skipped, 2 xfailed
    (the documented strict expected failures), 0 failed. Later commits change docs only.

Benchmarks

One trn2.48xlarge, Neuron SDK 2.32 (neuronx-cc 2.27.5334), the image from docker/Dockerfile at this branch, real
weights. Full tables and how each was checked: docs/RESULTS.md, "The model families on Trainium2".

Qwen3.8-27B, qwen38 build, AgentX (agentx-harness 1.0.12, the public trace set, InferenceX's scoring, per 16
chips; run at 32, 16, then 8 users, every engine's cache flushed before each point; --max-context-length 262144, the model's own
context, and the harness handles longer requests):

UsersProfiledRequests / minTokens/s per chipP90 tok/s per userTTFT p50 / p90Prompt from cacheM tokens per $: AWS Capacity Block $2.235 / SemiAnalysis $0.58 a chip-hour
321,532 in 60 min25.32,29724.29.9 s / 76.6 s93.4%3.70 / 14.26
161,209 in 60 min20.11,96925.41.3 s / 20.7 s94.0%3.17 / 12.22
8379 in 30 min12.51,25824.81.7 s / 18.2 s94.8%2.03 / 7.81

Accuracy on the same serve: GSM8K 97.42% ± 0.44 strict (InferenceX's eval, 5-shot, 1,319 problems, thinking at the
template default; InferenceX reports 97.04% for the FP8 checkpoint on H100); needle 3/3 on a 90,327-token document, cold
and after 48 churn documents.

Qwen3.8-27B decode step, device time, 4K window (captured on device from the compiled graph):

1 row, before1 row, kernels8 rows, before8 rows, kernels
Step20.45 ms20.09 ms52.95 ms25.45 ms
Gated DeltaNet (48 layers)4.515.208.787.30
Attention (16 layers)4.273.3629.844.50
MLPs (64)8.207.969.118.74
Norm, head, sampler1.461.521.911.63

GLM-5.3, glm53 build, decode step device time: 84.8 ms at 1 row, 366.2 ms at 16 rows.

Not in this PR

  • GLM-5.3 beyond 4K (needs a two-stage selection, fused index scoring for prefill, and context-parallel latent cache).
  • GLM-5.3 decode MoE: a TP-sliced kernel measured 1.6-3.2x faster than EP at B1-B16, but it needs a prefill path that HBM
    can co-host; parked. The build keeps expert-parallel MoE for both phases.
  • DeepSeek-V4.1-Flash's full model (FP8 slice-major experts, prefill / decode pieces), and its fp32 head (still bf16).
  • Qwen3.8-27B decode at 4 and 8 rows a step: the stall of three decode graphs in one engine (docs/KNOWN_ISSUES.md) caps the
    build at 2 running an engine; a build without the attention's early exit ran 1, 2 and 4 rows clean and is the next
    step.
  • Host-tier counters on /metrics (saves, restores), for every model: today a restore from the host tier cannot be
    observed from outside, so the needle judged answers only.

Summary by cubic

Runs the three experimental model families on a trn2.48xlarge for the first time, each with its own build. Qwen3.8-27B reaches preview (0.979 agreement vs CPU fp32, GSM8K 97.42%); GLM-5.3 and DeepSeek-V4.1-Flash run correctly at their first device-verified shapes, with the rest tracked in docs/RESULTS.md.

Fixes and additions

  • v0.3.0 builds could not start the families on a NeuronCore; each family now has its own build, and a model runs only its own on a NeuronCore.
  • Qwen3.8-27B gains device kernels (Gated DeltaNet decode, head_dim-256 attention prefill and decode, fp32-output head, vocabulary-parallel sampler) that cut the 8-row decode step from 52.95 to 25.45 ms; the attention routes now require a bf16 model.
  • GLM-5.3 fixes: sorted router top-k, NaN/-inf rows sanitized before the device top-k, rope rows evens-first, replicated projections dequantized once at load, indexer selection through the exact NKI kernel, all graphs at -O1.
  • DeepSeek-V4.1-Flash fixes: Engram ids hashed on host, key/value weights transposed at load, padding rows placed at a chunk's first position, bisection indexer selection (reads a NaN score at topk_floor), lean mHC sums above 512 rows, per-graph compiler arguments, experts on the XLA path.
  • The bf16 head rounded near-tied logits into exact ties (agreement 0.926); the fp32-output head raises it to 0.998.
  • Adds prompt logprobs to the plain decoder, host-tier state dumps (TRNRT_DUMP_STATE), and scoring support in tools/check_mixed.py. Prompt-logprob requests are refused at add-request time (a 400) on non-plain-decoder models or with token masks or penalties, and the target's rank is counted in fp32.
  • Device check tools refuse arguments that would under-report (a page rung the cache cannot hold, an empty row selection, an out-of-range position or chain plant), and check_mixed refuses mismatched state-dump pairs and scores without a tokenizer.
  • serve starts engine i at core i × the build's tensor-parallel degree instead of the bare --tp default.
  • KNOWN_ISSUES.md documents the 8-row decode stall's minimal trigger and the review findings left for later; MODELS.md records each family's mean logprob difference.

Summary by CodeRabbit

  • New Features
    • Added experimental Trainium2 builds and serving configurations for Qwen3.8-27B, GLM-5.3, and DeepSeek-V4.1-Flash.
    • Added prompt-token log-probability scoring and optional optimized attention, decoding, vocabulary-head, and sampling paths for supported configurations.
  • Bug Fixes
    • Improved DeepSeek-V4.1-Flash cache updates and host-side token handling.
    • Corrected serving core placement to follow the selected build’s parallelism settings.
  • Documentation
    • Added model results, configuration guidance, and known limitations, including Qwen3.8-27B decode constraints and experimental validation details.