Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion vllm/distributed/elastic_ep/elastic_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,12 @@ def warm_and_capture(self) -> None:
self._suppress_eplb(),
serving_state,
):
runner._dummy_run(runner.max_num_tokens, is_profile=True, skip_eplb=True)
runner._dummy_run(
runner.max_num_tokens,
is_profile=True,
skip_eplb=True,
randomize_inputs=self.worker.randomize_dummy_inputs,
)
self.worker.compile_or_warm_up_model()

lock_workspace()
13 changes: 11 additions & 2 deletions vllm/v1/worker/gpu/model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ def _dummy_run(
skip_eplb: bool = False,
is_profile: bool = False,
valid_dummy_state_slots: bool = False,
randomize_inputs: bool = False,
**kwargs,
) -> tuple[torch.Tensor | None, torch.Tensor | None]:
if skip_attn and not is_profile:
Expand Down Expand Up @@ -878,6 +879,7 @@ def _dummy_run(
is_profile=is_profile,
context_len=context_len,
valid_dummy_state_slots=valid_dummy_state_slots,
randomize_inputs=randomize_inputs,
)
self.kv_connector.set_disabled(False)

Expand Down Expand Up @@ -968,7 +970,7 @@ def _dummy_pooler_run(self, hidden_states: torch.Tensor) -> None:
self.pooling_runner.dummy_pooler_run(hidden_states)

@torch.inference_mode()
def profile_run(self) -> None:
def profile_run(self, randomize_inputs: bool = False) -> None:
if self.supports_mm_inputs and self.is_first_pp_rank:
mm_config = self.model_config.multimodal_config
if mm_config is not None and not mm_config.skip_mm_profiling:
Expand All @@ -981,7 +983,10 @@ def profile_run(self) -> None:
)

hidden_states, sample_hidden_states = self._dummy_run(
self.max_num_tokens, skip_attn=True, is_profile=True
self.max_num_tokens,
skip_attn=True,
is_profile=True,
randomize_inputs=randomize_inputs,
)

# Only run sampler/pooler on last PP rank (non-last ranks return None).
Expand Down Expand Up @@ -1690,6 +1695,7 @@ def execute_model(
is_profile: bool = False,
context_len: int = 0,
valid_dummy_state_slots: bool = False,
randomize_inputs: bool = False,
) -> ModelRunnerOutput | IntermediateTensors | None:
if not dummy_run:
# Update the request states.
Expand Down Expand Up @@ -1808,6 +1814,9 @@ def execute_model(
# so MoE memory is measured and MoE kernels are exercised.
is_padding=not is_profile,
)
if randomize_inputs:
# All-zero input_ids route every token to the same experts.
input_batch.input_ids.random_(0, self.vocab_size)
if self.pcp_manager is not None:
input_batch = self.pcp_manager.prepare_inputs_to_capture(input_batch)
if skip_attn_for_dummy_run:
Expand Down
7 changes: 5 additions & 2 deletions vllm/v1/worker/gpu_model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5735,6 +5735,9 @@ def maybe_randomize_inputs(
- during profile_run
- during DP rank dummy run
"""
# The worker also resolves this flag and passes randomize_inputs, but
# V1 has internal dummy runs (e.g. CUDA graph capture) that don't go
# through the worker, so keep the check here too.
dp_size = self.vllm_config.parallel_config.data_parallel_size
randomize_inputs = randomize_inputs or (
envs.VLLM_RANDOMIZE_DP_DUMMY_INPUTS and dp_size > 1
Expand Down Expand Up @@ -6420,7 +6423,7 @@ def _dummy_pooler_run(
max_task = max(output_size.items(), key=lambda x: x[1])[0]
return self._dummy_pooler_run_task(hidden_states, max_task)

def profile_run(self) -> None:
def profile_run(self, randomize_inputs: bool = False) -> None:
# Profile with multimodal encoder & encoder cache.
if self.supports_mm_inputs:
mm_config = self.model_config.multimodal_config
Expand Down Expand Up @@ -6481,7 +6484,7 @@ def profile_run(self) -> None:

# Add `is_profile` here to pre-allocate communication buffers
hidden_states, last_hidden_states = self._dummy_run(
self.max_num_tokens, is_profile=True
self.max_num_tokens, is_profile=True, randomize_inputs=randomize_inputs
)
if get_pp_group().is_last_rank:
if self.is_pooling_model:
Expand Down
25 changes: 21 additions & 4 deletions vllm/v1/worker/gpu_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ def determine_available_memory(self) -> int:
if kv_cache_memory_bytes := self.cache_config.kv_cache_memory_bytes:
# still need a profile run which compiles the model for
# max_num_batched_tokens
self.model_runner.profile_run()
self.model_runner.profile_run(randomize_inputs=self.randomize_dummy_inputs)

msg = (
f"Initial free memory {format_gib(self.init_snapshot.free_memory)} "
Expand Down Expand Up @@ -650,7 +650,7 @@ def determine_available_memory(self) -> int:
# memory_profiling measures, restoring the original limit.
self._scoped_allocator_max_split(max_split_size_mb=20),
):
self.model_runner.profile_run()
self.model_runner.profile_run(randomize_inputs=self.randomize_dummy_inputs)

# Profile CUDA graph memory if graphs will be captured.
# ROCm is included: #44825 moved the profiler to
Expand Down Expand Up @@ -885,7 +885,12 @@ def compile_or_warm_up_model(self) -> CompilationTimes:
# We skip EPLB here since we don't want to record dummy metrics
for size in sorted(warmup_sizes, reverse=True):
logger.info("Compile and warming up model for size %d", size)
self.model_runner._dummy_run(size, skip_eplb=True, remove_lora=False)
self.model_runner._dummy_run(
size,
skip_eplb=True,
remove_lora=False,
randomize_inputs=self.randomize_dummy_inputs,
)
self.model_runner.maybe_remove_all_loras(self.model_runner.lora_config)

# Warmup and tune the kernels used during model execution before
Expand Down Expand Up @@ -1387,9 +1392,21 @@ def profile(self, is_start: bool = True, profile_prefix: str | None = None):
# Recreate it so the next profile_prefix is honored.
self.profiler = None

@property
def randomize_dummy_inputs(self) -> bool:
# Not cached: elastic EP rewrites parallel_config in place on reconfigure.
return (
envs.VLLM_RANDOMIZE_DP_DUMMY_INPUTS
and self.parallel_config.data_parallel_size > 1
)
Comment on lines +1397 to +1401

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be fine to cache this though - it's probably fine to always randomize if we started with DP > 1 since DP=1 would likely only be a transient state?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only for the profile run? I think we may want to randomize for CUDA graph capture even for DP=1 so we don't get weird autotuning/algorithm selection due to expert imbalance. @benchislett brought this up recently

@njhill njhill Sep 30, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then would it be better for this to be envs.VLLM_RANDOMIZE_DP_DUMMY_INPUTS and self.model_config.is_moe?

Or should we just have VLLM_RANDOMIZE_DP_DUMMY_INPUTS default to true in MoE case?


def execute_dummy_batch(self) -> None:
num_tokens = getattr(self.model_runner, "uniform_decode_query_len", 1)
self.model_runner._dummy_run(num_tokens, uniform_decode=True)
self.model_runner._dummy_run(
num_tokens,
uniform_decode=True,
randomize_inputs=self.randomize_dummy_inputs,
)

def add_lora(self, lora_request: LoRARequest) -> bool:
return self.model_runner.add_lora(lora_request)
Expand Down
Loading