[Bug]: Seeded sampling restarts its random stream when a request resumes from a generated prefix

Aperta
#23,190 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@devanshi-code18 ci sta già lavorando.

Dal 2/12/2026.

  • #23191 di @devanshi-code18 — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python, pytorch

Direzione di ricerca

Start with _SeedManager.observe in tensorrt_llm/_torch/pyexecutor/sampler/seed_manager.py, then read the sampler’s seeded offset handling and its unit tests. Reproduce the resumed request using the issue’s repro.py scenario and compare token streams at matching positions. Done means resumed seeded draws use the intended sequence positions and the relevant tests cover the behavior; an open linked pull request is already addressing this issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Customized kernels
System Info

TensorRT-LLM 1.4.0rc5 (pip wheel), PyTorch backend, LLM API, 1x H100 80GB HBM3, torch 2.14.0+cu130. tensorrt_llm/_torch/pyexecutor/sampler/ is identical on main at 06b1cbcd.

Who can help?

Code: _SeedManager.observe in tensorrt_llm/_torch/pyexecutor/sampler/seed_manager.py.

Information
  • The official example scripts
  • My own modified scripts
Tasks
  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)
Reproduction

Resume a seeded request after k = 8 tokens by sending its prompt plus those tokens as a new prompt with the same seed, as request migration (Dynamo) and RL partial rollouts do:

repro.py (TinyLlama-1.1B-Chat, temperature 1, seed 1234)
from tensorrt_llm import LLM, SamplingParams
from tensorrt_llm.llmapi import KvCacheConfig


def main():
    llm = LLM("TinyLlama/TinyLlama-1.1B-Chat-v1.0",
              kv_cache_config=KvCacheConfig(enable_block_reuse=False))
    prompt = llm.tokenizer.encode("Write a short story about a lighthouse keeper.")

    def generate(token_ids, n):
        sp = SamplingParams(max_tokens=n, temperature=1.0, seed=1234, ignore_eos=True)
        return list(llm.generate([token_ids], sp)[0].outputs[0].token_ids)

    k = 8
    full = generate(prompt, 16)  # one uninterrupted request
    resumed = generate(prompt + full[:k], 16 - k)  # same seed, resumed after k tokens
    print("uninterrupted[k:]", full[k:])
    print("resumed          ", resumed)
    llm.shutdown()


if __name__ == "__main__":
    main()
uninterrupted[k:] [29958, 13, 8439, 892, 263, 2846, 1180, 1338]
resumed           [29958, 13, 2887, 263, 301, 18919, 1709, 1589]
Expected behavior

The resumed request draws the same random number at each position as the uninterrupted one, so its tokens match wherever the logits match. vLLM (model runner v2) and SGLang (multinomial_with_seed) key each seeded draw to (seed, token position).

actual behavior

Over 64 prompts resumed after 1, 8 and 32 tokens (TinyLlama, temperature 1), the first resumed token matched in 123/192 runs and the whole continuation in 0/192.

_SeedManager.observe sets a seeded request's Philox offset to 0 when it takes its slot, so the resumed request draws its first token with offset 0 instead of k.

additional notes
  • Proposed fix: start the offset at the request's token count (prompt included), so each token's offset is its sequence position. The first resumed token then matches in 179/192 runs.
  • Replaying the sampler offline on the engine's logits reproduces both tokens with offset prompt_len + k in every run, so the 13 left come from prefill vs decode logit differences.
  • The fix renumbers seeded streams: ordinary seeded requests, and n > 1 requests without a seed (C++ seeds them 0..n-1), sample different tokens from the same distribution.
  • Greedy and n = 1 unseeded outputs do not change. I have the change with unit tests and will open a PR that references this issue.
Lingua principale
Python
Stelle
15.2k
Fork
3k
Merge medio
2g 21h
PR unite (30g)
477

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NVIDIA/TensorRT-LLM

Tutte le issue di NVIDIA/TensorRT-LLM

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.