[Qwen4Exp] Support UVA PLE-offload and Engram tensor parallelism (#54371)

Signed-off-by: huanghaoyan.hhy <huanghaoyan.hhy@alibaba-inc.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Harry Huang
2026-09-09 07:32:34 -07:00
committed by GitHub
co-authored by mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 62f3bf58a5
commit 3116c5d06b
16 changed files with 1712 additions and 495 deletions
+3
View File
@@ -13,6 +13,7 @@ from vllm.config.device import DeviceConfig
from vllm.config.diffusion import DiffusionConfig
from vllm.config.ec_manager_config import EncoderCacheManagerConfig
from vllm.config.ec_transfer import ECTransferConfig
from vllm.config.engram import EngramConfig
from vllm.config.fault_tolerance import FaultToleranceConfig
from vllm.config.kernel import KernelConfig
from vllm.config.kv_events import KVEventsConfig
@@ -81,6 +82,8 @@ __all__ = [
"EncoderCacheManagerConfig",
# From vllm.config.ec_transfer
"ECTransferConfig",
# From vllm.config.engram
"EngramConfig",
# From vllm.config.kernel
"KernelConfig",
# From vllm.config.kv_events
+82
View File
@@ -0,0 +1,82 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from typing import TYPE_CHECKING
from pydantic import Field
import vllm.envs as envs
from vllm.config.utils import config, get_hash_factors, hash_factors
from vllm.logger import init_logger
if TYPE_CHECKING:
from vllm.config.model import ModelConfig
from vllm.config.parallel import ParallelConfig
logger = init_logger(__name__)
def _default_cpu_offload() -> bool:
"""Honor the legacy environment variable only when the field is omitted."""
if envs.is_set("VLLM_PLE_CPU_OFFLOAD"):
logger.warning_once(
"VLLM_PLE_CPU_OFFLOAD is a legacy setting and may be removed in a "
"future release. Use --engram-config.cpu_offload instead."
)
return envs.VLLM_PLE_CPU_OFFLOAD
@config
class EngramConfig:
"""Configuration for Engram embedding storage and sharding."""
cpu_offload: bool = Field(default_factory=_default_cpu_offload)
"""Store embedding weights in pinned CPU memory for UVA lookup.
Defaults to False, or VLLM_PLE_CPU_OFFLOAD when set for compatibility.
An explicit value takes precedence over the legacy environment variable."""
embedding_across_dp: bool = False
"""Shard embeddings across TP and all DP ranks when enabled.
Otherwise, each DP rank has a separate TP-sharded embedding replica."""
def verify_model_config(self, model_config: "ModelConfig | None") -> None:
"""Reject Engram configuration for models without supported embeddings."""
from vllm.platforms import current_platform
supported_architectures = {
"Qwen4ExpForCausalLM",
"Qwen4ExpForConditionalGeneration",
}
if (
model_config is None
or model_config.architecture not in supported_architectures
or not current_platform.is_cuda()
or not getattr(model_config.hf_text_config, "ple_layer_ids", None)
):
raise ValueError(
"EngramConfig requires a model with supported Engram "
"embeddings. Currently only the CUDA Qwen4Exp implementation "
"with non-empty ple_layer_ids is supported."
)
def verify_parallel_config(self, parallel_config: "ParallelConfig") -> None:
"""Reject unsupported embedding parallel topologies."""
if (
self.embedding_across_dp
and parallel_config.data_parallel_size > 1
and parallel_config.enable_elastic_ep
):
raise ValueError(
"Engram embedding_across_dp is not supported with elastic EP yet."
)
def get_parallel_size(self, parallel_config: "ParallelConfig") -> int:
"""Derive the embedding group size from the parallel configuration."""
size = parallel_config.tensor_parallel_size
if self.embedding_across_dp and parallel_config.data_parallel_size > 1:
size *= parallel_config.data_parallel_size
return size
def compute_hash(self) -> str:
"""Hash settings that affect embedding execution and graph structure."""
return hash_factors(get_hash_factors(self, set()))
+28
View File
@@ -34,6 +34,7 @@ from .device import DeviceConfig
from .diffusion import DiffusionConfig
from .ec_manager_config import EncoderCacheManagerConfig
from .ec_transfer import ECTransferConfig
from .engram import EngramConfig
from .kernel import KernelConfig
from .kv_events import KVEventsConfig
from .kv_transfer import KVTransferConfig
@@ -370,6 +371,8 @@ class VllmConfig:
"""Model weight offloading configuration."""
attention_config: AttentionConfig = Field(default_factory=AttentionConfig)
"""Attention configuration."""
engram_config: EngramConfig | None = None
"""Optional Engram configuration, only valid for supported PLE models."""
mamba_config: MambaConfig = Field(default_factory=MambaConfig)
"""Mamba configuration."""
kernel_config: KernelConfig = Field(default_factory=KernelConfig)
@@ -506,6 +509,11 @@ class VllmConfig:
vllm_factors.append(self.attention_config.compute_hash())
else:
vllm_factors.append("None")
vllm_factors.append(
self.engram_config.compute_hash()
if self.engram_config is not None
else "None"
)
if self.lora_config:
vllm_factors.append(self.lora_config.compute_hash())
else:
@@ -1083,6 +1091,25 @@ class VllmConfig:
if not self.use_v2_model_runner:
raise ValueError("trace replay requires Model Runner V2")
def _resolve_and_verify_engram_config(self) -> None:
"""Resolve legacy offload settings and validate model and parallel configs."""
if self.engram_config is None:
if not envs.VLLM_PLE_CPU_OFFLOAD:
return
self.engram_config = EngramConfig()
model_config = self.model_config
speculative_config = self.speculative_config
# Draft configs inherit the target's communication groups and settings.
# Qwen4Exp MTP itself disables PLE, so validate its target instead.
if (
speculative_config is not None
and model_config is speculative_config.draft_model_config
):
model_config = speculative_config.target_model_config
self.engram_config.verify_model_config(model_config)
self.engram_config.verify_parallel_config(self.parallel_config)
logger.info_once("Resolved Engram configuration: %s", str(self.engram_config))
def __post_init__(self):
"""Verify configs are valid & consistent with each other."""
@@ -1095,6 +1122,7 @@ class VllmConfig:
logger.info_once("Performance mode set to '%s'.", self.performance_mode)
self.try_verify_and_update_config()
self._resolve_and_verify_engram_config()
# Models may have supplied their own DCP defaults above; anything still
# unset falls back to the stock ones.