Skip to navigation

How to get repeatable results using seed

View as Markdown

The seed parameter enables best-effort repeatability for the same prompt and settings. It does not guarantee identical output.

Use it to reduce variation during testing and debugging, while allowing for outputs to change between requests or model updates.

What it does:

  • The same seed and request parameters can reduce output variation.
  • Identical requests can still produce different outputs.
  • Model or serving updates can change results produced by a previously used seed.
  • This feature is currently in Beta.

In recent testing, setting seed did not measurably reduce output variation compared to omitting it, repeated requests with the same seed varied as much as requests with no seed at all. Treat seed as best-effort only, and do not rely on it for reproducibility until this is confirmed fixed.


Format and Range:

PropertyValue TypeRange
seedInteger>= -9223372036854776000 to <= 9223372036854776000

šŸ‘‰ Typically, values like 42, 1234, or any stable number will work fine.

When to use seed:

Use CaseWhy use it?
Regression testingReduce unrelated variation between runs
Demo apps or tutorialsMake outputs more predictable
A/B testing with fixed inputsLimit sampling variation during comparison
QA pipelinesCompare behavior without assuming exact text

First, install the SDK:

pip install -Uqq sarvamai

Then use the following Python code:

from sarvamai import SarvamAI
# Initialize the SarvamAI client with your API key
client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
# Example: Using `seed` to repeat responses
response = client.chat.completions(
model="sarvam-105b",
messages=[
{"role": "system", "content": "You are a poetry assistant."},
{"role": "user", "content": "Write a short poem about the moon."}
],
seed=12345 # Best-effort repeatability; identical output is not guaranteed
)
# Receive assistant's reply as output
print(response.choices[0].message.content)