[Feature] Support per-draft-model MoE backend via --speculative-config (#37880)
Signed-off-by: Andrii Skliar <askliar@nvidia.com> Signed-off-by: [Andrii Skliar] <askliar@nvidia.com> Co-authored-by: Andrii Skliar <askliar@nvidia.com>
This commit is contained in:
co-authored by
Andrii Skliar
parent
a1a2566447
commit
cd7643015e
@@ -9,6 +9,7 @@ from pydantic import Field, SkipValidation, model_validator
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm.config import LoadConfig
|
||||
from vllm.config.kernel import MoEBackend
|
||||
from vllm.config.model import ModelConfig
|
||||
from vllm.config.parallel import ParallelConfig
|
||||
from vllm.config.utils import config
|
||||
@@ -93,6 +94,11 @@ class SpeculativeConfig:
|
||||
"""Quantization method that was used to quantize the draft model weights.
|
||||
If `None`, we assume the model weights are not quantized. Note that it only
|
||||
takes effect when using the draft model-based speculative method."""
|
||||
moe_backend: MoEBackend | None = None
|
||||
"""MoE backend to use for the draft model. When `None`, the draft model
|
||||
inherits the target model's `--moe-backend` setting. Useful when the
|
||||
drafter and generator require different MoE kernels (e.g. quantized
|
||||
generator with unquantized drafter)."""
|
||||
max_model_len: int | None = Field(default=None, ge=1)
|
||||
"""The maximum model length of the draft model. Used when testing the
|
||||
ability to skip speculation for some sequences."""
|
||||
|
||||
@@ -6,10 +6,10 @@ import torch.nn as nn
|
||||
from typing_extensions import override
|
||||
|
||||
from vllm.config import VllmConfig
|
||||
from vllm.config.utils import replace
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.model_loader import get_model
|
||||
from vllm.v1.spec_decode.eagle import SpecDecodeBaseProposer
|
||||
from vllm.v1.spec_decode.utils import create_vllm_config_for_draft_model
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
@@ -50,16 +50,29 @@ class DraftModelProposer(SpecDecodeBaseProposer):
|
||||
"Please pass 'draft_tensor_parallel_size' in the speculative_config."
|
||||
)
|
||||
|
||||
@override
|
||||
def _create_draft_vllm_config(self) -> VllmConfig:
|
||||
base = super()._create_draft_vllm_config()
|
||||
spec = self.speculative_config
|
||||
|
||||
return replace(
|
||||
base,
|
||||
quant_config=None,
|
||||
parallel_config=replace(
|
||||
spec.draft_parallel_config,
|
||||
rank=self.vllm_config.parallel_config.rank,
|
||||
),
|
||||
model_config=spec.draft_model_config,
|
||||
)
|
||||
|
||||
@override
|
||||
def _get_model(self) -> nn.Module:
|
||||
# Draft models may be quantized or on different parallelism,
|
||||
# so we load them with a modified vllm config
|
||||
from vllm.compilation.backends import set_model_tag
|
||||
|
||||
temp_vllm_config = create_vllm_config_for_draft_model(self.vllm_config)
|
||||
draft_vllm_config = self._create_draft_vllm_config()
|
||||
with set_model_tag("draft_model"):
|
||||
model = get_model(
|
||||
vllm_config=temp_vllm_config,
|
||||
vllm_config=draft_vllm_config,
|
||||
prefix="draft_model",
|
||||
)
|
||||
return model
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
import ast
|
||||
from dataclasses import replace
|
||||
from importlib.util import find_spec
|
||||
from typing import cast
|
||||
|
||||
@@ -13,6 +12,7 @@ from vllm.config import (
|
||||
CUDAGraphMode,
|
||||
VllmConfig,
|
||||
get_layers_from_vllm_config,
|
||||
replace,
|
||||
)
|
||||
from vllm.distributed.parallel_state import get_pp_group
|
||||
from vllm.forward_context import set_forward_context
|
||||
@@ -1213,6 +1213,21 @@ class SpecDecodeBaseProposer:
|
||||
model = model.module
|
||||
return model.__class__.__name__
|
||||
|
||||
def _create_draft_vllm_config(self) -> VllmConfig:
|
||||
"""Return a VllmConfig with kernel-level overrides for the proposer.
|
||||
Subclasses may override to apply additional config changes.
|
||||
"""
|
||||
spec_cfg = self.speculative_config
|
||||
if spec_cfg.moe_backend is not None:
|
||||
return replace(
|
||||
self.vllm_config,
|
||||
kernel_config=replace(
|
||||
self.vllm_config.kernel_config,
|
||||
moe_backend=spec_cfg.moe_backend,
|
||||
),
|
||||
)
|
||||
return self.vllm_config
|
||||
|
||||
def _get_model(self) -> nn.Module:
|
||||
"""
|
||||
Default method to call get_model(). Can be overridden by subclasses which
|
||||
@@ -1220,9 +1235,10 @@ class SpecDecodeBaseProposer:
|
||||
"""
|
||||
from vllm.compilation.backends import set_model_tag
|
||||
|
||||
draft_vllm_config = self._create_draft_vllm_config()
|
||||
with set_model_tag("eagle_head"):
|
||||
model = get_model(
|
||||
vllm_config=self.vllm_config,
|
||||
vllm_config=draft_vllm_config,
|
||||
model_config=self.speculative_config.draft_model_config,
|
||||
load_config=self.speculative_config.draft_load_config,
|
||||
)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
import torch
|
||||
|
||||
from vllm.config import VllmConfig, replace
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.triton_utils import tl, triton
|
||||
from vllm.v1.attention.backends.utils import (
|
||||
@@ -258,30 +257,6 @@ def compute_new_slot_mapping(
|
||||
return new_slot_mapping
|
||||
|
||||
|
||||
def create_vllm_config_for_draft_model(
|
||||
target_model_vllm_config: VllmConfig,
|
||||
) -> VllmConfig:
|
||||
"""The vllm_config is configured for the target model, e.g.
|
||||
its quant_config and parallel_config. But the draft model is potentially
|
||||
quantized differently, and has potentially different tensor_parallel_size.
|
||||
This function creates a new vllm_config configured for the drafter.
|
||||
The vllm_config is useful when loading the draft model with get_model().
|
||||
"""
|
||||
old = target_model_vllm_config
|
||||
assert old.speculative_config is not None, "speculative_config is not set"
|
||||
old_spec_config = old.speculative_config
|
||||
new_parallel_config = replace(
|
||||
old_spec_config.draft_parallel_config, rank=old.parallel_config.rank
|
||||
)
|
||||
new: VllmConfig = replace(
|
||||
old,
|
||||
quant_config=None,
|
||||
parallel_config=new_parallel_config,
|
||||
model_config=old_spec_config.draft_model_config,
|
||||
)
|
||||
return new
|
||||
|
||||
|
||||
def extend_all_queries_by_N(
|
||||
common_attn_metadata: CommonAttentionMetadata,
|
||||
N: int,
|
||||
|
||||
Reference in New Issue
Block a user