- VLLM_E2_PLE_PULL_TRANSPORT replaces the fork's old switch name, which v0.30.0 reuses for its UVA backend with the opposite default; strict parser; compile/capture factor. - The pull transport is reachable on v0.30.0 through a pull embedding class that inherits upstream's without editing it; the upstream UVA backend is provably off while the pull switch is on. - resolve_ple_mode()/assert_ple_mode() log and assert the effective PLE mode for target and drafter, and refuse a mixed configuration. - Producer log lines for the PLE backend and weight dtype. - CPU tests for mode resolution and the mixed-config refusal. Co-Authored-By: Hinata <hinata@idihore.id> Signed-off-by: MOVZX <movzx@yahoo.com>
148 lines
6.3 KiB
Python
148 lines
6.3 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
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
|
|
|
|
if TYPE_CHECKING:
|
|
from vllm.config.model import ModelConfig
|
|
from vllm.config.parallel import ParallelConfig
|
|
|
|
# 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 = {
|
|
"DeepseekV41ForCausalLM": "engram_layer_ids",
|
|
"Qwen4ExpForCausalLM": "ple_layer_ids",
|
|
"Qwen4ExpForConditionalGeneration": "ple_layer_ids",
|
|
}
|
|
|
|
|
|
def _default_cpu_offload() -> bool:
|
|
# Fork: with VLLM_E2_PLE_PULL_TRANSPORT=1 the default is False and a
|
|
# VLLM_PLE_CPU_OFFLOAD value that would enable UVA fails the boot. With the
|
|
# pull transport off, the upstream default below is returned unchanged.
|
|
from vllm.v1.e2_guards import pull_transport_cpu_offload_default
|
|
|
|
if not envs.VLLM_E2_PLE_PULL_TRANSPORT:
|
|
return envs.VLLM_PLE_CPU_OFFLOAD
|
|
return pull_transport_cpu_offload_default(False)
|
|
|
|
|
|
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 VLLM_PLE_CPU_OFFLOAD, which is enabled by default. An explicit
|
|
value takes precedence over the environment variable. With
|
|
VLLM_E2_PLE_PULL_TRANSPORT=1 the default is False and a value that would
|
|
enable UVA fails the boot (vllm/v1/e2_guards.py)."""
|
|
|
|
host_file_gather: bool = False
|
|
"""Serve Qwen4Exp PLE rows by gathering them on the CPU from the loader's
|
|
file-backed checkpoint views and staging them on the device each step,
|
|
instead of allocating the table; takes precedence over `cpu_offload`."""
|
|
|
|
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 | None = None
|
|
"""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. Defaults to enabled whenever
|
|
the other settings allow it, falling back to per-replica tables when DP
|
|
replicas are not co-located on one node or /dev/shm cannot hold them."""
|
|
|
|
use_thp: bool = False
|
|
"""Back private CPU-offloaded tables with transparent huge pages (best
|
|
effort, falls back to ordinary pinned pages). Prefaulting the tables at
|
|
startup takes longer. Requires cpu_offload without dp_shared_memory."""
|
|
|
|
@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")
|
|
if self.use_thp and (not self.cpu_offload or self.dp_shared_memory):
|
|
raise ValueError(
|
|
"use_thp requires cpu_offload=True and dp_shared_memory=False"
|
|
)
|
|
return self
|
|
|
|
def verify_model_config(self, model_config: "ModelConfig | None") -> None:
|
|
"""Reject Engram configuration for models without n-gram embeddings."""
|
|
field = (
|
|
_NGRAM_LAYER_FIELDS.get(model_config.architecture)
|
|
if model_config is not None
|
|
else None
|
|
)
|
|
if (
|
|
model_config is None
|
|
or field is None
|
|
or not getattr(model_config.hf_text_config, field, None)
|
|
):
|
|
raise ValueError(
|
|
"EngramConfig requires a model with supported Engram "
|
|
"embeddings and non-empty n-gram layer ids."
|
|
)
|
|
if self.host_file_gather and (
|
|
field != "ple_layer_ids" or current_platform.is_rocm()
|
|
):
|
|
raise ValueError("host_file_gather requires a Qwen4Exp model on CUDA")
|
|
|
|
def resolve_dp_shared_memory(self, parallel_config: "ParallelConfig") -> None:
|
|
"""Share host tables by default wherever the configuration permits."""
|
|
if self.dp_shared_memory is None:
|
|
self.dp_shared_memory = (
|
|
self.cpu_offload
|
|
and not self.use_thp
|
|
and parallel_config.data_parallel_size > 1
|
|
and not parallel_config.enable_elastic_ep
|
|
)
|
|
|
|
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
|
|
and parallel_config.enable_elastic_ep
|
|
):
|
|
raise ValueError(
|
|
"Engram embedding_across_dp is not supported with elastic EP yet."
|
|
)
|
|
if self.host_file_gather and parallel_config.enable_elastic_ep:
|
|
raise ValueError("host_file_gather is not supported with elastic EP.")
|
|
|
|
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()))
|