Repository navigation
Conversation
Signed-off-by: Ruodi Lu <ruodil@users.noreply.github.com>
|
Requesting the first standard CI run for unchanged head The documented 16 CPU tests/60 subcases are local results, not full-build or GPU validation. A standard CI pass alone will not establish exact-case context-plan performance acceptance. Draft and the unchecked GPU/performance checklist are retained until the required evidence is available. |
|
/bot run |
|
PR_Github #86614 [ run ] triggered by Bot. Commit: |
|
PR_Github #86614 [ run ] completed with state |
trtllm-agent-review
left a comment
There was a problem hiding this comment.
Thanks for the PR. Moves the opt-in context-plan attempt in TrtllmAttention.forward after output allocation, so callers that pass output=None can use plans, and extends plans to the exact dense FallbackFmha for non-quantized BF16/FP16 calls, with admission rechecks on every hit and 16 CPU tests.
Reviewed at commit a0adae57c1 (2 files, +547/−8).
The FlashInfer-family plans that the reorder newly enables for output=None callers (Qwen3.5 eager prefill with an FP8 KV cache or more than 4 requests) were reviewed too; they match the regular path, and the pre-merge B200 Qwen3.5 eager accuracy tests now run them.
Request changes: 1 Blocker needs fixing before merge.
Blockers (1)
- (B5: User-visible switch behavior) The output_gate guard refuses every Qwen3.5 eager prefill call, so the new FallbackFmha plan never runs for the 1-4-request BF16 batches it targets (trtllm.py:3163)
Nice to have (8): 8 inline, 0 below
- (R4: Bypassing framework mechanisms) Plan admission switches on concrete FMHA classes in the backend instead of a capability the library declares, so each newly planned library needs backend edits (trtllm.py:3223)
- (R1: PR process) Draft PR #21984 deletes fmha/flashinfer_trtllm_gen.py and rewrites these same plan lines; the two PRs need a merge order (trtllm.py:3221)
- (R3: Repository rules) Two new test helpers are unannotated, and this one shadows the test's q, against CODING_GUIDELINES.md (test_trtllm_context_plan.py:217)
- (R6: Required documentation) The plan docstrings still say plans run only trtllm-gen, but they now also run FallbackFmha (thop) without the KV-pool recheck (trtllm.py:125)
- (N4: Performance optimization opportunity) Every FallbackFmha plan hit recomputes layer-static checks such as quant_mode.has_any_quant(), about 8 us of host time per planned layer (trtllm.py:3296)
- (N6: Duplication and reuse) The block-extent rule is now copied in three places, and the expected KV DataType re-derives torch_dtype_to_binding (trtllm.py:3234)
- (N3: Missing or ineffective tests) The new tests never set output_gate, FP16 or a KV-dtype mismatch and never compare the plan with the regular path; some subcases cannot fail (test_trtllm_context_plan.py:145)
- (N5: Code tidiness) Dead and redundant admission code: a second copy of the six metadata checks, unreachable conditions in the new gate, and a redundant is_fallback slot (trtllm.py:3213)
What this review checked
- The moved plan attempt keeps forward()'s error contract: the variable-window and DSv4 ValueErrors still raise before any output is allocated (trtllm.py:2721-2732, 2757-2761), and a plan hit returns the same output tensor the regular path would.
- On the FallbackFmha plan path the native op gets the same FmhaParams as PhasedFmha.forward: the same context_params (phased.py:277-324), total_num_blocks 0 on both paths (fallback.py:87, phased.py:373), a no-op prepare_workspace, and default sparse runtime params equal to what prepare_sparse_runtime_params returns for dense layers.
- 9 of the 16 new tests fail against the base trtllm.py; they run pre-merge in l0_cpu (cpu_only) and are deselected on the GPU stages.
- Not covered: No GPU run; the TTFT of the NVBug 7017171 case at this head is unmeasured.
- Not covered: The NVBug's exact configuration (eager or compiled prefill, KV dtype) is not on the PR page, so which half of the change it exercises is inferred from the code.
- Not covered: The generated native FmhaParams readers are build artifacts; that the C++ op never reads output_gate rests on the sources under cpp/ and the generator script.
Automated review by trtllm-agent-review. If a point is wrong, reply in its thread. Once you have pushed code changes and replied in every Blocker thread, the bot re-checks the Blockers within a few hours.
| from .fmha.flashinfer_trtllm_gen import FlashInferTrtllmGenFmha | ||
| fmha = self._fmha_manager.select(self, q, None, None, metadata, fwd) | ||
| if not isinstance(fmha, FlashInferTrtllmGenFmha): | ||
| plan.is_fallback = type(fmha) is FallbackFmha |
There was a problem hiding this comment.
[Nice to have] (R4: Bypassing framework mechanisms) Plan admission is now decided here by concrete class (type(fmha) is FallbackFmha / isinstance(fmha, FlashInferTrtllmGenFmha)), and FallbackFmha's plan scope (dtypes, quant mode, KV dtype, mixed precision) lives in TrtllmAttention. ATTENTION_DEVELOPER_GUIDE.md section 3.2.2 has libraries "declare shared capabilities through class attributes ... and override only _is_available() and _is_supported() for implementation-specific checks", and the plan already reads such attributes (NEEDS_BLOCK_EXTENT, supports_workspace_reclamation).
As written, this has three effects:
- FlashInfer subclasses such as
GqaDecodeFmhaare planned viaisinstance, with no recheck on a hit. FallbackFmhasubclasses are refused.- The next library to plan ([None][refactor] Remove the FlashInfer trtllm-gen FMHA library #21984's
TrtllmGenFmha) needs another branch here.
Suggestion:
- Add a
supports_context_planclass attribute onPhasedFmha, True onFlashInferTrtllmGenFmhaandFallbackFmha. - Add a library hook such as
context_plan_supported(q, metadata, fwd) -> boolthatFallbackFmhaoverrides with its scope. - Check both at build time, and call the hook on every hit for every library.
type(fmha).forward is PhasedFmha.forwardkeeps the exact-type protection without naming classes.- The hook can also refuse forward-argument fields it does not know, so a field added later turns the plan off instead of being replayed.
There was a problem hiding this comment.
Follow-up in 0837bcee0a4f:
Deferring the shared capability/hook redesign to the FMHA library work, including #21984. This repair keeps the exact FallbackFmha protection, fixes the offered-gate blocker, and retains per-call recipe and mutable-metadata guards. A cross-library API change would enlarge this draft beyond the verified repair.
| or metadata.enable_flash_mla): | ||
| return plan | ||
| from .fmha.fallback import FallbackFmha | ||
| from .fmha.flashinfer_trtllm_gen import FlashInferTrtllmGenFmha |
There was a problem hiding this comment.
[Nice to have] (R1: PR process) Open draft #21984 ("Remove the FlashInfer trtllm-gen FMHA library") deletes fmha/flashinfer_trtllm_gen.py and rewrites exactly these lines:
- this import and the
isinstancegate becomeTrtllmGenFmha; - both
total_num_blocksexpressions (here and in_run_context_plan) go through a new_context_plan_num_blockshelper.
It still attempts the plan before output allocation. The new test imports FlashInferTrtllmGenFmha at module scope (test_trtllm_context_plan.py:16-18), so if #21984 lands first, this module fails at collection on every stage that runs unittest/_torch/attention.
Please link the two PRs and agree a merge order. Whichever lands second has to port the moved attempt, the FallbackFmha branch and the test.
There was a problem hiding this comment.
Follow-up in 0837bcee0a4f:
Related PR: #21984 . It is still an open Draft; no merge-order agreement has been established. This revision targets current main. Whichever PR lands second must port the post-allocation plan attempt, FallbackFmha coverage, and the tests to the resulting library names/API. Keeping this coordination item open.
| plan.counter_rows = (metadata.max_num_sequences | ||
| or metadata.max_num_requests) | ||
| plan.total_num_blocks = fmha._get_total_num_blocks(metadata) | ||
| plan.total_num_blocks = (fmha._get_total_num_blocks(metadata) |
There was a problem hiding this comment.
[Nice to have] (N6: Duplication and reuse) fmha._get_total_num_blocks(metadata) if fmha.NEEDS_BLOCK_EXTENT else 0 now appears in three places: here, at line 3302, and in PhasedFmha.forward (phased.py:373). The backend also calls the library's private method. One public PhasedFmha.block_extent(metadata) keeps the plan in step with the regular path; #21984 adds a similar _context_plan_num_blocks.
Line 3150 can also become torch_dtype_to_binding(q.dtype) (tensorrt_llm/_utils.py:371, as FlashInfer does at flashinfer_trtllm_gen.py:700), which removes the need for the new module-level DataType import.
There was a problem hiding this comment.
Follow-up in 0837bcee0a4f:
Replaced the dtype mapping with torch_dtype_to_binding and removed the DataType import. Deferring the public block_extent API to the coordinated PhasedFmha/#21984 library change so this repair does not introduce a second API shape ahead of that work.
There was a problem hiding this comment.
[Nice to have] (N5: Code tidiness) tensorrt_llm/_torch/attention/backends/trtllm.py:3213: - trtllm.py:3213-3218: _build_context_plan still repeats the six metadata checks that _is_plain_context_call now owns (trtllm.py:3118-3123). Its only callers (trtllm.py:3292, trtllm.py:3306) run after that check has passed, so this copy can never fire, and a rule added next to it later would run only at plan build. Keep only the kv_cache_manager, block_offsets and workspace checks there.
- trtllm.py:3145-3147, trtllm.py:3164-3166, trtllm.py:3170-3171, trtllm.py:3176:
_fallback_context_plan_eligiblere-tests conditions that are already guaranteed. Dropping them leaves only the conditions that define the fallback scope:fwd.output is None,qk_fp8_per_tensor,v_fp8_per_tensorandsparse_backend_argsare already rejected by_is_plain_context_call;is_mla_enableandsparse_paramscannot be set, because such layers havecache_context_planoff (trtllm.py:2214-2216);sparse is not Nonealways holds for adefault_factoryfield;- the sage block counts are implied by
sage_attn_qk_dtype is None.
- trtllm.py:125:
is_fallbackduplicatesplan.fmha_cls is FallbackFmha. It is read only at trtllm.py:3296, afterfmha_clswas found to be set, and it is True on refused plans whosefmha_clsis None.
There was a problem hiding this comment.
Follow-up in 0837bcee0a4f:
Removed the six repeated metadata checks from _build_context_plan, removed is_fallback in favor of the selected class, and removed fallback checks already owned by common per-call admission (per-tensor FP8 and sparse backend args). I retained the explicit optional-output/layer guards and conservative Sage/sparse-carrier checks. The recipe table now checks both build and hit admission, including independently set Sage block counts; broader guard removal is deferred from this repair.
|
Re-review status. @trtllm-agent-review re-reviews this PR once all three of these hold since its last review:
Not met yet:
The bot checks again in its next round. |
Signed-off-by: Ruodi Lu <ruodil@users.noreply.github.com>
|
/bot run |
|
PR_Github #87082 [ run ] triggered by Bot. Commit: |
|
PR_Github #87082 [ run ] completed with state
|
trtllm-agent-review
left a comment
There was a problem hiding this comment.
Thanks for the PR. Moves the opt-in context-plan attempt in TrtllmAttention.forward after output allocation and extends context plans to the dense FallbackFmha for non-quantized BF16/FP16 calls; the follow-up stops refusing an offered output gate, so eager Qwen3.5 prefill now uses the plan.
Reviewed at commit 0837bcee0a (4 files, +758/−19).
This re-review covers the follow-up commit since the earlier review at a0adae5: the earlier Blocker is fixed, and it found no new Blocker or possible blocker.
Re-review: approve: no Blocker found.
What this review checked
- The earlier Blocker is fixed: an offered output gate no longer refuses the FallbackFmha plan (trtllm.py:3165), and no context path consumes the gate (FallbackFmha.run_context only calls thop.run_context; the GQA decode libraries set output_gate_applied only in generation), so the module still applies it exactly once (attention.py:1106-1107).
- Eager Qwen3.5 BF16 prefill of 1-4 requests on SM100/SM103 now builds and hits the FallbackFmha plan, and the plan's context call matches the context part of PhasedFmha.forward: the same prepare_workspace, a zero block extent, the same max q/kv lengths, and the same window and KV-scale defaults.
- The checks removed from _build_context_plan and _fallback_context_plan_eligible all live in _is_plain_context_call, which runs before every caller, and the cached _context_plan_unquantized flag is refreshed by update_quant_config, the only writer of quant_mode on a layer that can plan.
- Not covered: No GPU run; the new GPU test was checked by reading the code only.
- Not covered: The head's pre-merge CI run stopped on an infrastructure failure (a package-sanity stage could not download its wheel, and fail-fast aborted the other stages), so the new GPU test has no CI result yet.
- Not covered: No performance measurement for NVBug 7017171.
Automated review by trtllm-agent-review. If a point is wrong, reply in its thread. Once you have pushed code changes and replied in every Blocker thread, the bot re-checks the Blockers within a few hours. A Blocker you think should not be fixed needs no code change: reply in its thread with the reason and the evidence.
Signed-off-by: Ruodi Lu <ruodil@users.noreply.github.com>
|
/bot run |
|
PR_Github #87316 [ run ] triggered by Bot. Commit: |
|
PR_Github #87316 [ run ] completed with state
|
|
/bot run |
|
PR_Github #87578 [ run ] triggered by Bot. Commit: |
|
PR_Github #87578 [ run ] completed with state
|
Signed-off-by: Ruodi Lu <ruodil@users.noreply.github.com>
|
/bot run |
|
PR_Github #88030 [ run ] triggered by Bot. Commit: |
|
PR_Github #88030 [ run ] completed with state |
Signed-off-by: Ruodi Lu <ruodil@users.noreply.github.com>
|
/bot run |
|
PR_Github #88771 [ run ] triggered by Bot. Commit: |
There was a problem hiding this comment.
⚠️ Pyrefly: 5 diagnostics from your changes
Found after merging this PR (d1e8ddb) into the latest main (abeaf94). Line numbers refer to the merged code.
This check is advisory and does not block the PR for now. Some of the diagnostics below may come from a semantic conflict with the latest main, so please look at each one carefully and decide whether to fix it. Resolve this conversation before merging the PR.
tensorrt_llm/_torch/attention/backends/trtllm.py:5107
[missing-attribute] Object of class `_ContextPlan` has no attribute `workspace`
tensorrt_llm/_torch/attention/backends/trtllm.py:5121
[missing-attribute] Object of class `_ContextPlan` has no attribute `total_num_blocks`
tensorrt_llm/_torch/attention/backends/trtllm.py:5183
[missing-attribute] Object of type `_ContextPlan | None` has no attribute `fmha_cls`
tensorrt_llm/_torch/attention/backends/trtllm.py:5191
[missing-attribute] Object of class `Fmha` has no attribute `_get_total_num_blocks`
tensorrt_llm/_torch/attention/backends/trtllm.py:5192
[missing-attribute] Object of class `Fmha` has no attribute `NEEDS_BLOCK_EXTENT`
|
PR_Github #88771 [ run ] completed with state Resource maintenance in LLM/main/L0_Test-x86_64-Single-GPU #5719: AWS-PDX-SLURM-1 is unavailable for maintenance on 2026-12-02 17:00-23:00 UTC; H100_PCIe-PyTorch-Perf-1 was retired from main.
|
Description
Context plans were attempted before output allocation, so callers leaving
output=Nonecould not use them. Allocate and validate the output first, then extend context-plan coverage to the exact denseFallbackFmhaimplementation for non-quantized BF16/FP16 with matching KV/output dtypes. Bind fresh parameters and tensor references for every layer.The review follow-up also allows an offered
output_gate: the context kernel does not consume it, and the attention module still applies it whenoutput_gate_appliedis false. This makes eager Qwen3.5 prefill eligible instead of admitting and then refusing its fallback plan. Unsupported recipes, mixed-precision staging, speculative/beam/Helix cases and mixed context/generation batches keep the regular path. Model defaults are unchanged; experimental native attribute-name reuse is outside this PR.Cache the quantization eligibility result when
update_quant_configrefreshes the layer configuration, while retaining mutable per-call and metadata checks. Remove duplicate admission checks and the redundant fallback tag, use the shared dtype conversion, and document the plan lifecycle in the attention developer guide.Draft: the affected-path GPU regression passed on H100, B200 and B300. Controlled exact-case performance acceptance remains required.
Validation
Previous validation head:
b962ac649075fdf5c7979b152959ee3522204f67. The focused validation below used source follow-up0837bcee0a4f035ea9578db7b4423f92b16b57c4. That follow-up’s merge-tree against main38b3273d289ea24ee2e4d2d47f28817ca1cc61a1is clean; the merged source preserves the newer main argument documentation, variable-window/locality guards, and post-allocation plan order.The offered-gate regression first fails on the previous implementation in both existing/missing-output Fallback cases, then passes after the correction.
43 focused CPU tests and 55 subtests pass using this checkout's backend source with compatible C-wheel support modules and CUDA stubs, CPU tensors and no GPU devices. Cases cover BF16/FP16, offered gates, KV dtype mismatch, the ordinary
PhasedFmha.forwardparameter oracle, plan build/hit recipe guards, fresh two-layer bindings, metadata invalidation, and quantization-configuration refresh.Add four GPU cases for two layers and real KV pages: batch size 1/4, fresh/cached-prefix context, planned versus ordinary outputs and KV writes, and explicit fallback/shared-plan identity. The existing H100/B200 attention-directory test entries collect the file. Local collection succeeded and skipped the four cases without CUDA. On
b962ac6, the L0 #73071 JUnit report records all four cases passing on each of H100, B200 and B300 (12 GPU passes). The CPU context-plan module also recorded 43 passes on each architecture.Applicable pre-commit checks pass. The advisory Pyrefly hook reports that Pyrefly is not installed; no type-check success is claimed. No full TensorRT-LLM build or full unit-suite pass is claimed.
Previous head
a0adae57c1c00e53d8810c64e75f2d51275e1882passed PR_Github #86614 / L0 #71796. That result applies to the previous head.L0 #72448 on
eacd4c9failed two CPU assertions in the GB300 Qwen3.5 AgentX TEP8/TEP16 decode recipes plus their parent suite. Upstream #22370 updated the test to allow the recipes’ explicit transfer window. The transceiver-config test module passes all 262 cases on bothmain(2bb2e88394) and its clean merge with this head in a standalone pytest run. L0 #72683 reproduced the same CPU assertions oneacd4c9. The PR branch now includesmainat99ad36e76be4, including the upstream fix. All 262 cases in the transceiver-config test module passed locally on the resulting merge. Standard CI onb962ac6passed in PR_Github #88030 / L0 #73071. The controlled exact-case performance run remains pending.Merged
mainated9650f2123bintod1e8ddbfebf7, preserving the upstreamFmhaV2Fmhaimport and context-plan dispatch after output allocation. Python compilation, merge-tree and diff checks passed. The cached local wheel predates the upstream FMHA modules and could not collect the CPU suite. Standard L0 is needed to validate the merged native backend and GPU regressions on this head.Remaining acceptance and integration
Run controlled main-based exact-case performance validation for NVBug 7017171. November 11 B300 experiments used different production heads, and the combined experiment also included native name reuse; they do not validate this head or establish bug closure.
Open Draft #21984 removes the FlashInfer FMHA module and changes these context-plan paths. Both currently target
main; maintainers still need to choose the landing order, and whichever lands second must port the allocation order, fallback coverage and tests. No merge-order agreement is claimed.PR Checklist