Skip to content

[Performance] Guided decoding with one-model speculative decoding drains the GPU 4 times per eager step, even when no request is guided #21460

Closed

Description

@jvpflum

System info

  • 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.

  • B300, 160 users: output throughput +2.9% burst, +3.4% sustained.
  • B200, 128 users: +1.6% burst, +5.7% sustained.
  • 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.

Activity

  1. added
    Speculative Decoding
    General perf
    on Nov 2, 2026
  2. added a commit that references this issue on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    General perfSpeculative Decoding

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions