[Qwen4Exp] Host-resident token embedding tables (VLLM_HOST_EMBED_TABLE)

Keeps the token embedding table in pinned host memory behind a UVA view for the
stage-0 target and the last-stage MTP drafter, freeing GPU memory for KV. TP
sharding, masking and the all-reduce are retained. The knob is registered as a
compile-cache factor.

Co-Authored-By: Hinata <hinata@idihore.id>
Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
2026-10-09 19:43:53 +07:00
co-authored by Hinata
parent 66b3d8c108
commit 41f6691c26
4 changed files with 231 additions and 3 deletions
+27 -1
View File
@@ -30,8 +30,10 @@ from vllm.model_executor.layers.mamba.mamba_utils import (
)
from vllm.model_executor.layers.quantization import QuantizationConfig
from vllm.model_executor.layers.vocab_parallel_embedding import (
PinnedHostVocabParallelEmbedding,
ParallelLMHead,
VocabParallelEmbedding,
should_use_host_embed_table,
)
from vllm.model_executor.models.interfaces import (
HasInnerState,
@@ -487,7 +489,31 @@ class Qwen4ExpModel(nn.Module):
if layer_type in _QSA_LAYER_TYPES
and getattr(config, "indexer_n_heads", None) is not None
)
self.embed_tokens = VocabParallelEmbedding(self.vocab_size, config.hidden_size)
self.uses_host_embed_table = (
get_pp_group().is_first_rank
and should_use_host_embed_table()
)
if self.uses_host_embed_table and getattr(
config, "tie_word_embeddings", False
):
raise ValueError(
"VLLM_HOST_EMBED_TABLE=1 is incompatible with "
"tie_word_embeddings=True"
)
# PP ownership: the input embedding runs on
# the first stage only (see forward); later stages carried an unused
# 248320 x 2560 bf16 table (0.59 GiB per GPU at TP2) beside the MTP
# drafter's own copy. PP=1 ownership is unchanged, and the PLE offload
# worker retains meta construction.
if get_pp_group().is_first_rank:
embedding_cls = (
PinnedHostVocabParallelEmbedding
if self.uses_host_embed_table
else VocabParallelEmbedding
)
self.embed_tokens = embedding_cls(self.vocab_size, config.hidden_size)
else:
self.embed_tokens = PPMissingLayer()
def get_layer(prefix: str) -> Qwen4ExpDecoderLayer:
layer_idx = extract_layer_index(prefix)
+16 -2
View File
@@ -29,8 +29,10 @@ from vllm.model_executor.layers.layernorm import GemmaRMSNorm
from vllm.model_executor.layers.linear import ColumnParallelLinear
from vllm.model_executor.layers.logits_processor import LogitsProcessor
from vllm.model_executor.layers.vocab_parallel_embedding import (
PinnedHostVocabParallelEmbedding,
ParallelLMHead,
VocabParallelEmbedding,
should_use_host_embed_table,
)
from vllm.model_executor.model_loader.utils import configure_quant_config
from vllm.model_executor.models.interfaces import (
@@ -183,7 +185,20 @@ class Qwen4ExpMultiTokenPredictor(nn.Module):
self.hidden_size = config.hidden_size
self.hc_count = config.hc_count
self.embed_tokens = VocabParallelEmbedding(self.vocab_size, self.hidden_size)
self.uses_host_embed_table = should_use_host_embed_table()
if self.uses_host_embed_table and getattr(
config, "tie_word_embeddings", False
):
raise ValueError(
"VLLM_HOST_EMBED_TABLE=1 is incompatible with "
"tie_word_embeddings=True"
)
embedding_cls = (
PinnedHostVocabParallelEmbedding
if self.uses_host_embed_table
else VocabParallelEmbedding
)
self.embed_tokens = embedding_cls(self.vocab_size, self.hidden_size)
draft_vllm_config = _make_draft_vllm_config(
vllm_config,
self.mtp_start_layer_idx,
@@ -314,7 +329,6 @@ class Qwen4ExpMultiTokenPredictor(nn.Module):
hidden_states = hidden_states.flatten(-2)
prev_block_output = inputs_embeds
else:
assert intermediate_tensors is not None
hidden_states = intermediate_tensors["hidden_states"]
current_step_idx = spec_step_idx % self.num_mtp_layers