Skip to content

[None][perf] Optimize MiniMax-M3 NVFP4 context (prefill) path on Rubin (SM107) - #20629

Open
peihu-nv wants to merge 27 commits into
NVIDIA:mainfrom
peihu-nv:peihengh/m3-vr-sm107-ctx
Open

peihu-nv wants to merge 27 commits into
NVIDIA:mainfrom
peihu-nv:peihengh/m3-vr-sm107-ctx

Conversation

@peihu-nv

@peihu-nv peihu-nv commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

The changes add SM107-specific MiniMax-M3 prefill paths across QKV projection and cache production, sparse and dense attention, normalization and quantization, MXFP8 GEMMs, MoE routing and finalization, and context scheduling. New CUDA operators and CuTe DSL kernels have runtime gates and fallback paths. The patch also adds Rubin serving configurations and a patched FA4 setup script.

Review should focus on numerical and cache correctness at optimization boundaries. The reported FA4 accuracy miss for a short chunk over a long prefix, selector-test abort on SM107, and NaNs in fmha_sm100 when reused partial KV pages contain stale FP8 V values are follow-up risks; the supplied reports do not establish that they are resolved. Several paths also change reduction order, use deterministic MoE finalization, or skip intermediate BF16 writes, so their numerical bounds, stream use, and fallback behavior need validation. SM107 GPU coverage is registered in l0_gr100, but the supplied objective says no SM107 GPU CI stage exists.

QA Engineer Review

The diff changes 107 files. It adds and modifies unit tests and updates two test-db lists. The CPU list adds CPU-compatible routing, dispatch, contract, and configuration checks. The l0_gr100 list adds Rubin GPU tests for context kernels, attention, quantization, routing, MoE, and GEMM paths. No manual-QA list changes appear in the supplied diff. Test-list registration is present for the listed integration tests; the supplied evidence does not establish completed test or CI results. Coverage verdict: needs follow-up, particularly for reported FA4 accuracy, selector abort, and partial-page stale-V NaNs.

Per-File QA Perspective

Source, kernels, operators, and configuration

Changed file QA perspective
3rdparty/patches/fa4_fp8_rescale0.patch Changes FA4 FP8 rescaling behavior. Verify numerical accuracy and compatibility with the pinned FA4 package.
3rdparty/patches/msa_strided_paged_kv.patch Updates the MSA third-party patch. Verify patched behavior and compatibility with supported package versions.
cpp/tensorrt_llm/kernels/customAllReduceKernels.cu Adds the SM107 row-persistent RMSNorm path for large residual-RMSNorm batches. Verify row coverage, residual behavior, and PDL execution.
cpp/tensorrt_llm/kernels/fusedQKNormRopeKernel.cu Adds an SM107 multi-token QKV cache producer. Verify the 1024-token dispatch boundary, cache-slot guards, and output parity.
cpp/tensorrt_llm/kernels/minimaxM3/routerGemv.cu Adds optional full-FP32 router accumulation using three TF32 terms. Verify numerical behavior and cluster dispatch in both modes.
cpp/tensorrt_llm/kernels/minimaxM3/routerGemv.h Extends router APIs with a defaulted precision flag. Verify existing callers retain the prior default behavior.
cpp/tensorrt_llm/kernels/minimaxM3/selectPrefillTile.cu Adds the CUDA prefill tile selector and dispatch variants. Verify tie-breaking, forced selections, bounds, and large candidate counts.
cpp/tensorrt_llm/kernels/minimaxM3/selectPrefillTile.h Publishes the selector limit and API contract. Verify callers respect layout, capacity, and output-padding requirements.
cpp/tensorrt_llm/kernels/minimaxM3Sm107Tp2/ctxResidualRmsNormMxfp8.cu Adds fused residual RMSNorm with MXFP8 and optional NVFP4 outputs. Verify scale layouts, padding, and supported geometries.
cpp/tensorrt_llm/kernels/minimaxM3Sm107Tp2/ctxResidualRmsNormMxfp8.h Publishes the fused norm API and shape constraints. Verify operator validation matches the kernel constraints.
cpp/tensorrt_llm/thop/minimaxM3/minimaxM3RouterGemvOp.cpp Extends router Torch operators with the full-FP32 option. Verify schema defaults and architecture checks match kernel dispatch.
cpp/tensorrt_llm/thop/minimaxM3/minimaxM3SelectPrefillTileOp.cpp Adds a validated Torch wrapper for tile selection. Verify tensor layout checks and CUDA error propagation.
cpp/tensorrt_llm/thop/minimaxM3/minimaxM3Sm107Tp2CtxNormMxfp8Op.cpp Adds the fused context norm operator. Verify dtype, alignment, device, and architecture rejection paths.
cpp/tensorrt_llm/thop/mxfp8Gemm.cpp Adds small-M tuning buckets on SM107. Verify bucket boundaries and preserve exact-M tuning elsewhere.
examples/minimax_m3/rubin/README.md Documents Rubin disaggregated serving and FA4 setup/fallback. Verify instructions against the actual runtime switches.
examples/minimax_m3/rubin/agg/README.md Documents aggregated Rubin serving configurations. Verify worker counts, placement, and configuration references.
examples/minimax_m3/rubin/agg/agg_c14.yaml Adds a TP2 serving configuration. Validate token, cache, and speculation settings with the intended workload.
examples/minimax_m3/rubin/agg/agg_c20.yaml Adds a TP2 serving configuration. Validate memory and batch settings against the target deployment.
examples/minimax_m3/rubin/agg/agg_c46.yaml Adds a higher-concurrency TP2 configuration. Validate host-cache sizing and scheduling parameters.
examples/minimax_m3/rubin/agg/agg_c56.yaml Adds a maximum-concurrency TP2 configuration. Validate CUDA graph batches, cache sizing, and token limits.
examples/minimax_m3/rubin/agg/agg_env.sh Adds shared environment defaults and disables selected context optimizations. Verify variables are intentional for every sourcing worker.
examples/minimax_m3/rubin/ctx_agentx_c24.yaml Adds an AgentX context-worker configuration. Validate cache reuse, transfer, and chunked-prefill settings.
examples/minimax_m3/rubin/fp4_moe_tactics_tp2ctx_v1.json Adds pinned FP4 MoE tactics. Verify keys and tactic values match the runner’s shape and bucket lookup scheme.
examples/minimax_m3/rubin/setup_fa4.sh Adds hash-validated FA4 patch setup. Verify source-version hashes and failure handling before deployment.
tensorrt_llm/_torch/_experimental/modeling_v2/models/minimax_m3/kernels/fake_ops.py Updates the fake router operator typing. Verify fake outputs remain consistent with registered operator schemas.
tensorrt_llm/_torch/_experimental/modeling_v2/models/minimax_m3/minimax_m3_nvfp4__sm_107__tp2/modeling.py Adds eager CTX stack paths and routing thresholds. Verify capture exclusions, fallback behavior, and refit refresh.
tensorrt_llm/_torch/attention/backends/fmha/drafter_last_row.py Adds drafter last-row attention and optional cache-tail zeroing. Verify partial-page reuse safety and stock fallback.
tensorrt_llm/_torch/attention/backends/fmha/flashinfer_trtllm_gen.py Extracts context attention into a helper. Verify that options and output behavior remain unchanged.
tensorrt_llm/_torch/attention/backends/fmha/msa_combine_mxfp8.py Adds prequantized MXFP8 handoff from sparse combine to o_proj. Verify skipped BF16 writes only occur when the consumer takes the slot.
tensorrt_llm/_torch/attention/backends/fmha/msa_prefill.py Adds FA4, tail handling, and buffer/workspace reuse paths. Verify partial-page safety and numerical parity across FA4 and fallback.
tensorrt_llm/_torch/attention/backends/fmha/registry.py Registers the drafter-specific FMHA backend. Verify registration ordering and marking requirements.
tensorrt_llm/_torch/attention/backends/sparse/minimax_m3/kernels/msa_utils.py Adds an SM107 NumPy path for valid-block counts. Verify output dtype and causal-offset parity.
tensorrt_llm/_torch/attention/backends/sparse/minimax_m3/msa_backend.py Adds segmented proxy planning and page gathering. Verify capacity limits, offsets, and mutable page-table handling.
tensorrt_llm/_torch/attention/backends/sparse/minimax_m3/msa_indexer.py Adds the SM107 tile selector and optional unfilled proxy buffers. Verify eligibility gates and initialization assumptions.
tensorrt_llm/_torch/custom_ops/cpp_custom_ops.py Adds fake output shapes for fused context norm. Verify scale and optional-output shapes match the real operator.
tensorrt_llm/_torch/custom_ops/cute_dsl_custom_ops.py Adds permuted-row MoE finalize mode and a custom op. Verify runner cache keys and output contracts include the mode.
tensorrt_llm/_torch/custom_ops/torch_custom_ops.py Adds small-M MXFP8 bucket profiles. Verify mapping when native runner construction fails and at bucket boundaries.
tensorrt_llm/_torch/custom_ops/trtllm_gen_custom_ops.py Adds optional tactic-table lookup. Verify absent or unmatched entries preserve autotuner behavior.
tensorrt_llm/_torch/kernels/rubin/m3_qkv_fusion/__init__.py Adds license headers only. No runtime behavior change.
tensorrt_llm/_torch/kernels/rubin/m3_qkv_fusion/clc_tile_scheduler.py Adds a dynamic persistent scheduler. Verify cluster layouts, coordinate decoding, and CLC advancement for each raster mode.
tensorrt_llm/_torch/kernels/rubin/m3_qkv_fusion/kernel.py Adds fused persistent QKV GEMM and post-processing. Verify SM107 compilation gating, cache writes, and debug/reference parity.
tensorrt_llm/_torch/kernels/rubin/m3_qkv_fusion/plain_gemm.py Adds a GEMM-only wrapper and weight cache. Verify validation and cache lifetime through refit/reload.
tensorrt_llm/_torch/models/modeling_minimaxm3.py Adds several SM107 context, router, embedding, and MoE paths. Verify threshold gates, API compatibility, and stock fallbacks.
tensorrt_llm/_torch/modules/linear.py Adds prequantized activation handoff and CLC dispatch. Verify pointer matching, cross-stream lifetime, and fallback quantization.
tensorrt_llm/_torch/modules/m3_ctx_clc_gemm.py Adds eager CTX CLC GEMM dispatch and precompilation. Verify shape gates and that only intended host preparation errors fall back.
tensorrt_llm/_torch/modules/swiglu.py Adds fused SwiGLU-to-MXFP8 quantization. Verify scale layout, padding, and activation parameter handling.
tensorrt_llm/_torch/moe/fused_moe/cutedsl/grouped_gemm/eligibility.py Adds an opt-in eligibility exception for SwiGLU-OAI. Verify all other grouped-GEMM restrictions remain enforced.
tensorrt_llm/_torch/moe/fused_moe/cutedsl/grouped_gemm/nvfp4.py Adds deterministic FC2 and one-shot residual folding. Verify residual matching and deterministic-mode fallback.
tensorrt_llm/_torch/moe/fused_moe/router_gemm.py Adds a router GEMM custom op. Verify operand validation, split-K reduction, and empty-row behavior.
tensorrt_llm/_torch/moe/fused_moe/unpermute_residual.py Adds ordered unpermute accumulation with optional residual. Verify index bounds, rounding, and contraction modes.
tensorrt_llm/_torch/moe/kernels/rubin/rubin_contiguous_gather_grouped_blockscaled_gemm_act_fusion.py Adds SwiGLU-OAI activation parameters. Verify defaults preserve prior SwiGLU behavior.
tensorrt_llm/_torch/moe/kernels/rubin/rubin_contiguous_grouped_blockscaled_gemm_finalize_fusion.py Adds permuted-row stores without atomic reduction. Verify mode-specific output semantics and consumers.
tensorrt_llm/_torch/pyexecutor/resource_manager.py Stores partial-reuse copy policy on the cache manager. Verify tail-zeroing safety reads the same policy.
tensorrt_llm/_torch/pyexecutor/scheduler/scheduler_v2.py Adds context append reserve and shortest-uncached-first scheduling. Verify progress fallback, token caps, and paired-cache accounting.

Test-list files

Changed file QA perspective
tests/integration/test_lists/test-db/l0_cpu.yml Adds CPU-list entries for context routing, contracts, dispatch, and tactic lookup. Verify each listed selector is stable and CPU-compatible.
tests/integration/test_lists/test-db/l0_gr100.yml Adds Rubin GPU entries for context kernels, dense prefill, routing, and MoE. These entries register the listed GPU tests in this CI test list.

Test-code files

Changed file QA perspective
tests/unittest/_torch/attention/fmha/test_msa_combine_mxfp8.py Tests combine eligibility, handoff, logging, and skipped-store safety. Listed in l0_gr100? No.
tests/unittest/_torch/attention/sparse/msa/test_fa4_setup.py Tests FA4 setup script success and hash-failure behavior. Listed in l0_gr100? No.
tests/unittest/_torch/attention/sparse/msa/test_fmha_sm107_gates.py Tests MSA SM107 gates, cache handling, and invalid inputs. Listed in l0_gr100? No.
tests/unittest/_torch/attention/sparse/msa/test_minimax_m3_dense_prefill_fa4.py Tests FA4 eligibility, determinism, finiteness, and reference error. Listed in l0_gr100.
tests/unittest/_torch/attention/sparse/msa/test_minimax_m3_dense_prefill_fa4_arch.py Tests FA4 architecture eligibility. Listed in l0_gr100? No.
tests/unittest/_torch/attention/sparse/msa/test_minimax_m3_dense_prefill_fa4_patched.py Runs the patched FA4 accuracy suite in a subprocess. Listed in l0_gr100.
tests/unittest/_torch/attention/sparse/msa/test_minimax_m3_prefill_v_tail.py Tests stale V-tail NaNs on partial pages. Listed in l0_gr100? No.
tests/unittest/_torch/attention/sparse/msa/test_minimax_m3_proxy_nofill.py Compares filled and unfilled proxy score buffers and selections. Listed in l0_gr100.
tests/unittest/_torch/attention/sparse/msa/test_minimax_m3_sparse_attn_decode.py Pins proxy-mode defaults in a JIT-cache test. Listed in l0_gr100? No.
tests/unittest/_torch/attention/sparse/msa/test_minimax_m3_tile_select.py Tests selector parity, gates, layouts, and graph replay. Listed in l0_gr100.
tests/unittest/_torch/attention/sparse/msa/test_msa_backend.py Adds segmented-proxy and current-page-table regression coverage. Its new regression selector is listed in l0_gr100.
tests/unittest/_torch/attention/sparse/msa/test_msa_k2q_ws_stream.py Tests workspace reuse and stream ownership. Its stock-content selector is listed in l0_gr100.
tests/unittest/_torch/attention/sparse/msa/test_msa_per_token_valid_blocks_numpy.py Tests NumPy and PyTorch valid-block parity. Listed in l0_gr100? No.
tests/unittest/_torch/attention/sparse/msa/test_msa_prefill_nvfp4_out_in_place.py Tests the NVFP4 sparse output-buffer eligibility gate. Listed in l0_gr100.
tests/unittest/_torch/attention/sparse/msa/test_msa_proxy_few_rows_kv_splits.py Tests split-count selection by row count. Listed in l0_gr100? No.
tests/unittest/_torch/attention/sparse/msa/test_msa_q_e4m3.py Tests optimized Q-to-E4M3 conversion and fallback parity. Listed in l0_gr100.
tests/unittest/_torch/attention/test_drafter_kv_tail_zero.py Tests cache-tail zeroing gates and cache-manager safety. Listed in l0_gr100.
tests/unittest/_torch/attention/test_flashinfer_trtllm_gen_sm107_p128.py Adds drafter last-row parity tests for BF16/FP8 and context/decode paths. Listed in l0_gr100? No.
tests/unittest/_torch/kernels/parallel/test_mxfp8_mxfp8_gemm.py Adds SM107 small-M tactic mapping and output parity tests. Its two new selectors are listed in l0_gr100.
tests/unittest/_torch/kernels/parallel_hw_agnostic/test_minimax_m3_nvfp4_horizontal_producer.py Tests row-kernel parity across split calls and guard pages. Its new selector is listed in l0_gr100.
tests/unittest/_torch/kernels/serial/test_m3_ctx_clc_gemm.py Tests CLC GEMM numerical gates, dispatch, replay, timing, and cache lifetime. Listed in l0_gr100.
tests/unittest/_torch/kernels/serial/test_m3_ctx_fused_quant.py Tests fused context quantization and SwiGLU quantization. Listed in l0_gr100.
tests/unittest/_torch/kernels/serial/test_m3_qkv_contract.py Tests QKV host validation and stream selection. Listed in l0_cpu.yml.
tests/unittest/_torch/kernels/serial/test_m3_qkv_fusion.py Tests fused QKV parity, repeatability, replay, and optional timing. Listed in l0_gr100.
tests/unittest/_torch/kernels/serial/test_sm107_allreduce_rmsnorm_rows.py Tests SM107 row-wise all-reduce RMSNorm across dtypes and row boundaries. Listed in l0_gr100.
tests/unittest/_torch/misc/test_fp4_moe_tactic_table.py Tests tactic-table lookup and fallback. Listed in l0_cpu.yml.
tests/unittest/_torch/modeling/test_minimax_m3_router_fp32_cast.py Tests router input cast parity and SM107 gating. Listed in l0_gr100.
tests/unittest/_torch/modeling/test_minimax_m3_router_tc_gen.py Tests tensor-core router and gate dispatch, including graph and numerical checks. Listed in l0_gr100.
tests/unittest/_torch/modeling_v2/models/minimax_m3/minimax_m3_nvfp4__sm_107__tp2/attention/test_modeling_v2_m3_draft_attention.py Removes strict expected-failure marking for context cells. Listed in l0_gr100? No.
tests/unittest/_torch/modeling_v2/models/minimax_m3/minimax_m3_nvfp4__sm_107__tp2/gemm/test_modeling_v2_m3_pinned_gemm.py Adds failure diagnostics while retaining bitwise tactic checks. Listed in l0_gr100? No.
tests/unittest/_torch/modeling_v2/models/minimax_m3/minimax_m3_nvfp4__sm_107__tp2/test_modeling_v2_m3_capture_boundary.py Adds refit cache-refresh coverage and adjusts test stand-ins. The new selector is listed in l0_cpu.yml.
tests/unittest/_torch/modeling_v2/models/minimax_m3/minimax_m3_nvfp4__sm_107__tp2/test_modeling_v2_m3_ctx_stack_route.py Tests CTX routing thresholds, capture behavior, and generic boundaries. Listed in l0_cpu.yml.
tests/unittest/_torch/modeling_v2/models/minimax_m3/minimax_m3_nvfp4__sm_107__tp4/attention/test_modeling_v2_m3_draft_attention.py Removes strict expected-failure marking for context cells. Listed in l0_gr100? No.
tests/unittest/_torch/modeling_v2/models/minimax_m3/minimax_m3_nvfp4__sm_107__tp4/gemm/test_modeling_v2_m3_mxfp8_pinned_gemm.py Adds failure diagnostics while retaining bitwise tactic checks. Listed in l0_gr100? No.
tests/unittest/_torch/modeling_v2/models/minimax_m3/minimax_m3_nvfp4__sm_107__tp8/attention/test_modeling_v2_m3_draft_attention.py Removes strict expected-failure marking for context cells. Listed in l0_gr100? No.
tests/unittest/_torch/modeling_v2/models/minimax_m3/minimax_m3_nvfp4__sm_107__tp8/gemm/test_modeling_v2_m3_pinned_gemm.py Adds failure diagnostics while retaining bitwise tactic checks. Listed in l0_gr100? No.
tests/unittest/_torch/models/test_minimax_m3.py Adds optimization eligibility, fallback, refit, and geometry tests. Several new selectors are listed in l0_cpu.yml; the embedding selector is listed in l0_gr100.
tests/unittest/_torch/models/test_minimax_m3_drafter_rows.py Tests drafter live-row selection, output restoration, and cleanup. Listed in l0_cpu.yml.
tests/unittest/_torch/modules/test_m3_ctx_clc_dispatch.py Tests CLC preparation failures, propagation, and success dispatch. Listed in l0_cpu.yml.
tests/unittest/_torch/modules/test_mxfp8_linear.py Adds SM107 small-M profile tests. Its new selector is listed in l0_gr100.
tests/unittest/_torch/modules/test_prequantized_mxfp8_streams.py Tests cross-stream tensor lifetime and stream recording. Listed in l0_gr100.
tests/unittest/_torch/moe/test_cutedsl_rubin_deterministic.py Tests deterministic FC2 repeatability and folded-residual parity. Listed in l0_gr100.
tests/unittest/_torch/moe/test_cutedsl_swiglu_oai_resolution.py Tests SwiGLU-OAI backend resolution and eligibility. Listed in l0_gr100.
tests/unittest/_torch/moe/test_m3_fold_shared_finalize.py Tests shared-output folding parity and refusal conditions. Listed in l0_gr100? No.
tests/unittest/_torch/moe/test_m3_router_tc_fp4_moe.py Tests router-produced FP4 payloads and MoE parity. Listed in l0_gr100.
tests/unittest/_torch/moe/test_moe_impl.py Updates activation-support expectations for SwiGLU-Bias. Listed through the unittest/_torch/moe directory in l0_cpu.yml.
tests/unittest/_torch/moe/test_router_gemm.py Tests router GEMM validation, determinism, split-K, replay, and SM107 integration. Listed in l0_gr100.
tests/unittest/_torch/moe/test_unpermute_residual.py Tests bitwise unpermute/residual behavior across layouts and contraction modes. Listed in l0_gr100.
tests/unittest/_torch/peft/test_moe_lora_model_path.py Adjusts stand-ins to disable shared-fold behavior in LoRA tests. Listed in l0_gr100? No.
tests/unittest/_torch/pyexecutor/kv_cache/test_kv_cache_v2_scheduler.py Tests append reserve, ordering, token caps, retries, and memoization. Listed in l0_gr100? No.
tests/unittest/_torch/pyexecutor/kv_cache/test_kv_connector_v2_prefix_real_manager.py Tests stable reuse probes and eviction ordering with a real cache manager. Listed in l0_gr100? No.

Description

Depends on #20623 (Rubin decode targets, which depends on #20306). This PR adds only the last commit; please review that commit.

This PR speeds up the MiniMax-M3 NVFP4 context (prefill) worker on Rubin (sm_107). Changes are on by default and engage on sm_107 only; each change that alters numerics or adds a kernel has an environment kill switch, and other GPUs keep the stock path.

Performance

Cold prefill (no cached prefix) on the TP2 context worker (Rubin, MiniMax-M3 NVFP4, Eagle3): 1,807–1,902 ms at 165K tokens (43–46K tok/s/GPU), 3.9–4.1 s at 323K and 9.7–10.0 s at 650K, about 1.3× faster at 165K and 1.5× at 650K than an earlier stock-path image (measured on different nodes; indicative).

Projections and boundaries

  • Fused QKV-index GEMM + cache producer (kernels/rubin/m3_qkv_fusion, TRTLLM_CTX_QKV_FUSED): above 1024 rows one MXFP8 GEMM (2-CTA, CLC tile scheduler) runs the QKV/index projection and writes the NVFP4 K/V and FP8 index-K caches from its epilogue; breakable-graph buckets take it through an eager break.
  • CLC MXFP8 GEMM (modules/m3_ctx_clc_gemm.py, TRTLLM_CTX_CLC_GEMM) for o_proj, the shared-expert gate_up and the dense MLP at ≥ 1024 rows.
  • Fused boundary norm + quantize (TRTLLM_CTX_NORM_MXFP8, TRTLLM_CTX_NORM_FP4): at ≥ 8192 rows the residual RMSNorm after the all-reduce also emits the next linear's MXFP8 input and the routed experts' NVFP4 input.
  • SwiGLU-OAI + MXFP8 quantize for the dense MLP (TRTLLM_CTX_SWIGLU_MXFP8), and one-entry MXFP8 hand-off slots between producers and the consuming linear, kept out of compiled graphs.

Attention

  • FP8 dense prefill on FA4 over the paged cache (fmha/msa_prefill.py, kill TRTLLM_MSA_DISABLE_DENSE_FA4); it needs flash-attn-4 4.0.0b19 with the FP8 rescale_threshold change (3rdparty/patches/fa4_fp8_rescale0.patch, applied to a copy of the installed package by examples/minimax_m3/rubin/setup_fa4.sh), and without it the dense layers keep fmha_sm100.
  • MSA combine writes the o_proj input as MXFP8 (TRTLLM_CTX_COMBINE_MXFP8), plus prefill tile selection, a segmented/split indexer proxy with SM-wide KV splits, and an in-place NVFP4 prefill output.
  • Eagle3 drafter: context attention on each request's last row only (TRTLLM_CTX_DRAFTER_LAST_ROW), o_proj/MLP only on the rows the draft loop reads (TRTLLM_CTX_DRAFTER_DEAD_ROWS), and the partial last page's K/V tails zeroed on private pages (TRTLLM_CTX_DRAFTER_KV_TAIL_ZERO).
  • MSA prefill host path: the adaptive plan's split decision is deferred, the k2q CSR build uses a scratch arena and per-shape buffers with a direct extension call, and per_token_valid_blocks is one NumPy pass.
  • MSA dependency (3rdparty/patches/msa_strided_paged_kv.patch): two correctness fixes for every GPU (V tail zeroed past kv_valid_cols, griddepcontrol.wait restored); its performance changes are gated to sm_107 at runtime.

MoE, router and scheduling

  • Deterministic CuteDSL NVFP4 MoE (TLLM_CUTEDSL_MOE_DETERMINISTIC): FC2 per permuted row with a fixed-order unpermute, optionally folding the shared-expert output (TLLM_M3_MOE_FOLD_SHARED).
  • Batch-invariant fixed-tile TF32 router for context steps (TRTLLM_CTX_ROUTER_TF32_FIXED), and the TF32 tensor-core router for 9–16-row generation steps on the built-in model (TRTLLM_M3_ROUTER_TC_GEN). The context router GEMM splits K into 8 fixed slices up to 8192 rows.
  • Context append reserve (opt-in, TLLM_CTX_APPEND_RESERVE=<tokens>): behind a long prefill a reserved token budget lets short appends join the same step, optionally shortest-first (TLLM_CTX_APPEND_RESERVE_SJF); unset, every model keeps the stock chunking.
  • Breakable prefill CUDA graphs capped at 2048 rows, and an example context-worker recipe with an opt-in FP4 MoE tactic table (TLLM_FP4_MOE_TACTIC_TABLE).

The sm_107 TP2 target (modeling_v2)

  • Context steps past 48 rows route on the fixed-tile TF32 router.
  • Prefill steps with at least 4096 context rows take the built-in CTX stack above (fused QKV GEMM + producer, the fused boundary norm with its MXFP8 / NVFP4 outputs, the built-in MoE forward). Eager steps only; Eagle3 capture layers keep the target's own boundary.
  • An example aggregated TP2 serving recipe in examples/minimax_m3/rubin/agg/.

Numerics. Most items are bitwise equal to their off switch. The fused QKV GEMM, the CLC GEMM, the FA4 dense prefill, the deterministic MoE FC2, the TF32 routers and the router's split-K use a different reduction order: deterministic, but not bitwise to the stock kernels. All of them except the router split-K are chunk-size invariant; the TF32 router splits K only up to 8192 rows, so its reduction order changes at 8192 rows and router logits (and, at near-ties, the selected experts) can differ between chunks of at most 8192 rows and larger ones.

External dependencies. flash-attn-4 is pinned to 4.0.0b19: setup_fa4.sh checks the FA4 file and the patch by SHA256. The MiniMax-M3 Rubin maintainers own it; an FA4 update re-derives the patch, re-runs the FP8 dense-prefill check and updates both pins, and the patch is dropped once FA4 ships the change.

Test Coverage

  • Bitwise vs the reference build on the TP2 context worker (cold 163,840-token prompt plus appends of 6 to 2,000 tokens): identical first-token logits on every turn, and every item's engagement line on both ranks.
  • Accuracy vs the reference build: GSM8K (1319) greedy and sampled with no significant McNemar difference, and identical per-request output and Eagle3 acceptance over 264 natural long-context requests.
  • Prefill timing parity with the reference build, same node, both run orders.
  • Unit tests on Rubin, one session per directory: attention/ (fmha, sparse/msa incl. the sm_107 gate cells), models/test_minimax_m3.py, moe/, thop/serial/, modeling/, the sm_107 modeling_v2 TP2 / TP4 / TP8 target directories, and the scheduler's append-reserve tests, all passing.
  • CI scope: the device-free tests (arch guards, resolution, tactic table) are cpu_only and listed in l0_cpu.yml; the sm_107 GPU tests have no CI stage yet (no Rubin test list), and the TF32 router / unpermute / fold tests exercise paths used only on the sm_107 context worker, so they are not registered on other GPUs in this PR.

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-compatible or api-breaking. For api-breaking, include BREAKING in 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.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

@peihu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #79102 [ run ] triggered by Bot. Commit: c1400ba Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #79102 [ run ] completed with state FAILURE. Commit: c1400ba
/LLM/main/L0_MergeRequest_PR pipeline #65161 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@peihu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@peihu-nv peihu-nv changed the title [None][perf] MiniMax-M3 NVFP4 context (prefill) path on Rubin (SM107) [None][perf] Optimize MiniMax-M3 NVFP4 context (prefill) path on Rubin (SM107) Oct 20, 2026
@peihu-nv
peihu-nv force-pushed the peihengh/m3-vr-sm107-ctx branch from 5a3dd8b to 9fe0dfb Compare October 20, 2026 15:22
@peihu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #79290 [ run ] triggered by Bot. Commit: 9fe0dfb Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #79290 [ run ] completed with state SUCCESS. Commit: 9fe0dfb
/LLM/main/L0_MergeRequest_PR pipeline #65312 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@peihu-nv
peihu-nv force-pushed the peihengh/m3-vr-sm107-ctx branch from 9fe0dfb to cf8a77e Compare October 21, 2026 14:50
@peihu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #79640 [ run ] triggered by Bot. Commit: cf8a77e Link to invocation

@peihu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #79640 [ run ] completed with state SUCCESS. Commit: cf8a77e
/LLM/main/L0_MergeRequest_PR pipeline #65572 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@SimengLiu-nv

Copy link
Copy Markdown
Collaborator

MiniMax-M3 on VR200 (sm_107): two small findings from a correctness bisect of this PR's context path

We bisected sporadic near-uniform next-token distributions on VR200 with this PR applied (r3 wheel: main +
#20306/#20623/#20629, CUDA 13.5, 107-real). They turned out to be model behaviour on raw /v1/completions prompts
that lack the BOD token ]~!b[. GB300 reproduces them to two decimals, and prepending 200034 removes all of them on
both platforms. None of this PR's switches is involved: TRTLLM_MSA_NVFP4_OUT_IN_PLACE and
TRTLLM_CTX_Q_E4M3_ROWS are bit-identical on/off at short prompts, and FA4 / the TF32 router only perturb rounding.
Two side findings:

  1. FA4 dense prefill misses the rule-1b band at the TP4 geometry for a short chunk over a long prefix.
    • Setup: test_minimax_m3_dense_prefill_fa4.py's _case / _reference / _run with
      NUM_HEADS, NUM_KV_HEADS = 16, 1 (TP4 of 64 / 4), one row (qo_len, kv_len) = (5, 900), seed 912, randn * 0.5
      pool and q.
    • Result: FA4 max error vs fp64 is 2.10e-3, fmha_sm100 1.76e-3, |ref|max 0.05. The test's bound
      stock_err * 1.05 + 2**-9 * |ref|max is 1.95e-3.
    • Every other row we tried at 16:1 is equal to fmha_sm100 (single-page prompts 5-170 tokens, (64, 640), a
      two-request batch). Low severity, but the upstream test only covers 32:2 heads, and with all four rows in one
      batch the larger rows' error hides the (5, 900) row. A single-row 16:1 case would catch it.
  2. test_minimax_m3_msa_selector.py::test_fused_selector_rejects_invalid_operator_contracts[scores_dtype-…] aborts
    the process on our sm_107 build instead of raising.
    • The op's TORCH_CHECK(scores.scalar_type() == torch::kFloat32, …) (minimaxM3SelectBlocksOp.cpp:47) should
      raise RuntimeError.
    • Instead pytest dies with Fatal Python error: Aborted, with no c10::Error text. It stopped the run before
      test_minimax_m3_tile_select.py and test_msa_backend.py.
    • We have not separated "this op" from "C++ exceptions do not propagate in a CUDA 13.5 / Rubin-base build", so a
      one-line check of any failing TORCH_CHECK on that toolchain would tell. The 51 functional selector tests pass on
      sm_107.

Happy to share the standalone repro (ctx_switch_repro.py: FA4 vs fmha_sm100 vs fp64 at 16:1, the Q E4M3 rows cast vs
aten, and the TF32 router vs fp64; everything else passed).

@SimengLiu-nv

Copy link
Copy Markdown
Collaborator

fmha_sm100 dense FP8 prefill returns NaN when a recycled partial page holds FP8 NaN bytes past kv_len (FA4 path is
protected; fmha_sm100 is not)

This PR's _zero_partial_page_v_tail documents the mechanism for FA4: P·V multiplies the rows past kv_len on a partial
last page by zero, and an FP8 NaN byte (0x7F / 0xFF) left in a recycled page turns the tile NaN. The same happens on the
fmha_sm100 dense prefill (run_msa_prefill_gqa → run_msa_sparse_gqa with kv_block_indexes=None), which has no
equivalent zeroing. That is the path on sm_100 / sm_103 for every dense layer, and on sm_107 under
TRTLLM_MSA_DISABLE_DENSE_FA4=1.

  • Repro, using the same harness as test_minimax_m3_dense_prefill_fa4.py:
    • Fill the whole FP8 pool with 0x7F (pool.view(torch.uint8).fill_(0x7F)).
    • Write finite K/V for each row's first kv_len tokens.
    • Run the dense branch with FA4 disabled (dense_prefill_fa4_enabled → False).
  • Result at 16:1 heads on sm_107:
    • The output is NaN for every row ending mid-page: single rows of 5, 9, 38, 62, 86, 110, 127, 129, 170 and
      (5, 900) tokens, and a (38, 86) batch.
    • Rows ending on a page boundary (128, (64, 640)) are finite.
    • FA4 is finite in all cases and matches the fp64 reference.
    • With finite stale bytes (randn * 20 past kv_len) both paths are correct, so the masking itself is fine; only
      non-finite stale bytes leak through 0·NaN.
  • Reachability: the M3 pools are zero-initialised (TRTLLM_M3_KV_POOL_ZERO_INIT=1), so a dense-layer V page holds a
    NaN byte only if some earlier request wrote a NaN V there. After that, every later request that gets that page as its
    partial last page returns NaN for the whole prefill tile. Applying the same V-tail zeroing (or masking V instead of
    only the scores) on the fmha_sm100 path would close it.

@peihu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@github-actions

Copy link
Copy Markdown

👎 Promotion blocked, new vulnerability found

Vulnerability report

Component Vulnerability Description Severity
py-filelock CVE-2026-112906 filelock is a platform-independent file lock for Python. From 4.1.0 until 4.2.1, SoftFileLock versions from 4.1.0 can reuse a stale observation when an attacker pre-dates and removes its own marker, at least two lock-user processes are waiting, coarse or matching modification times preserve the observation, and an honest contender creates a fresh marker on the reused inode, causing that live marker to be removed as stale. This issue is fixed in version 4.2.1. MEDIUM
py-filelock CVE-2026-112914 filelock is a platform-independent file lock for Python. From 4.1.0 until 4.2.1, SoftFileLock can restore a stale marker by name after moving it aside, allowing another local user with rename access in a non-sticky lock directory to swap in a symbolic link and, on a runtime that follows the link and a same-filesystem target, make the lock user hard-link one of its files into the lock directory. This issue is fixed in version 4.2.1. MEDIUM
py-filelock CVE-2026-112937 filelock is a platform-independent file lock for Python. From 4.1.0 until 4.2.1, ReadWriteLock can remove a randomized .filelock-* private-hard-link directory during cleanup, allowing another local user with rename access in a non-sticky parent to observe a live name or forge a dead-owner sweep name and rename a sibling directory onto it for deletion. This issue is fixed in version 4.2.1. MEDIUM
py-filelock CVE-2026-112940 filelock is a platform-independent file lock for Python. From 3.20.4 until 4.2.1, ReadWriteLock let SQLite reopen the database and side files by name; on POSIX systems an attacker with rename access in a non-sticky parent can swap those names to cause overwrite or unlink operations, while a writable adjacent hot journal is additionally required for attacker-chosen content overwrites. This issue is fixed in version 4.2.1. HIGH

@peihu-nv
peihu-nv marked this pull request as ready for review October 27, 2026 22:39
@peihu-nv
peihu-nv requested review from a team as code owners October 27, 2026 22:39
Reject unsupported OAI locality execution and pre-scaled FP4 handoffs, preserve activation offsets and refit cache allocations, release stale CLC weight arguments, and validate native input devices. Keep scheduler starvation caps and release the optional reserve for indivisible chunks. Add focused routing, FA4 geometry, refit, and rejection regressions plus explicit Rubin CI registrations.

Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Preserve requested-device plan synchronization and compatible split outputs. Keep draft admission within the optional append reserve and avoid non-consuming decode-graph MXFP8 placeholders.

Repair CI fixtures and runtime import isolation; retain all router BF16 terms while using exact operand promotion for TF32 MMA, with synchronized launch diagnostics and unchanged accuracy gates.

Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
…d reserves

Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
…ier shapes

Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
@peihu-nv
peihu-nv force-pushed the peihengh/m3-vr-sm107-ctx branch from bdba755 to dc2f5c4 Compare November 6, 2026 18:11
@peihu-nv

peihu-nv commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast --extra-stage "GR100-PyTorch-Post-Merge-1"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83136 [ run ] triggered by Bot. Commit: dc2f5c4 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83136 [ run ] completed with state FAILURE. Commit: dc2f5c4
/LLM/main/L0_MergeRequest_PR pipeline #68687 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants