[EPLB] Mask padding in EPLB load recording (#38128)
Signed-off-by: ilmarkov <markovilya197@gmail.com> Signed-off-by: Markov Ilya <markovilya19@gmail.com> Co-authored-by: Markov Ilya <markovilya19@gmail.com>
This commit is contained in:
co-authored by
Markov Ilya
parent
311ad689ad
commit
a2abce646f
@@ -9,6 +9,7 @@ import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from vllm.config import CUDAGraphMode, VllmConfig, get_layers_from_vllm_config
|
||||
from vllm.distributed.eplb.eplb_state import EplbState
|
||||
from vllm.forward_context import set_forward_context
|
||||
from vllm.model_executor.layers.attention_layer_base import AttentionLayerBase
|
||||
from vllm.model_executor.model_loader import get_model
|
||||
@@ -43,6 +44,8 @@ class ExtractHiddenStatesProposer:
|
||||
self.dtype = vllm_config.model_config.dtype
|
||||
self.dp_rank = vllm_config.parallel_config.data_parallel_rank
|
||||
|
||||
self.eplb_state: EplbState | None = None
|
||||
|
||||
# Model and attention layer tracking (initialized in load_model)
|
||||
self.model: nn.Module | None = None
|
||||
self.attn_layer_names: list[str] = []
|
||||
@@ -83,6 +86,10 @@ class ExtractHiddenStatesProposer:
|
||||
self.max_num_tokens, dtype=torch.int64, device=device
|
||||
)
|
||||
|
||||
def set_eplb_state(self, eplb_state: EplbState) -> None:
|
||||
"""Inject EPLB state after construction."""
|
||||
self.eplb_state = eplb_state
|
||||
|
||||
def propose(
|
||||
self,
|
||||
num_speculative_tokens: int,
|
||||
@@ -145,6 +152,12 @@ class ExtractHiddenStatesProposer:
|
||||
if num_tokens_across_dp is not None:
|
||||
num_tokens_across_dp[self.dp_rank] = num_input_tokens
|
||||
|
||||
if self.eplb_state is not None:
|
||||
assert self.vllm_config.speculative_config is not None
|
||||
self.eplb_state.prepare_forward(
|
||||
self.vllm_config.speculative_config.draft_model_config,
|
||||
num_tokens,
|
||||
)
|
||||
with set_forward_context(
|
||||
per_layer_attn_metadata,
|
||||
self.vllm_config,
|
||||
|
||||
@@ -15,6 +15,7 @@ from vllm.config import (
|
||||
get_layers_from_vllm_config,
|
||||
replace,
|
||||
)
|
||||
from vllm.distributed.eplb.eplb_state import EplbState
|
||||
from vllm.distributed.parallel_state import get_pp_group
|
||||
from vllm.forward_context import set_forward_context
|
||||
from vllm.logger import init_logger
|
||||
@@ -79,6 +80,7 @@ class SpecDecodeBaseProposer:
|
||||
self.dtype = vllm_config.model_config.dtype
|
||||
self.max_model_len = vllm_config.model_config.max_model_len
|
||||
self.dp_rank = vllm_config.parallel_config.data_parallel_rank
|
||||
self.eplb_state: EplbState | None = None
|
||||
self.num_speculative_tokens = self.speculative_config.num_speculative_tokens
|
||||
|
||||
# We need to get the hidden size from the draft model config because
|
||||
@@ -328,6 +330,10 @@ class SpecDecodeBaseProposer:
|
||||
"does not support M-RoPE yet"
|
||||
)
|
||||
|
||||
def set_eplb_state(self, eplb_state: EplbState) -> None:
|
||||
"""Inject EPLB state after construction."""
|
||||
self.eplb_state = eplb_state
|
||||
|
||||
def _init_parallel_drafting_params(self):
|
||||
# For parallel drafting, we need the token ID to use for masked slots
|
||||
# And for EAGLE + parallel drafting, we need the hidden state tensor to use
|
||||
@@ -527,6 +533,12 @@ class SpecDecodeBaseProposer:
|
||||
if self._share_mtp_indices and hasattr(self.model.model, "set_skip_topk"):
|
||||
self.model.model.set_skip_topk(False)
|
||||
|
||||
if self.eplb_state is not None:
|
||||
self.eplb_state.prepare_forward(
|
||||
self.draft_model_config,
|
||||
num_tokens,
|
||||
)
|
||||
|
||||
with set_forward_context(
|
||||
per_layer_attn_metadata,
|
||||
self.vllm_config,
|
||||
@@ -672,6 +684,12 @@ class SpecDecodeBaseProposer:
|
||||
if self.pass_hidden_states_to_model:
|
||||
model_kwargs["hidden_states"] = self.hidden_states[:input_batch_size]
|
||||
|
||||
if self.eplb_state is not None:
|
||||
self.eplb_state.prepare_forward(
|
||||
self.draft_model_config,
|
||||
batch_size,
|
||||
)
|
||||
|
||||
with set_forward_context(
|
||||
per_layer_attn_metadata,
|
||||
self.vllm_config,
|
||||
|
||||
@@ -8,6 +8,7 @@ from typing import Any
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from vllm.config import ModelConfig
|
||||
from vllm.distributed.eplb.eplb_state import EplbState
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.models.interfaces import (
|
||||
@@ -90,6 +91,7 @@ class EPLBController:
|
||||
draft_model,
|
||||
speculative_config.draft_model_config,
|
||||
)
|
||||
speculator.set_eplb_state(self.state)
|
||||
self._has_registered_models = True
|
||||
return True
|
||||
|
||||
@@ -135,6 +137,16 @@ class EPLBController:
|
||||
log_stats=self.parallel_config.eplb_config.log_balancedness,
|
||||
)
|
||||
|
||||
def prepare_forward(
|
||||
self,
|
||||
model_config: ModelConfig,
|
||||
num_unpadded_tokens: int,
|
||||
ubatch_slices: list | None = None,
|
||||
) -> None:
|
||||
if self.state is None or not self.parallel_config.enable_eplb:
|
||||
return
|
||||
self.state.prepare_forward(model_config, num_unpadded_tokens, ubatch_slices)
|
||||
|
||||
def setup_from_mapping(
|
||||
self,
|
||||
model: nn.Module,
|
||||
|
||||
@@ -1284,6 +1284,9 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
model_inputs["intermediate_tensors"] = IntermediateTensors(new_tensors)
|
||||
del intermediate_tensors
|
||||
|
||||
# Update the EPLB meta.
|
||||
self.eplb.prepare_forward(self.model_config, input_batch.num_tokens)
|
||||
|
||||
# Run model.
|
||||
if batch_desc.cg_mode == CUDAGraphMode.FULL:
|
||||
# Use explicit cudagraph replay for FULL mode.
|
||||
|
||||
@@ -213,6 +213,8 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
need_eager=is_profile,
|
||||
)
|
||||
|
||||
self._prepare_eplb_forward(input_batch.num_tokens)
|
||||
|
||||
if prefill_batch_desc.cg_mode == CUDAGraphMode.FULL:
|
||||
# Replay the full graph for draft prefill.
|
||||
assert self.prefill_cudagraph_manager is not None
|
||||
@@ -424,6 +426,8 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
num_tokens_across_dp: torch.Tensor | None,
|
||||
cudagraph_runtime_mode: CUDAGraphMode = CUDAGraphMode.NONE,
|
||||
) -> None:
|
||||
self._prepare_eplb_forward(num_reqs)
|
||||
|
||||
idx_mapping = self.idx_mapping[:num_reqs]
|
||||
positions = self.input_buffers.positions[:num_reqs]
|
||||
# Run the draft model forward pass.
|
||||
|
||||
@@ -278,6 +278,9 @@ class DFlashSpeculator(DraftModelSpeculator):
|
||||
self.hidden_states[:num_target_tokens],
|
||||
self.context_positions[:num_target_tokens],
|
||||
)
|
||||
# DFlash processes all speculative tokens in one forward pass,
|
||||
# so the real token count is num_query_tokens.
|
||||
self._prepare_eplb_forward(num_query_tokens)
|
||||
self._generate_draft(
|
||||
num_reqs,
|
||||
num_query_tokens,
|
||||
@@ -354,6 +357,10 @@ class DFlashSpeculator(DraftModelSpeculator):
|
||||
self.kv_cache_config,
|
||||
)
|
||||
|
||||
# DFlash processes all speculative tokens in one forward pass,
|
||||
# so the real token count is num_query_tokens.
|
||||
self._prepare_eplb_forward(num_query_tokens)
|
||||
|
||||
if batch_desc.cg_mode == CUDAGraphMode.FULL:
|
||||
assert self.query_cudagraph_manager is not None
|
||||
self.query_cudagraph_manager.run_fullgraph(batch_desc)
|
||||
|
||||
@@ -8,6 +8,7 @@ import torch.nn as nn
|
||||
|
||||
from vllm.config import VllmConfig, get_layers_from_vllm_config
|
||||
from vllm.config.compilation import CUDAGraphMode
|
||||
from vllm.distributed.eplb.eplb_state import EplbState
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.layers.attention_layer_base import AttentionLayerBase
|
||||
from vllm.v1.kv_cache_interface import KVCacheConfig
|
||||
@@ -106,6 +107,8 @@ class DraftModelSpeculator(BaseSpeculator):
|
||||
self.dp_size = vllm_config.parallel_config.data_parallel_size
|
||||
self.dp_rank = vllm_config.parallel_config.data_parallel_rank
|
||||
|
||||
self.eplb_state: EplbState | None = None
|
||||
|
||||
self.input_buffers = InputBuffers(
|
||||
max_num_reqs=self.max_num_reqs,
|
||||
max_num_tokens=self.max_num_tokens,
|
||||
@@ -165,6 +168,18 @@ class DraftModelSpeculator(BaseSpeculator):
|
||||
)
|
||||
self.draft_attn_layer_names = all_attn_layers - target_attn_layer_names
|
||||
|
||||
def set_eplb_state(self, eplb_state: EplbState) -> None:
|
||||
"""Inject EPLB state after construction."""
|
||||
self.eplb_state = eplb_state
|
||||
|
||||
def _prepare_eplb_forward(self, num_unpadded_tokens: int) -> None:
|
||||
"""Call EPLB prepare_forward if EPLB is active for the draft model."""
|
||||
if self.eplb_state is not None:
|
||||
self.eplb_state.prepare_forward(
|
||||
self.speculative_config.draft_model_config,
|
||||
num_unpadded_tokens,
|
||||
)
|
||||
|
||||
def set_attn(
|
||||
self,
|
||||
model_state: ModelState,
|
||||
|
||||
@@ -4319,6 +4319,13 @@ class GPUModelRunner(
|
||||
# When spec decode is enabled, defer connector finalization
|
||||
# (wait_for_save + clear metadata) until after draft model runs.
|
||||
defer_kv_connector_finalize = self.speculative_config is not None
|
||||
# Update the EPLB meta.
|
||||
if self.eplb_state is not None:
|
||||
self.eplb_state.prepare_forward(
|
||||
self.model_config,
|
||||
num_tokens_unpadded,
|
||||
ubatch_slices_padded,
|
||||
)
|
||||
with (
|
||||
set_forward_context(
|
||||
attn_metadata,
|
||||
@@ -5215,6 +5222,8 @@ class GPUModelRunner(
|
||||
self.drafter.model,
|
||||
spec_config.draft_model_config,
|
||||
)
|
||||
assert hasattr(self.drafter, "set_eplb_state")
|
||||
self.drafter.set_eplb_state(self.eplb_state)
|
||||
eplb_models += 1
|
||||
|
||||
self._setup_eagle3_aux_hidden_state_outputs()
|
||||
|
||||
Reference in New Issue
Block a user