[Qwen4Exp] Serve PLE rows from the loader's mapped checkpoint shards (PR #58815)
Adds an opt-in backend, --engram-config '{"host_file_gather": true}', that
serves Qwen4Exp PLE rows from the checkpoint files through the page cache
instead of allocating the 47.7 GiB table on GPU or in pinned host memory.
- Qwen4ExpPLEFileGatherEmbedding allocates no table rows; load_weights keeps
the default loader's zero-copy safetensors views of each shard. At bind
(post-load hook) every view must be file-backed per /proc/self/maps (HF
cache symlinks work; heap/pinned/anonymous memory is rejected) and the
shards must cover the whole table.
- Each step, Qwen4ExpModelState.prepare_inputs computes the PLE n-gram ids,
copies them to pinned host memory, syncs the stream once, issues
POSIX_FADV_WILLNEED over the coalesced page ranges of the step's rows,
gathers the rows on the host, and copies them into a fixed device staging
buffer. The forward reads only the staging buffer, so FULL CUDA graph
capture is unaffected.
- Rows stay in the checkpoint dtype (FP8 table stays FP8, dequantized on the
GPU); dummy loads serve zeros; weight reload is rejected; takes precedence
over cpu_offload; rejected on ROCm and with elastic EP.
Co-Authored-By: Hinata <hinata@idihore.id>
Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
@@ -13,6 +13,12 @@ from vllm.v1.worker.gpu.mm.encoder_cache import EncoderCache
|
||||
from vllm.v1.worker.gpu.model_states.mamba_hybrid import MambaHybridModelState
|
||||
from vllm.v1.worker.gpu.states import RequestState
|
||||
|
||||
from .ngram_embedding import (
|
||||
Qwen4ExpNGramEmbedding,
|
||||
Qwen4ExpPLEFileGatherEmbedding,
|
||||
stage_checkpoint_rows,
|
||||
)
|
||||
|
||||
|
||||
class Qwen4ExpModelState(MambaHybridModelState):
|
||||
"""Add rollback-safe PLE n-gram context to the model inputs."""
|
||||
@@ -63,6 +69,12 @@ class Qwen4ExpModelState(MambaHybridModelState):
|
||||
dtype=torch.int32,
|
||||
device=self.device,
|
||||
)
|
||||
self.file_gather_modules = [
|
||||
module
|
||||
for module in model.modules()
|
||||
if isinstance(module, Qwen4ExpNGramEmbedding)
|
||||
and isinstance(module.ngram_embedding, Qwen4ExpPLEFileGatherEmbedding)
|
||||
]
|
||||
|
||||
def _prepare_ngram_context(
|
||||
self,
|
||||
@@ -106,9 +118,17 @@ class Qwen4ExpModelState(MambaHybridModelState):
|
||||
query_start_loc[: num_reqs_padded + 1].copy_(input_batch.query_start_loc)
|
||||
# Represent unused capacity as trailing zero-length requests.
|
||||
query_start_loc[num_reqs_padded + 1 :].copy_(input_batch.query_start_loc[-1])
|
||||
ngram_context = self._prepare_ngram_context(input_batch, req_states)
|
||||
if self.file_gather_modules:
|
||||
stage_checkpoint_rows(
|
||||
self.file_gather_modules,
|
||||
input_batch.input_ids,
|
||||
query_start_loc,
|
||||
ngram_context,
|
||||
)
|
||||
model_inputs.update(
|
||||
query_start_loc=query_start_loc,
|
||||
ngram_context=self._prepare_ngram_context(input_batch, req_states),
|
||||
ngram_context=ngram_context,
|
||||
)
|
||||
return model_inputs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user