Repository navigation
[None][feat] Add low-latency host task dispatch mode for guided decoding - #15863
Conversation
📝 WalkthroughWalkthroughThis PR adds a low-latency dispatch mode for CUDA host function launches. The C++ binding gains a ChangesLow-latency host dispatch
Estimated code review effort: 2 (Simple) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant Executor
participant hostfuncPy as hostfunc.py
participant Bindings as bindings.launch_hostfunc
participant CUDA as CUDA Runtime
Executor->>hostfuncPy: set_low_latency_dispatch(enabled)
hostfuncPy->>hostfuncPy: update _low_latency_dispatch
hostfuncPy->>Bindings: launch_hostfunc(stream, freeUserData, low_latency, callback)
Bindings->>CUDA: cudaLaunchHostFunc_v2(cudaHostTaskSpinWait) or cudaLaunchHostFunc
CUDA-->>Bindings: launch result
Related issues: None specified. Related PRs: None specified. Suggested labels: low-latency, hostfunc, prototype Suggested reviewers: None specified. Poem A rabbit spins instead of sleeps, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cpp/tensorrt_llm/nanobind/runtime/hostfunc.cpp`:
- Around line 84-100: The fallback in `launchHostFunc` logs a warning every time
`lowLatency` is true on CUDA <13.2, which can spam the hot path. Update the
`launchHostFunc` logic in `hostfunc.cpp` to emit the fallback warning only once
(for example via a static once-flag or equivalent), while keeping the fallback
`cudaLaunchHostFunc` call unchanged. Also reconcile the
`enable_low_latency_host_dispatch` documentation in `llm_args.py` so it matches
the intended once-only or silent fallback behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 338754ea-936b-4c6a-9dd1-b2587064eb6b
📒 Files selected for processing (8)
cpp/tensorrt_llm/nanobind/runtime/hostfunc.cpptensorrt_llm/_torch/hostfunc.pytensorrt_llm/_torch/pyexecutor/_util.pytensorrt_llm/llmapi/llm_args.pytests/integration/defs/accuracy/test_llm_api_pytorch.pytests/unittest/api_stability/references/llm.yamltests/unittest/bindings/test_hostfunc.pytests/unittest/llmapi/test_llm_args.py
|
/bot run |
|
PR_Github #57078 [ run ] triggered by Bot. Commit: |
|
PR_Github #57078 [ run ] completed with state
|
|
/bot run |
|
PR_Github #57197 [ run ] triggered by Bot. Commit: |
|
PR_Github #57197 [ run ] completed with state
|
|
/bot run |
|
PR_Github #57220 [ run ] triggered by Bot. Commit: |
|
PR_Github #57220 [ run ] completed with state
|
|
/bot run |
|
PR_Github #57265 [ run ] triggered by Bot. Commit: |
|
PR_Github #57265 [ run ] completed with state |
|
/bot run |
|
PR_Github #57269 [ run ] triggered by Bot. Commit: |
|
PR_Github #57269 [ run ] completed with state
|
|
/bot run |
|
PR_Github #57339 [ run ] triggered by Bot. Commit: |
The CUDA < 13.2 fallback warning was emitted on every launchHostFunc call, producing unbounded log spam on guided-decoding workloads. Guard with std::once_flag so it fires at most once per process lifetime. Signed-off-by: Aurelien Chartier <2567591+achartier@users.noreply.github.com>
…patch docs The field description said the CUDA < 13.2 fallback is silent, but the implementation logs a one-time warning. Update the docs to match. Signed-off-by: Aurelien Chartier <2567591+achartier@users.noreply.github.com>
00a3bf1 to
abc6479
Compare
|
/bot run |
|
PR_Github #57638 [ run ] triggered by Bot. Commit: |
|
PR_Github #57638 [ run ] completed with state
|
…lm_args create_py_executor_instance can receive a SimpleNamespace (e.g. in unit tests) instead of a real TorchLlmArgs. Use getattr with a False default so callers that don't set the field still work. Signed-off-by: Aurelien Chartier <2567591+achartier@users.noreply.github.com>
|
/bot run |
|
PR_Github #57673 [ run ] triggered by Bot. Commit: |
|
PR_Github #57673 [ run ] completed with state
|
|
/bot run |
|
PR_Github #57784 [ run ] triggered by Bot. Commit: |
|
PR_Github #57784 [ run ] completed with state
|
|
/bot run |
|
PR_Github #57821 [ run ] triggered by Bot. Commit: |
|
PR_Github #57821 [ run ] completed with state
|
|
/bot run |
|
PR_Github #57834 [ run ] triggered by Bot. Commit: |
|
PR_Github #57834 [ run ] completed with state
|
|
/bot run |
|
PR_Github #57873 [ run ] triggered by Bot. Commit: |
|
PR_Github #57873 [ run ] completed with state |
…ing (NVIDIA#15863) Signed-off-by: Aurelien Chartier <2567591+achartier@users.noreply.github.com>
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Description
Adds
enable_low_latency_host_dispatch(defaultFalse) toTorchLlmArgs.When enabled, CUDA host callbacks are dispatched via
cudaLaunchHostFunc_v2with
cudaHostTaskSpinWaitinstead of the default blocking mode, reducingguided-decoder callback latency by keeping the CPU thread spinning until the
GPU event fires rather than sleeping.
This matters most when Eagle3 speculative decoding is combined with guided
decoding: in that configuration the guided-decoder
@hostfunccallbacks arecaptured inside the CUDA graph (called from
_execute_guided_decoder_if_presentduring the target model forward pass), so the spin-wait policy applies to every
decode step and the per-step wake-up latency directly affects inter-token delay.
Requires CUDA 13.2+ (
cudaHostTaskSyncModeenum,cudaHostTaskSpinWait = 0x1).Falls back silently to
cudaLaunchHostFuncon older drivers with a log warning.Files changed:
cpp/tensorrt_llm/nanobind/runtime/hostfunc.cpp— addbool lowLatencyparam; usecudaLaunchHostFunc_v2behindCUDART_VERSION >= 13020guardtensorrt_llm/_torch/hostfunc.py— module-level_low_latency_dispatchflag +set_low_latency_dispatch()settertensorrt_llm/_torch/pyexecutor/_util.py— call setter fromcreate_py_executor_instancetensorrt_llm/llmapi/llm_args.py—TorchLlmArgsfield (status="prototype")Test Coverage
Unit tests (no GPU required beyond existing fixture):
tests/unittest/bindings/test_hostfunc.py—test_low_latency_dispatch: verifies the module-level flag is toggled and hostfuncs fire correctly in both dispatch modestests/unittest/llmapi/test_llm_args.py—TestEnableLowLatencyHostDispatch: default value, explicit True/False, YAML round-trip, invalid-type rejectionAPI stability:
tests/unittest/api_stability/references/llm.yaml— field entry added (required to keeptest_api_statusgreen)Integration test:
tests/integration/defs/accuracy/test_llm_api_pytorch.py—test_guided_decoding_with_eagle3_low_latency_dispatch: exercises the flag with Eagle3 one-model + xgrammar/llguidance + CUDA graphs on Hopper+, validating end-to-end correctness viaJsonModeEvalPR Checklist
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.