Repository navigation
[TRTLLM-16622][perf] DeepSeek-V4.1: steady decode-step prepare, row-bounded CSA2 page tables and cross-rank tactic merge - #22370
Conversation
9ddab7f to
c470ccc
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #86388 [ run ] triggered by Bot. Commit: |
|
@heyuhhh, could you help to review this PR as trt-llm-torch-attention-devs? Thanks~ Assignment explanation
Affinity and workload are snapshots at selection, not live counters. Existing reservations on this PR are counted once. |
|
PR_Github #87195 [ run ] completed with state |
0938504 to
d195388
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #87257 [ run ] triggered by Bot. Commit: |
|
/bot run --disable-fail-fast |
|
PR_Github #87283 [ run ] triggered by Bot. Commit: |
|
PR_Github #87257 [ run ] completed with state |
…ounded CSA2 page tables and cross-rank tactic merge A DeepSeek-V4.1 rank keeps its requests for tens of decode steps, yet every step ran the full input preparation and the full CSA2 metadata prepare. - A model opts into the steady one-model MTP prepare with steady_decode_prepare (DeepSeek-V4.1, SM100/SM103): its decode batches, also under attention DP with CUDA graph padding rows, are staged by one kernel, while padding, the count exchange and the speculative metadata run the full pass's own steps. With attention TP the staging launch also does the Engram pre-replay refresh. - With the opt-in the steady prepare also records a pass with no previous device step, stages an admitting step on the recorded shape (prompt lengths and Engram seeds in the launch) and stages with a kernel that issues its loads before its stores; the sampler then updates its stores on the D2H side stream and the kernel reads the previous step's output rows. Models without the opt-in keep main's steady prepare, staging kernel and sampler stores. - CSA2: less host work per decode prepare, a joining request keeps the steady prepare, unchanged page storage keeps the converted page tables, and each row converts and copies only its live columns. - KVCacheManagerV2 keeps a decoding request's growth block across a draft shrink when the steady prepare arms it (attention TP). - DeepSeek-V4.1 merges tuned tactics across ranks (RuntimeHooks). Every steady step hands the model the inputs the full pass builds. GB300, DeepSeek-V4.1, rank 0 executor busy per decode step, base vs the host series (with the executor and Engram host work): 25 requests per rank 4,623 -> 3,654 us (4,214 without the steady prepare), 320 per rank 14,521 -> 13,787 us, attention TP8 batch 1 2,629 -> 2,140 us; step times unchanged. Row-bounded page tables at 320 rows with one 6,122-block row: conversion 122.0 -> 31.3 us, copy 68.8 -> 13.4 us. Batch-one disaggregated generation (TP4, DSpark k=5), first token to second response: admitting step 6.16 -> 5.90 ms p50, its seeds in the launch 6.03 -> 5.63 ms p50. Test: test_steady_spec_prepare.py (steady vs forced full passes without the opt-in, and with it at attention TP and attention DP with padding, with admissions), test_steady_glue.py (glue vs staging launch plus the replay hook, bitwise), test_steady_page_tables.py (unchanged-page exit with kept growth blocks, row-bounded tables vs full width). Signed-off-by: ziyixiong-nv <[email protected]> Signed-off-by: Jin Li <[email protected]>
Signed-off-by: Jin Li <[email protected]>
Signed-off-by: Jin Li <[email protected]>
Declare no runtime hooks in the compile-policy fixture and use the renamed Engram decode refresh limit in the fused-path assertion. Signed-off-by: Jin Li <[email protected]>
Validate changed and joining requests before reusing the steady metadata. Share the steady eligibility checks and page copy bookkeeping while preserving overlap invalidation for manager-owned outputs. Signed-off-by: Jin Li <[email protected]>
Keep the scheduling scenarios explicit and share allocation, acceptance, and the full-prepare reference. Keep stream ordering assertions alongside output parity. Signed-off-by: Jin Li <[email protected]>
Keep fused Engram hashing in the Engram kernel package and identify fusible replay hooks by type. Arm kept growth blocks only for the opted-in preparer and forward the replay flag explicitly. Signed-off-by: Jin Li <[email protected]>
Signed-off-by: Jin Li <[email protected]>
Serialize writes to borrowed SWA backing and discard bounds for overlapping block-offset destinations. Only construct the steady stager when decode CUDA graphs are enabled. Signed-off-by: Jin Li <[email protected]>
Signed-off-by: Jin Li <[email protected]>
Both AgentX TEP decode recipes intentionally enable a transfer admission window at PP=1. Check their other transceiver options with the regular recipe checks. Signed-off-by: Jin Li <[email protected]>
d195388 to
0af1b4b
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #87289 [ run ] triggered by Bot. Commit: |
|
PR_Github #87283 [ run ] completed with state |
|
PR_Github #87289 [ run ] completed with state |
Dev Engineer Review
steady_decode_preparecomes from model runtime hooks. DeepSeek-V4.1 enables it on SM100/SM103. Steady one-model MTP preparation can also be enabled by the existing speculative fast-path setting when attention-DP is disabled. Verify that other models keep main's behavior.stores_on_side_streamis set only whensteady_mtp_reads_output_rowsis true. Per the later commit, steady sampler stores are gated on decode graphs. Verify that the side-stream store path is off without decode graphs.prepare_inputswaits for store completion before guided decoding or any other reader. Verify that every reader of stored slots waits. Admission and side-stream ordering contracts are not verified from the snapshot._STEADY_PAGE_CHECKS). The exact debug condition and the behavior with debug mode off are not established.KVCacheManagerV2.keep_growth_blocks()changes capacity accounting for active requests. Verify rewind and compression-managed paths.max(1, count // 8)has no stated justification.convert_page_tables,copy_tables_,replay,prepare_steady_decode_step,stage_steady_inputs, andSteadyMtpPreparemethods gain or change parameters.SteadyMtpRecord.seq_lens_kvis replaced byseq_lens_kv_array. Check all callers.compute_batch_page_tableschanges its return annotation fromint | Nonetonp.ndarray | None. Confirm callers.#22355and#22364. Rebase status is not established.QA Engineer Review
test_steady_page_tables.py,test_kv_cache_manager_v2_helix_superblock.py,test_disagg_receive_ordering.py,test_steady_glue.py,test_steady_spec_prepare.py,test_cache_manager.py,test_context_logits_memory.py,test_spec_store_scatter.py,tests/unittest/conftest.py,test_phase_selective_forward.py, andtest_engram_decode_hash.py.test-db/orqa/lists is not established.test_prepare_inputs_steady_steps_match_forced_full_passes(plain, tp, attention_dp_padded) andtest_steady_glue_matches_the_staging_launch_and_replay_hook. Other test names are not established.cudaMallocAsyncsubprocess variant intest_spec_store_scatter.py.Per-File QA Perspective
csa2/cache_manager.py: Verify per-row live-column conversion and reuse when page storage is unchanged.csa2/kernel.py: Verifyrow_columnsvalidation and the unbounded fallback when limits are absent.csa2/metadata.py: Verify steady-step eligibility gates and debug-mode page checks.csa2/README.md: Documents debug-mode page validation. No behavior change.attention/backends/trtllm.py: Verifyprompt_lensupdates the host buffer and invalidates the device cache.models/modeling_deepseekv41.py: Verify steady prepare and tactic-sharing hooks apply only to this model.modules/engram/engram.py: Verify refresh plans match provider state before adoption.pyexecutor/_util.py: Verify the sampler side-stream flag follows the engine setting and decode-graph gating.pyexecutor/cuda_graph_runner.py: Verify hooks are skipped only when staging and position offsets are supplied.pyexecutor/device_copy.py: Adds a new H2D copy site. Verify it runs on the intended path.pyexecutor/runtime_hooks.py: Verifysteady_decode_preparedefaults toFalse.decoder/config.py: Verify the new field defaults toFalse.decoder/graphs.py: Verifypre_replay_stagedreaches the runner only on non-capture replay.decoder/inputs.py: Verify admission, padding, and RNG staging for steady MTP. High-risk path.decoder/metadata.py: Verifykeep_growth_blocks()runs only forKVCacheManagerV2with the opt-in.decoder/runner.py: Verifysteady_mtp_reads_output_rowsis true only when the opt-in and decode graphs are set.runners/interface.py: Verifypre_replay_stageddefaults toFalse.h2d_cache.py: Verifyforget(dst)forces the next copy to that destination.kv_cache_manager_v2.py: Verify retained capacity for active requests and unchanged behavior for completed and context-init requests.model_engine.py: Verify the flag is enabled only on Blackwell datacenter with an accessible language model.steady_spec_prepare.py: Verify loads-first staging, admission, and Engram refresh eligibility. High-risk path.spec_sampler_base.py: Verify side-stream scatter, event readiness, and fallback waits.test_steady_page_tables.py: Covers steady entry and row-bounded page-table equivalence. Blackwell assertions skip elsewhere.test_kv_cache_manager_v2_helix_superblock.py: Multiline lambda refactor. Expected values unchanged.test_disagg_receive_ordering.py: Adds_keep_growth_blockto the mock. Verify it matches the manager attribute.test_steady_glue.py: Covers Engram glue against a no-glue reference. Blackwell-gated.test_steady_spec_prepare.py: Covers staging, RNG, and end-to-end steady equivalence. Largest test change.test_cache_manager.py: Replaces the conversion wait helper with a no-op in two tests. Verify those tests still order conversions correctly.test_context_logits_memory.py: UsesPreparedInputsin the mocked result. Verify the mock fields match the dataclass.test_phase_selective_forward.py: Setsengine.model.runtime_hookstoNonebefore the decoder-runner check. Verify the test still covers the intended path.test_engram_decode_hash.py: Uses the publicDECODE_REFRESH_MAX_ROWSname. No behavior change.test_spec_store_scatter.py: Adds CUDA-graph-buffer andcudaMallocAsyncsubprocess tests. Verify the subprocess path runs in CI.tests/unittest/conftest.py: Enables_STEADY_PAGE_CHECKSin the verify fixture when the module is loaded. Verify fixture scope.Description
Summary
A DeepSeek-V4.1 rank keeps its requests for tens of decode steps, yet every step ran the full input preparation and
the full CSA2 metadata prepare. This PR lets DeepSeek-V4.1 decode steps take the steady one-model MTP prepare (one
staging launch for an unchanged batch, which main runs only for models with
spec_decode_fast_pathsand withoutattention DP), extends that prepare to admitting steps, and trims the CSA2 page-table work behind it:
steady_decode_prepare(DeepSeek-V4.1, SM100/SM103). Itsdecode batches, including CUDA graph padding rows under attention DP, are recorded and staged by one kernel; the
padding, count exchange and speculative metadata run the full pass's own steps, so every rank takes the same
collectives. With attention TP the staging launch also does the Engram pre-replay refresh.
first step) is recorded, and a step whose requests all join on the recorded shape is staged too, including their
prompt lengths and Engram seeds. The opted-in models' staging kernel issues its loads before its stores.
its per-slot stores on its D2H side stream and the staging kernel reads the previous step's output rows.
the steady CSA2 prepare; a batch at unchanged page storage keeps its converted page tables; each row converts and
copies only its live columns instead of the widest row's.
across a draft shrink, so its pages change once per new block instead of about 0.8 times per 128-token block.
merge_tuned_tactics_across_ranksandevery rank serves the fastest profiled tactic per shape.
Changes
DecoderRunnerConfig.steady_decode_preparecomes fromRuntimeHooks.steady_decode_prepare.DecoderInputPreparerbuildsSteadyMtpPreparefor it, also underattention DP;
_steady_mtp_fast_prepare_modereturns "steady" or "admit".steady_spec_prepare.py: padding rows in the record, admissions (admits,admit), passes without a previousdevice step, and the Engram refresh in the staging launch (
EngramHashProvider.decode_refresh_plan/admission_refresh_plan,CUDAGraphRunner.replay(pre_replay_staged=)).SteadyMtpPrepare(steady_decode_prepare=)launches a new
_steady_decode_stage_kernel(load-first order, padding rows, first steps from the host, outputrows, Engram refresh) through
stage_steady_inputs(loads_first=True); without the opt-in it launches main's_steady_stage_kernel, which is unchanged.TrtllmAttentionMetadata.prepare_steady_decode_step(prompt_lens=);CSA2TrtllmMetadata.prepare_steady_decode_step.SpecSampler.stores_on_side_stream(set byinstantiate_samplerwhenModelEngine.steady_mtp_reads_output_rows,i.e. an opted-in model's steady prepare stages the decode steps): the store scatter runs on the D2H side stream,
SampleStateTensorsSpeccarriesstores_readyand the step's outputrows.cache_manager.py,metadata.py,kernel.py): per-row live-column bounds for the page-table conversion andcopy (SM100/SM103), the unchanged-page-storage exit and the joining-row mapping. A steady refresh validates
writable SWA, GLOBAL and compressor state pages for changed and joining requests before replay.
keep_growth_blocks()(not for draft pools, helix or attention DP) andkept_generation_capacity;DecoderMetadata.setup_attentionarms it whensteady_decode_prepareis on.DeepseekV41ForCausalLM.runtime_hooksenablessteady_decode_prepareon SM100/SM103 and addsmerge_tuned_tactics_across_ranksto DeepSeek-V4's hooks. The Engram refresh hook exposes its provider.Performance
The table records the original decode runs. Changed-row validation was measured separately on the host. Validation measurement
GB300, DeepSeek-V4.1-Flash, single-node decode runs, rank 0 executor busy time per decode step. Base against the
host series of this PR, #22355 and #22364's Engram host work (step times unchanged; the points are GPU-bound):
At 25 requests per rank the series without the steady decode-step prepare measured 4,214 us. Single items:
25.
122.0 -> 31.3 us, table copy 68.8 -> 13.4 us. Measured with two other generation-step changes (the fused-sampling
walk, [TRTLLM-16622][perf] DeepSeek-V4.1: fused sampling with a parallel inverse-CDF walk and a pipelined first sweep #22356, and the padded Engram refresh, [TRTLLM-16622][perf] DeepSeek-V4.1: Engram decode hashes and history scatter in one launch, pair gathers and a prologue fork #22364) at 320 requests per rank: steady-state generation step
31.06 -> 30.66 ms (-1.3%), output throughput +1.5%.
first token to the second response: staging an admitting step 6.16 -> 5.90 ms p50 (6.50 -> 6.22 ms p90); its
prompt lengths and Engram seeds in the staging launch 6.03 -> 5.63 ms p50 (6.21 -> 5.90 ms p90).
5 drafts). Staging kernel, loads first: 4.4 -> 3.8 us (8 rows), 7.3 -> 5.2 us (64 rows).
3-6 GEMM and 7-10 mHC autotuner keys differed across ranks, with it every rank runs the same kernels.
Compatibility
the staging launch, the CSA2 changes (CSA2 is DeepSeek-V4.1's attention), the kept growth blocks (armed only by the
steady_decode_prepareopt-in, attention TP) and the tactic merge (RuntimeHooks).spec_decode_fast_pathsbut withoutsteady_decode_prepare(Qwen3-Next with its decode kernels)already take the steady one-model MTP prepare on main, without attention DP, and keep main's behavior: no
admissions, no records of passes without a previous device step, main's staging kernel and the sampler stores on
the forward stream. The shared steady step now builds its padding and speculative metadata with the full pass's
own steps, which hands these models the inputs main's steady step hands them;
test_prepare_inputs_steady_steps_match_forced_full_passes[plain]checks this path against forced full passes.steady_decode_prepare.Dependencies
#22355 (
current_cuda_stream, the sampler's slot table) and #22364 (EngramDecodeRefreshKernelandthe Engram decode-refresh plan) are on main.
Test Coverage
test_steady_spec_prepare.py::test_prepare_inputs_steady_steps_match_forced_full_passes(extended,[plain, tp, attention_dp_padded]): steady steps on the real input preparer andTrtllmAttentionMetadatahand themodel what forced full passes hand it.
plainis main's case (no opt-in: first steps and the steps after them takefull passes);
tpandattention_dp_paddedopt in, with attention-DP padding rows, admissions after an idle deviceand right after another batch, and the previous step's output rows.
test_steady_glue.py::test_steady_glue_matches_the_staging_launch_and_replay_hook(new): the staging launch withthe Engram refresh writes what the staging launch plus the replay's hook writes, bit for bit, including a pending
history seed and an admission of seeded requests.
test_steady_page_tables.py::test_unchanged_page_storage_exit_matches_full_prepare(new, SWA scratch reuse off andon): steady-entry steps with growth blocks kept and the unchanged-page exit read what a full prepare writes over
growth, retirements and admissions.
test_steady_page_tables.py::test_row_bounded_page_tables_match_full_width(new, attention TP and DP): row-boundedconversions and copies read what full-width ones write, with one long request among short ones.
Stub fits:
_keep_growth_block=Falseon two KV cache manager stubs.CI: main's L0 lists already run these files (
l0_b200.yml/l0_gb300.ymllisttest_steady_spec_prepare.py;the
_torch/pyexecutorandattention/sparsedirectory entries ofl0_b300.ymlandl0_b200.ymltake the others).PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.