Skip to content

Consistent Output with Same Prompts #2411

Closed

Description

@ZhenboYan

Description
I ran the provided example script examples/llm-api/quickstart_example.py and observed that the output is consistent across multiple runs.

Steps to Reproduce

  1. Run the quickstart_example.py script multiple times with default settings inside the TensorRT container nvcr.io/nvidia/tensorrt:24.10-py3 container.
  2. Modify top_p and temperature values.
  3. Run the script again multiple times.

Observed Behavior

  • With the default settings, the output remains the same for each run.
  • After changing top_p and temperature, a different output (let's call it "result B") is generated.
  • Subsequent runs with the modified settings consistently produce "result B."

Expected Behavior
I'd like to understand how to generate non-deterministic results with fixed temperature and top_p settings.

Question
How can I configure the model or script to produce non-deterministic outputs with fixed temperature and top_p?

Activity

  1. added
    question
    triaged
    on Nov 6, 2024
  2. syuoni commented on Nov 7, 2024

    @syuoni
    Collaborator

    Hi @ZhenboYan ,

    If the random seed is not provided to SamplingParams, TRT-LLM will generate a default and fixed random seed for sampling. That's why you observed the generation outputs unchanged across different runs. So, we need to provide different random seeds to get different sampling outputs. Thanks!

  3. assigned and unassigned on Nov 7, 2024
  4. MadDanWithABox commented on Feb 17, 2025

    @MadDanWithABox

    @syuoni For future reference, what is the range of this seed? I want to be able to have the maximum amount of random as possible

  5. syuoni commented on Feb 17, 2025

    @syuoni
    Collaborator

    Hi @MadDanWithABox ,

    Please checkout this doc. The range is [0, 2^64-1].

    While, we do receive this same question in multiple places. We tend to change the current behavior, namely using a unfixed default random seed. I will update this issue when we finish this changing.

  6. syuoni commented on Mar 15, 2025

    @syuoni
    Collaborator

    Hi all,

    The default behavior has been aligned to vLLM's. More specifically, for SamplingParams with TopP/TopK (and proper temperature) but no random seed provided, the runtime will generate a random one. So, it will result in different responses. There is a test to protect this behavior.

    I'm closing this issue. Feel free to reopen or open another one if you encounter the same issue.

    Thanks for reporting the issue!

  7. bindrad commented on Jun 10, 2025

    @bindrad

    I'm running a docker container of tensorrt and when I try to pass a random seed, it returns {"object":"error","message":"[{'type': 'extra_forbidden', 'loc': ('body', 'random_seed'), 'msg': 'Extra inputs are not permitted', 'input': 8}]","type":"BadRequestError","param":null,"code":400}. Any idea what I'm doing wrong?

  8. fstandhartinger commented on Jul 27, 2025

    @fstandhartinger

    dear @syuoni and @Superjomn - we are trying to use Tensor-LLM for inference for the new Kimi-K2 model. Its crazy fast, but fails to generate different outputs, even though we are using absurd high top_k, temperature and explicitly set seed to different values each run.

    weirdly enough the 2nd generation is different but then all follow up generations stay the same. reproducibly.

    any idea what we could try? re-rolls with different gens are a must-have feature for us.

    thx for your assistance, keep up the good work!

    Image
  9. josephrocca commented on Sep 8, 2025

    @josephrocca

    I'm was observing the same behavior in v0.21.0, and realized (after many hours...) that you need to add enable_trtllm_sampler: true to your --extra_llm_api_options yaml file to enable temperature and other sampling option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

questiontriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions