spec: MTP speculative decoding and the AgentX presets
Adds multi-token prediction (MTP) speculative decoding to TrnRT, and the serving configurations behind our InferenceX AgentX measurements of GLM-5.3-Flash on one trn2.48xlarge, so anyone can reproduce them.
Merged into development ahead of its device evidence, by maintainer decision. #23 tracks the graph-equivalence and trn2 results (no release from main before it closes); #24 and #25 hold the review findings left for follow-up. The review's high and medium host-side findings are fixed in 9852772, and the mtp-model branch (the kda_decode kernel and its tests) is merged in. docs/AGENTX.md has the presets, the commands and the status.
What is in
- MTP speculative decoding scheduled before the previous step is read back (
engine/spec_async.py): 2 draft tokens per step, the accepted count, newest token, positions, state row and drafts kept on the device. - Four presets:
mtp-batch8(concurrency 1, 4, 8),mtp-always(2),mtp-batch12(12, 16),mtp-batch24(24, 32). The dynamic ones speculate only while at most 4 requests decode and step plain above that; plain steps still write the MTP layer's KV. - Recurrent-state seats of 1 + k rows only for the requests that speculate; decode checkpoints reserved before the accepted count is known.
- A benchmark mode for InferenceX's synthetic acceptance (
--spec-synth-al, golden length 2.518506 for 2 draft tokens). Off by default; a run's text is not the model's. trnrt:spec_decode_*metrics and aspecblock inGET /v1/stats.docs/AGENTX.md: the preset for each concurrency, compile and serve commands, and how to run and score an AgentX point with the harness and InferenceX's own scorer.docs/RESULTS.md: the trn2 numbers, marked unverified on this tree.
Checks before this leaves draft
- CPU suite, ruff, ruff format and mypy pass at the current head (the model-dependent tests below are not written yet).
- New CPU tests on the real model: plain-step MTP KV write equals the MTP layer's own write; drafts after a plain stretch equal always-on MTP's; host-cache restore with MTP equals a cold request. (The engine-level versions of the last one run against a fake device; the model-level ones wait for the verify and draft passes.)
-
tools/graph_equiv.py: every compiled graph of each preset equals the graphs behind the published measurements; and, with speculation off, the batch-12 defaults still equal OSS main. - On a trn2.48xlarge: compile from source, serve, GSM8K with MTP at or above 94%, and an AgentX point that reproduces the published number.
-
docs/RESULTS.mdandCHANGELOG.mdupdated (numbers marked unverified until the device check).
Summary by cubic
Adds MTP speculative decoding to TrnRT and the serving configurations behind the InferenceX AgentX measurements of GLM-5.3-Flash on a trn2.48xlarge, so anyone can reproduce them.
- The MTP layer drafts 2 tokens a step; this PR contains the verify and draft passes, the MTP layer's model code, and the kernels it needs: the fused DSA layer without the FFN half, the MoE half's standalone decode, the KDA decode kernel for above-cap decode steps, the sequence-parallel gather, and the 3,072-page bucket's two-stage selection.
- Blind speculative steps keep accepted counts, positions, state rows, and drafts on the device, so the next step is scheduled before the previous one is read back; speculative seats of 1 + k state rows make a rejected draft cost no copy.
- Presets are
mtp-always,mtp-batch8,mtp-batch12, andmtp-batch24, plus a dynamic mode that speculates only while few requests decode and a--spec-synth-albenchmark mode that reproduces InferenceX's synthetic acceptance (off by default). - The
mtp-*presets setTRNRT_DMA_HW, which compiles the kernels' static DMA helpers in hardware DGE as in the builds behind the published numbers; the CLI sets it before any kernel import. - Speculative counters appear in
GET /metricsand in aspecblock inGET /v1/stats. docs/AGENTX.mddocuments the preset for each concurrency from 1 to 32 and the batch-12 build's GSM8K result; thedocs/RESULTS.mdnumbers stay marked unverified until reproduced on this tree.
Summary by CodeRabbit
-
New Features
- Added GLM-5.3-Flash speculative decoding with four presets, two draft tokens per step, and dynamic mode for lower decode concurrency.
- Added optional synthetic-acceptance benchmarking and speculative-decoding metrics in runtime statistics.
- Added sequence-parallel gathering and optimized decode paths for supported workloads.
-
Documentation
- Added setup, configuration, benchmarking guidance, and performance results marked unverified pending device checks.
- Documented hardware DMA settings and speculative-decoding metrics.