reproducibility.md 2.09 KB
Newer Older
1
# Reproducibility
2

3
4
vLLM does not guarantee the reproducibility of the results by default, for the sake of performance. To achieve
reproducible results, you need to turn off multiprocessing to make the scheduling deterministic by setting `VLLM_ENABLE_V1_MULTIPROCESSING=0`.
5

6
Example: [examples/offline_inference/reproducibility.py](../../examples/offline_inference/reproducibility.py)
7

8
!!! warning
9

10
    Applying the above settings [changes the random state in user code](#locality-of-random-state).
11

12
!!! note
13

14
15
16
17
18
    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.
19

20
## Setting the global seed
21

22
The `seed` parameter in vLLM is used to control the random states for various random number generators.
23

24
If a specific seed value is provided, the random states for `random`, `np.random`, and `torch.manual_seed` will be set accordingly.
25

26
However, in some cases, setting the seed will also [change the random state in user code](#locality-of-random-state).
27

28
### Default Behavior
29

30
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`.
31

32
!!! note
33

34
35
36
    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.
    
37
    For more information, see: <https://github.com/vllm-project/vllm/pull/17929>
38

39
### Locality of random state
40

41
The random state in user code (i.e. the code that constructs [LLM][vllm.LLM] class) is updated by vLLM under the following conditions:
42

43
44
45
46
47
- 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.