[None][fix] Make FlashInfer sampling op wrappers opaque to Dynamo#16732
Conversation
|
/bot run |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughFlashInfer sampling and probability-computation wrappers are decorated with ChangesFlashInfer compiler control
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
PR_Github #60977 [ run ] triggered by Bot. Commit: |
|
PR_Github #60977 [ run ] completed with state
|
7ccf02b to
71cab53
Compare
|
/bot run |
|
PR_Github #61034 [ run ] triggered by Bot. Commit: |
|
PR_Github #61034 [ run ] completed with state
|
71cab53 to
80516ad
Compare
|
/bot run |
|
PR_Github #61066 [ run ] triggered by Bot. Commit: |
|
PR_Github #61066 [ run ] completed with state
|
|
/bot run |
80516ad to
4c47731
Compare
|
PR_Github #61072 [ run ] triggered by Bot. Commit: |
|
PR_Github #61072 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #61093 [ run ] triggered by Bot. Commit: |
|
PR_Github #61093 [ run ] completed with state
|
4c47731 to
cc2555c
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #61133 [ run ] triggered by Bot. Commit: |
The torch.compile'd spec-decode sampling functions (sampling_utils.py) inline these plain-Python wrappers, and nothing below them is opaque to Dynamo: flashinfer's kernels are reached via get_sampling_module(), a functools.cache'd lazy JIT bootstrap whose custom-op registration is a no-op in flashinfer. Dynamo bypasses the functools.cache wrapper and traces the bootstrap body, so every untraceable builtin in it (posix.stat, datetime.now, lock allocation, lru_cache'd get_cuda_version) emits a warn-once and becomes a permanent graph break whose call re-executes eagerly on every invocation of the compiled sampler, defeating the bootstrap's cache fast path. Decorate all wrappers with torch.compiler.disable: each becomes a single clean graph break, the Dynamo warnings disappear, and the functools.cache fast path is restored. Kernels already executed eagerly after the old graph breaks, so numerics and CUDA-graph behavior are unchanged. The decorator is applied through a typed shim (_compiler_disable) because torch.compiler.disable ships untyped: used directly it fails mypy strict (untyped-decorator on every wrapper) and cascades no-any-return errors into sampling_utils.py. Signed-off-by: Xianjie <5410381+qiaoxj07@users.noreply.github.com>
cc2555c to
de8c7c8
Compare
|
/bot kill |
|
/bot run --disable-fail-fast |
|
PR_Github #61220 [ kill ] triggered by Bot. Commit: |
|
PR_Github #61133 [ run ] completed with state |
|
PR_Github #61220 [ kill ] completed with state |
|
PR_Github #61221 [ run ] triggered by Bot. Commit: |
|
PR_Github #61221 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #61283 [ run ] triggered by Bot. Commit: |
|
PR_Github #61283 [ run ] completed with state |
…nnahz/dep-1083-port-flashinfer-stable-va-lifecycle-for-native-all-reduce * 'main' of https://github.com/NVIDIA/TensorRT-LLM: (83 commits) [None][feat] Bind SourceIdentity to checkpoint artifacts (NVIDIA#16159) [None][infra] Waive 4 failed cases for main in pre-merge 49550 (NVIDIA#16798) [None][fix] Make FlashInfer sampling op wrappers opaque to Dynamo (NVIDIA#16732) [None][feat] top-k: route decode to CuTe DSL GVR top-k in e2e (NVIDIA#16420) [None][feat] Default GLM-5 to the Python KV-cache transceiver (NVIDIA#16524) [None][chore] Add NVTX ranges to per-iteration ADP sync points in PyExecutor (NVIDIA#16422) [https://nvbugs/6426850][test] Unwaive Qwen3.5 397B NVFP4 ADP4 TRTLLM test (NVIDIA#16348) [https://nvbugs/6445456][fix] Restore inplace ops for functionalization v2 (NVIDIA#16410) [None][infra] Waive 1 failed cases for main in pre-merge 49229 (NVIDIA#16786) [None][fix] Load DeepSeek V4 mixed-precision NVFP4 checkpoints (NVIDIA#16433) [None][feat] ADP conversation router: configurable least-queued placement for new conversations (NVIDIA#16294) [None][infra] Waive 1 failed cases for main in pre-merge 49424 (NVIDIA#16780) [None][infra] Waive 1 failed cases for main in pre-merge 49424 (NVIDIA#16781) [TRTLLMINF-188][infra] Require approval for PerfSanity wildcard runs (NVIDIA#16777) [TRTLLM-13969][feat] Support MiniMax M3 for Disaggregated Serving (NVIDIA#16017) [NVIDIA#11932][fix] Filter CUTLASS MoE GEMM tile configs by device shared memory on SM121 (NVIDIA#12704) [None][chore] Remove attention backend test waivers (NVIDIA#16723) [TRTLLM-14540][perf] Skip fp32 state round-trip in FlashInfer GDN pre… (NVIDIA#16703) [TRTLLM-13694][feat] Add IBDB recipe provenance and refresh configs (NVIDIA#16254) [None][infra] Preview/bump/main (NVIDIA#16758) ... Signed-off-by: Hannah Zhang <hannahz@nvidia.com>
…IDIA#16732) Signed-off-by: Xianjie <5410381+qiaoxj07@users.noreply.github.com>
Description
The
@torch.compiled spec-decode sampling functions insampling_utils.py(compute_probs_from_logits,sampling_batch_spec_dec_one_model,sampling_batch_spec_dec_one_model_for_rejection) inline the plain-Python FlashInfer op wrappers insampler/ops/flashinfer.py, and nothing below those wrappers is opaque to Dynamo:get_sampling_module(), afunctools.cache-wrapped lazy JIT bootstrap.register_custom_op/register_fake_opare deliberate no-ops (flashinfer/utils.py, citingtorch.library.custom_opoverhead), so the kernel entry points are plain closures over an FFI module.Dynamo ignores
functools.cache/lru_cachewrappers and traces the wrapped body directly (torch/_dynamo/variables/functions.py,WrapperUserFunctionVariable). Tracing the JIT bootstrap hits untraceable builtins (posix.stat,datetime.now,_thread.allocate_lock,sys._getframe, plus nestedlru_cached helpers), each emitting a warn-onceUserWarningand a permanent graph break. Because the cache wrapper is bypassed inside the compiled artifact, the break-site calls (file stat, module re-load) re-execute eagerly on every invocation of the compiled sampler, defeating the bootstrap's cache fast path. In any MTP/spec-decode serving log this shows up as a burst ofDynamo does not know how to trace the builtin .../functools.lru_cache-wrapped functionwarnings per rank.Fix: decorate every wrapper in
sampler/ops/flashinfer.pywith@torch.compiler.disable. Each wrapper becomes a single clean graph break, the warnings disappear, and FlashInfer'sfunctools.cachefast path is restored. The kernels already executed eagerly after the old graph breaks, so numerics and CUDA-graph behavior are unchanged. Registering the wrappers astorch.library.custom_opinstead is not viable: the merged dual-mode randomness signature (torch.Generator+Union[int, torch.Tensor]seed/offset, intentional as of #16365) uses parameter types unsupported by the custom-op schema. This follows the existing@torch.compiler.disablepattern used for the cute_dsl fmha wrappers.Test Coverage
A/B on GB300 (torch 2.12 / flashinfer 0.6.15), calling
sampling_batch_spec_dec_one_modelandsampling_batch_spec_dec_one_model_for_rejectionundertorch.compilewith fixedseed/offsettensors — identical script, stock image vs. this patch bind-mounted:Dynamo does not know how to trace the builtinwarningsfunctools.lru_cache-wrappedwarningsExisting tests covering these paths:
tests/unittest/_torch/sampler/and the speculative one-model sampling tests.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.
Dev Engineer Review
tensorrt_llm/_torch/pyexecutor/sampler/ops/flashinfer.pymodule docstring to document the rationale: preventing TorchDynamo from tracing FlashInfer’s lazy JIT bootstrap/cache initialization during Python wrapper execution._compiler_disablehelper that appliestorch.compiler.disable(fn)while preserving the wrapped callable type viacast.@_compiler_disable(without changing their function signatures or internal FlashInfer call logic):top_k_top_p_sampling_from_logits_opsampling_from_probs_optop_k_sampling_from_probs_optop_p_sampling_from_probs_opsoftmax_optop_k_mask_logits_optop_p_renorm_probs_opcompute_probs_from_logits_opQA Engineer Review
No test changes.