2025-05-24 22:25:33 +08:00
# Reproducibility
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
vLLM does not guarantee the reproducibility of the results by default, for the sake of performance. You need to do the following to achieve
reproducible results:
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
- For V1: Turn off multiprocessing to make the scheduling deterministic by setting `VLLM_ENABLE_V1_MULTIPROCESSING=0` .
- For V0: Set the global seed (see below).
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
Example: <gh-file:examples/offline_inference/reproducibility.py>
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
!!! warning
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
Applying the above settings [changes the random state in user code ](#locality-of-random-state ).
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
!!! note
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
Even with the above settings, vLLM only provides reproducibility
when it runs on the same hardware and the same vLLM version.
Also, the online serving API (`vllm serve` ) does not support reproducibility
because it is almost impossible to make the scheduling deterministic in the
online setting.
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
## Setting the global seed
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
The `seed` parameter in vLLM is used to control the random states for various random number generators.
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
If a specific seed value is provided, the random states for `random` , `np.random` , and `torch.manual_seed` will be set accordingly.
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
However, in some cases, setting the seed will also [change the random state in user code ](#locality-of-random-state ).
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
### Default Behavior
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
In V0, the `seed` parameter defaults to `None` . When the `seed` parameter is `None` , the random states for `random` , `np.random` , and `torch.manual_seed` are not set. This means that each run of vLLM will produce different results if `temperature > 0` , as expected.
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
In V1, the `seed` parameter defaults to `0` which sets the random state for each worker, so the results will remain consistent for each vLLM run even if `temperature > 0` .
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
!!! note
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
It is impossible to un-specify a seed for V1 because different workers need to sample the same outputs
for workflows such as speculative decoding.
For more information, see: <gh-pr:17929>
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
### Locality of random state
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
The random state in user code (i.e. the code that constructs [LLM][vllm.LLM] class) is updated by vLLM under the following conditions:
2025-02-10 20:56:50 +05:30
2025-05-27 15:03:13 +08:00
- For V0: The seed is specified.
- For V1: The workers are run in the same process as user code, i.e.: `VLLM_ENABLE_V1_MULTIPROCESSING=0` .
By default, these conditions are not active so you can use vLLM without having to worry about
accidentally making deterministic subsequent operations that rely on random state.