New Tool Radar

AI Concepts

How to Set a Sampling Seed So a Generation Can Be Reproduced for Debugging

Pass the same seed with the same model and parameters, record the seed with the output, and treat the result as a reproducibility aid, not a guarantee.

Schematic with three steps: Send the same seed with the same; Repeat the call and compare; Record the seed with the output.

When a generation goes wrong, you need to reproduce it to debug it, and sampling makes that hard: the same prompt can give a different answer every time. A seed is the fix the API offers: the Chat Completions API accepts a seed value, and the system makes a best effort to sample deterministically, so repeated requests with the same seed and parameters should return the same result. It is a best effort, not a guarantee, so record the seed and the full parameters alongside the output.

What you need

  • A model and API that accept a seed parameter
  • The exact prompt and parameters that produced the output
  • A place to record the seed with the output

Step 1: Send the same seed with the same parameters

Call the API with the same seed, the same model, the same prompt and the same sampling parameters. Changing any of them, including temperature or top-p, can change the output even with the same seed.

Step 2: Repeat the call and compare

Send the identical request again and compare the two outputs. If they match, the seed is working for this model and these parameters; if they differ, note that and do not rely on the seed alone.

Step 3: Record the seed with the output

Store the seed, the model name, the prompt and the parameters with every output you need to reproduce. A seed recorded nowhere is useless when the bug reappears next week.

Worked example: synthetic seed reproducibility check

The table below is a synthetic example. It shows the expected result of using a seed; no API was called.

Call Seed Output
First call 42 Answer A
Repeat, same seed 42 Answer A
Repeat, different seed 7 Answer B
Repeat, same seed, new temperature 42 Answer C

Expected result (UNTESTED). the same seed with the same parameters repeats the output, while a different seed or a changed temperature does not. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Determinism with a seed is a best effort, not a guarantee, and it can vary by model.
  • A seed only helps when everything else is identical: model, prompt, parameters and system prompt.
  • Some providers do not support a seed at all, so check the API reference for your provider.
  • A reproducible bad answer is still a bad answer: the seed helps you debug it, not fix it.

Sources

See all