[DS V4.1][Engram] Support async prefetch for offloaded engram lookups and engram DP sharding (#56512)
Signed-off-by: Juntian Liu <Juntianl777@gmail.com> Signed-off-by: Woosuk Kwon <woosuk@inferact.ai> Co-authored-by: Roger Wang <hey@rogerw.io> Co-authored-by: ywang96 <> Co-authored-by: Woosuk Kwon <woosuk@inferact.ai> Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
co-authored by
Roger Wang
ywang96 <>
Woosuk Kwon
Codex
parent
e7a3963339
commit
d2d649e674
+45
-15
@@ -3,18 +3,17 @@
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic import Field, model_validator
|
||||
from typing_extensions import Self
|
||||
|
||||
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.load import LoadConfig
|
||||
from vllm.config.model import ModelConfig
|
||||
from vllm.config.parallel import ParallelConfig
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
# Architecture -> the hf_text_config field naming its n-gram layers. A model is
|
||||
# only configurable here if it actually has such layers to store.
|
||||
_NGRAM_LAYER_FIELDS = {
|
||||
@@ -25,28 +24,44 @@ _NGRAM_LAYER_FIELDS = {
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
def model_has_engram_layers(model_config: "ModelConfig | None") -> bool:
|
||||
"""Whether the model carries n-gram embedding layers."""
|
||||
if model_config is None:
|
||||
return False
|
||||
field = _NGRAM_LAYER_FIELDS.get(model_config.architecture)
|
||||
if field is None:
|
||||
return False
|
||||
return bool(getattr(model_config.hf_text_config, field, None))
|
||||
|
||||
|
||||
@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."""
|
||||
Defaults to VLLM_PLE_CPU_OFFLOAD, which is enabled by default. An explicit
|
||||
value takes precedence over the 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."""
|
||||
|
||||
dp_shared_memory: bool = False
|
||||
"""Share CPU-offloaded embedding weights between co-located
|
||||
DP replicas. Each node stores one copy of every TP shard, reducing host
|
||||
memory without per-step Engram DP collectives. Requires sufficient
|
||||
/dev/shm capacity and a shared IPC namespace."""
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _validate_shared_memory(self) -> Self:
|
||||
if self.dp_shared_memory and not self.cpu_offload:
|
||||
raise ValueError("dp_shared_memory requires cpu_offload=True")
|
||||
return self
|
||||
|
||||
def verify_model_config(self, model_config: "ModelConfig | None") -> None:
|
||||
"""Reject Engram configuration for models without n-gram embeddings."""
|
||||
from vllm.platforms import current_platform
|
||||
@@ -64,13 +79,16 @@ class EngramConfig:
|
||||
):
|
||||
raise ValueError(
|
||||
"EngramConfig requires a model with supported Engram "
|
||||
"embeddings. Currently only the CUDA Qwen4Exp and DeepSeek "
|
||||
"V4.1 implementations with non-empty n-gram layer ids are "
|
||||
"supported."
|
||||
"embeddings, non-empty n-gram layer ids, and CUDA."
|
||||
)
|
||||
|
||||
def verify_parallel_config(self, parallel_config: "ParallelConfig") -> None:
|
||||
"""Reject unsupported embedding parallel topologies."""
|
||||
if self.dp_shared_memory:
|
||||
if parallel_config.data_parallel_size <= 1:
|
||||
raise ValueError("dp_shared_memory requires data_parallel_size > 1.")
|
||||
if parallel_config.enable_elastic_ep:
|
||||
raise ValueError("dp_shared_memory is not supported with elastic EP.")
|
||||
if (
|
||||
self.embedding_across_dp
|
||||
and parallel_config.data_parallel_size > 1
|
||||
@@ -80,6 +98,18 @@ class EngramConfig:
|
||||
"Engram embedding_across_dp is not supported with elastic EP yet."
|
||||
)
|
||||
|
||||
def verify_load_config(self, load_config: "LoadConfig") -> None:
|
||||
"""Shared tables require a loader that invokes parameter weight callbacks."""
|
||||
if self.dp_shared_memory and load_config.load_format not in (
|
||||
"auto",
|
||||
"safetensors",
|
||||
"pt",
|
||||
):
|
||||
raise ValueError(
|
||||
"dp_shared_memory requires load_format 'auto', "
|
||||
f"'safetensors' or 'pt'; got {load_config.load_format!r}."
|
||||
)
|
||||
|
||||
def get_parallel_size(self, parallel_config: "ParallelConfig") -> int:
|
||||
"""Derive the embedding group size from the parallel configuration."""
|
||||
size = parallel_config.tensor_parallel_size
|
||||
|
||||
+23
-8
@@ -34,7 +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 .engram import EngramConfig, model_has_engram_layers
|
||||
from .kernel import KernelConfig
|
||||
from .kv_events import KVEventsConfig
|
||||
from .kv_transfer import KVTransferConfig
|
||||
@@ -381,7 +381,7 @@ class VllmConfig:
|
||||
attention_config: AttentionConfig = Field(default_factory=AttentionConfig)
|
||||
"""Attention configuration."""
|
||||
engram_config: EngramConfig | None = None
|
||||
"""Optional Engram configuration, only valid for supported PLE models."""
|
||||
"""N-gram embedding storage and sharding settings."""
|
||||
mamba_config: MambaConfig = Field(default_factory=MambaConfig)
|
||||
"""Mamba configuration."""
|
||||
kernel_config: KernelConfig = Field(default_factory=KernelConfig)
|
||||
@@ -1218,22 +1218,37 @@ class VllmConfig:
|
||||
)
|
||||
|
||||
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()
|
||||
"""Resolve defaults and validate n-gram embedding settings."""
|
||||
from vllm.platforms import current_platform
|
||||
|
||||
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.
|
||||
# Validate the target because the draft may disable n-gram embeddings.
|
||||
if (
|
||||
speculative_config is not None
|
||||
and model_config is speculative_config.draft_model_config
|
||||
):
|
||||
model_config = speculative_config.target_model_config
|
||||
if (
|
||||
model_config is not None
|
||||
and model_config.architecture == "DeepseekV41ForCausalLM"
|
||||
and getattr(model_config.hf_text_config, "engram_layer_ids", None)
|
||||
and self.parallel_config.use_ubatching
|
||||
):
|
||||
raise ValueError(
|
||||
"DeepSeek V4.1 Engram does not support DBO or microbatching. "
|
||||
"Disable --enable-dbo and set --ubatch-size to 0."
|
||||
)
|
||||
if self.engram_config is None:
|
||||
if not current_platform.is_cuda() or not model_has_engram_layers(
|
||||
model_config
|
||||
):
|
||||
return
|
||||
self.engram_config = EngramConfig()
|
||||
self.engram_config.verify_model_config(model_config)
|
||||
self.engram_config.verify_parallel_config(self.parallel_config)
|
||||
self.engram_config.verify_load_config(self.load_config)
|
||||
logger.info_once("Resolved Engram configuration: %s", str(self.engram_config))
|
||||
|
||||
def __post_init__(self):
|
||||
|
||||
Reference in New Issue
Block a user