@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / d7219bcda3
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 12, 18:30 UTC

[Misc] Move dynamic seed initialization to `EngineArgs` (#29165)

Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>

Cyrus Leung committed Nov 21, 2025 at 23:27 UTC d7219bcda3e6508cb14881bec303e2d0ab68c898
4 files changed +23 -37
vllm/config/model.py
+7 -27
@@ -146,9 +146,12 @@ class ModelConfig:
146 - "bfloat16" for a balance between precision and range.\n
147 - "float" is shorthand for FP32 precision.\n
148 - "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."""
155 hf_config: PretrainedConfig = field(init=False)
156 """The Hugging Face config of the model."""
157 hf_text_config: PretrainedConfig = field(init=False)
@@ -415,7 +418,7 @@ class ModelConfig:
418 def __post_init__(
419 self,
420 # 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,
422 enable_mm_embeds: bool | None,
423 media_io_kwargs: dict[str, dict[str, Any]] | None,
424 mm_processor_kwargs: dict[str, Any] | None,
@@ -428,23 +431,6 @@ class ModelConfig:
431 skip_mm_profiling: bool | None,
432 video_pruning_rate: float | None,
433 ) -> 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 -
434 # Keep set served_model_name before maybe_model_redirect(self.model)
435 self.served_model_name = get_served_model_name(
436 self.model, self.served_model_name
@@ -1151,12 +1137,6 @@ class ModelConfig:
1137 self,
1138 parallel_config: ParallelConfig,
1139 ) -> 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 -
1140 total_num_attention_heads = getattr(
1141 self.hf_text_config, "num_attention_heads", 0
1142 )
vllm/config/speculative.py
+1 -6
@@ -9,6 +9,7 @@ from pydantic import Field, SkipValidation, model_validator
9 from pydantic.dataclasses import dataclass
10 from typing_extensions import Self
11
12 +from vllm.config.model import ModelConfig
13 from vllm.config.parallel import ParallelConfig
14 from vllm.config.utils import config
15 from vllm.logger import init_logger
@@ -18,10 +19,8 @@ if TYPE_CHECKING:
19 from transformers import PretrainedConfig
20
21 import vllm.model_executor.layers.quantization as me_quant
21 - from vllm.config import ModelConfig
22 else:
23 PretrainedConfig = Any
24 - ModelConfig = Any
24
25 me_quant = LazyLoader(
26 "model_executor", globals(), "vllm.model_executor.layers.quantization"
@@ -316,10 +315,6 @@ class SpeculativeConfig:
315 self.prompt_lookup_min = 0
316
317 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 -
318 self.draft_model_config = ModelConfig(
319 model=self.model,
320 runner="draft",
vllm/engine/arg_utils.py
+15 -1
@@ -367,7 +367,7 @@ class EngineArgs:
367 config_format: str = ModelConfig.config_format
368 dtype: ModelDType = ModelConfig.dtype
369 kv_cache_dtype: CacheDType = CacheConfig.cache_dtype
370 - seed: int | None = ModelConfig.seed
370 + seed: int | None = None
371 max_model_len: int | None = ModelConfig.max_model_len
372 cuda_graph_sizes: list[int] | None = CompilationConfig.cudagraph_capture_sizes
373 cudagraph_capture_sizes: list[int] | None = (
@@ -1188,6 +1188,20 @@ class EngineArgs:
1188 if check_gguf_file(self.model):
1189 self.quantization = self.load_format = "gguf"
1190
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 +
1205 if self.disable_mm_preprocessor_cache:
1206 logger.warning(
1207 "`--disable-mm-preprocessor-cache` is deprecated "
vllm/v1/worker/tpu_worker.py
-3
@@ -106,9 +106,6 @@ class TPUWorker:
106 "Profiling enabled. Traces will be saved to: %s", self.profile_dir
107 )
108
109 - if self.model_config.seed is None:
110 - self.model_config.seed = 0
111 -
109 def initialize_cache(self, num_gpu_blocks: int, num_cpu_blocks: int) -> None:
110 self.cache_config.num_gpu_blocks = num_gpu_blocks
111 self.cache_config.num_cpu_blocks = num_cpu_blocks