You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Performance] Guided decoding with one-model speculative decoding drains the GPU 4 times per eager step, even when no request is guided #21460
General perf<NV>Broad performance issues not specific to a particular componentSpeculative Decoding<NV>MTP/Eagle/Medusa/Lookahead/Prompt-Lookup-Decoding/Draft-Target-Model/ReDrafter
TensorRT-LLM 1.4.0rc1 (nvcr.io/nvidia/tensorrt-llm/release:1.4.0rc1), PyTorch backend, trtllm-serve. The same code is on current main.
1x B300 SXM6, also seen on 1x B200.
NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4 with MTP one-model speculative decoding (max_draft_len: 3), guided_decoding_backend: xgrammar as in the model's deployment recipe, CUDA graphs on, chunked prefill.
What happens
In every eager (non-CUDA-graph) step, meaning every prefill and mixed prefill/decode step, CapturableGuidedDecoder enqueues its grammar host functions and then waits on the GPU in _drain_host_functions. It does this after the target logits and after each draft step, so 4 times per step with 3 draft tokens. It happens even when no request in the batch has guided_decoding_params.
Each wait empties the GPU queue, and the GPU then idles while the host launches the next kernels. For a batch with no guided requests, every one of these calls is a no-op: _build sets token_mask only for guided rows, so the bitmask kernel leaves the logits unchanged, and the host functions only touch guided requests.
Measured (160 concurrent users, 8K in / 1K out, AIPerf with unique prompts, no guided requests)
The GPU idles about 5% of each 32K-token prefill step (about 19 of 383 ms) and a similar amount in mixed steps.
py-spy shows the executor thread waiting in _drain_host_functions during those gaps.
Workaround we run
Skip the guided-decoding calls of an eager step when no request in the batch is guided and the previous step's guided calls also ran eagerly. The second condition means no host function from an earlier CUDA-graph step can still be pending, so the deadlock _drain_host_functions guards against can't happen. The first eager step after graph replays keeps the normal path, and so does every batch with a guided request.
Structured output unchanged: 32 json_schema requests mixed with 64 unguided ones, thinking off and on, gave 32/32 valid both ways and zero grammar failures (stock: 31/32 plus one cut off at the token limit, and 32/32).
A version of this patch rebased onto current main is on a branch: jvpflum/TensorRT-LLM@main...perf/guided-skip-unguided-eager (53 lines in guided_decoder.py). We measured it on 1.4.0rc1 and have not run it on main yet. Happy to open it as a PR.
Suggested fix
Check once per batch whether any request is guided, and skip the host functions, bitmask copies and drains in eager steps when none is. Alternatively, drain only in steps that actually enqueued host work.
General perf<NV>Broad performance issues not specific to a particular componentSpeculative Decoding<NV>MTP/Eagle/Medusa/Lookahead/Prompt-Lookup-Decoding/Draft-Target-Model/ReDrafter
Activity
[NVIDIA#21460][test] Guided-decoding skip: check the first eager step…