Skip to content

Commit d7219bc

Browse files
[Misc] Move dynamic seed initialization to EngineArgs (#29165)
Signed-off-by: DarkLight1337 <[email protected]>
1 parent 4050bae commit d7219bc

File tree

4 files changed

+23
-37
lines changed

4 files changed

+23
-37
lines changed

vllm/config/model.py

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,12 @@ class ModelConfig:
146146
- "bfloat16" for a balance between precision and range.\n
147147
- "float" is shorthand for FP32 precision.\n
148148
- "float32" for FP32 precision."""
149-
seed: int | None = None
150-
"""Random seed for reproducibility. Initialized to None in V0, but
151-
initialized to 0 in V1."""
149+
seed: int = 0
150+
"""Random seed for reproducibility.
151+
152+
We must set the global seed because otherwise,
153+
different tensor parallel workers would sample different tokens,
154+
leading to inconsistent results."""
152155
hf_config: PretrainedConfig = field(init=False)
153156
"""The Hugging Face config of the model."""
154157
hf_text_config: PretrainedConfig = field(init=False)
@@ -415,7 +418,7 @@ def _apply_dict_overrides(
415418
def __post_init__(
416419
self,
417420
# Multimodal config init vars
418-
limit_mm_per_prompt: dict[str, int] | None,
421+
limit_mm_per_prompt: dict[str, int | dict[str, int]] | None,
419422
enable_mm_embeds: bool | None,
420423
media_io_kwargs: dict[str, dict[str, Any]] | None,
421424
mm_processor_kwargs: dict[str, Any] | None,
@@ -428,23 +431,6 @@ def __post_init__(
428431
skip_mm_profiling: bool | None,
429432
video_pruning_rate: float | None,
430433
) -> None:
431-
# Set the default seed to 0 in V1.
432-
# NOTE(woosuk): In V1, we use separate processes for workers (unless
433-
# VLLM_ENABLE_V1_MULTIPROCESSING=0), so setting a seed here
434-
# doesn't affect the user process. However, without a consistent seed,
435-
# different tensor parallel workers would sample different tokens,
436-
# leading to inconsistent results.
437-
if self.seed is None:
438-
self.seed = 0
439-
if not envs.VLLM_ENABLE_V1_MULTIPROCESSING:
440-
logger.warning(
441-
"The global random seed is set to %d. Since "
442-
"VLLM_ENABLE_V1_MULTIPROCESSING is set to False, this may "
443-
"affect the random state of the Python process that "
444-
"launched vLLM.",
445-
self.seed,
446-
)
447-
448434
# Keep set served_model_name before maybe_model_redirect(self.model)
449435
self.served_model_name = get_served_model_name(
450436
self.model, self.served_model_name
@@ -1151,12 +1137,6 @@ def verify_with_parallel_config(
11511137
self,
11521138
parallel_config: ParallelConfig,
11531139
) -> None:
1154-
if parallel_config.distributed_executor_backend == "external_launcher":
1155-
assert self.seed is not None, (
1156-
"Seed must be set when using external launcher backend to "
1157-
"make sure sampling results are the same across workers."
1158-
)
1159-
11601140
total_num_attention_heads = getattr(
11611141
self.hf_text_config, "num_attention_heads", 0
11621142
)

vllm/config/speculative.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pydantic.dataclasses import dataclass
1010
from typing_extensions import Self
1111

12+
from vllm.config.model import ModelConfig
1213
from vllm.config.parallel import ParallelConfig
1314
from vllm.config.utils import config
1415
from vllm.logger import init_logger
@@ -18,10 +19,8 @@
1819
from transformers import PretrainedConfig
1920

2021
import vllm.model_executor.layers.quantization as me_quant
21-
from vllm.config import ModelConfig
2222
else:
2323
PretrainedConfig = Any
24-
ModelConfig = Any
2524

2625
me_quant = LazyLoader(
2726
"model_executor", globals(), "vllm.model_executor.layers.quantization"
@@ -316,10 +315,6 @@ def __post_init__(self):
316315
self.prompt_lookup_min = 0
317316

318317
if self.model is not None:
319-
# TODO: Move this import to the top once `ModelConfig`
320-
# lives in `vllm.config.model`.
321-
from vllm.config import ModelConfig
322-
323318
self.draft_model_config = ModelConfig(
324319
model=self.model,
325320
runner="draft",

vllm/engine/arg_utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ class EngineArgs:
367367
config_format: str = ModelConfig.config_format
368368
dtype: ModelDType = ModelConfig.dtype
369369
kv_cache_dtype: CacheDType = CacheConfig.cache_dtype
370-
seed: int | None = ModelConfig.seed
370+
seed: int | None = None
371371
max_model_len: int | None = ModelConfig.max_model_len
372372
cuda_graph_sizes: list[int] | None = CompilationConfig.cudagraph_capture_sizes
373373
cudagraph_capture_sizes: list[int] | None = (
@@ -1188,6 +1188,20 @@ def create_model_config(self) -> ModelConfig:
11881188
if check_gguf_file(self.model):
11891189
self.quantization = self.load_format = "gguf"
11901190

1191+
# NOTE(woosuk): In V1, we use separate processes for workers (unless
1192+
# VLLM_ENABLE_V1_MULTIPROCESSING=0), so setting a seed here
1193+
# doesn't affect the user process.
1194+
if self.seed is None:
1195+
self.seed = 0
1196+
if not envs.VLLM_ENABLE_V1_MULTIPROCESSING:
1197+
logger.warning(
1198+
"The global random seed is set to %d. Since "
1199+
"VLLM_ENABLE_V1_MULTIPROCESSING is set to False, this may "
1200+
"affect the random state of the Python process that "
1201+
"launched vLLM.",
1202+
self.seed,
1203+
)
1204+
11911205
if self.disable_mm_preprocessor_cache:
11921206
logger.warning(
11931207
"`--disable-mm-preprocessor-cache` is deprecated "

vllm/v1/worker/tpu_worker.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ def __init__(
106106
"Profiling enabled. Traces will be saved to: %s", self.profile_dir
107107
)
108108

109-
if self.model_config.seed is None:
110-
self.model_config.seed = 0
111-
112109
def initialize_cache(self, num_gpu_blocks: int, num_cpu_blocks: int) -> None:
113110
self.cache_config.num_gpu_blocks = num_gpu_blocks
114111
self.cache_config.num_cpu_blocks = num_cpu_blocks

0 commit comments

Comments
 (0)