Seeding¶
How experiment seeds reach each model back-end; see Models.
rupsycho.seeding
¶
Reproducible sampling: map an experiment seed onto each model back-end.
Every model call of an experiment carries a seed (parameters.seeds). How that seed
reaches the model differs per back-end, and silently ignoring it would defeat the purpose
of a seeded experiment:
- Local Hugging Face pipelines have no
seedargument. Their sampling is driven by global random number generators, so the seed is applied withtransformers.set_seedright before every call. - API / server back-ends with a
seedfield (OpenAI, DeepSeek, Ollama, ...) receive the seed through a copy of the model with that field set; chat models around a Hugging Face endpoint receive it as a request parameter. - Back-ends without any seed support (e.g. Google Gemini) cannot be seeded. A warning is emitted once per model type; repetitions are then independent samples.
Custom model types can be registered with :func:register_seeder.
Seeder
module-attribute
¶
A function (model, seed) -> seeded runnable.
register_seeder
¶
Register how models of model_type are seeded.
The most recent registration wins and takes precedence over the built-in strategies.
| PARAMETER | DESCRIPTION |
|---|---|
model_type
|
The model class (subclasses match too).
TYPE:
|
seeder
|
Function
TYPE:
|
is_thread_safe
¶
Whether calls to model may run concurrently in several threads.
Local pipelines rely on process-global state (random generators, accelerator memory) and are therefore not thread safe; API clients are.
supports_seeding
¶
Whether :func:seed_model can make model reproducible.
seed_model
¶
Return a runnable that samples from model reproducibly for seed.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The model (any LangChain runnable).
TYPE:
|
seed
|
The seed of the current experiment run.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Runnable
|
A runnable to use in place of |
Runnable
|
itself is returned and a warning is emitted (once per model type). |