[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:
@@ -38,6 +38,11 @@ class EngramConfig:
|
||||
cpu_offload: bool = True
|
||||
"""Store embedding weights in pinned CPU memory for UVA lookup."""
|
||||
|
||||
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."""
|
||||
@@ -85,6 +90,10 @@ class EngramConfig:
|
||||
"embeddings, non-empty n-gram layer ids, and a CUDA-alike "
|
||||
"device (CUDA or ROCm)."
|
||||
)
|
||||
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."""
|
||||
@@ -110,6 +119,8 @@ class EngramConfig:
|
||||
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."""
|
||||
|
||||
Reference in New Issue
Block a user