Files
vLLM/vllm/v1/ple_offload/rowdump.py
T
MOVZXandHinata 3b5fc7c7be [Worker] Boundary allocator telemetry and an opt-in PLE row dump
Env-gated diagnostics, inert unless set. Allocator telemetry is read only at
step boundaries, armed after warm-up and capture.

Co-Authored-By: Hinata <hinata@idihore.id>
Signed-off-by: MOVZX <movzx@yahoo.com>
2026-10-09 19:49:50 +07:00

42 lines
1.5 KiB
Python

# SPDX-License-Identifier: Apache-2.0
"""Debug-only PLE row dump for byte-level transport checks (off unless VLLM_PLE_ROW_DUMP=<dir>).
Each process appends framed records to <dir>/<tag>-pid<pid>.bin:
b"PLER" | kind u8 (0 = GPU worker: rows its forward consumed; 1 = offload process: rows it published)
| rank u8 | reserved u16 | seq u32 | n u32 | row_bytes u32 | ids int64[n] | rows uint8[n * row_bytes]
"""
import os
import struct
import threading
import torch
_DIR = os.environ.get("VLLM_PLE_ROW_DUMP", "")
_LOCK = threading.Lock()
_FILES: dict = {}
MAGIC = b"PLER"
def enabled() -> bool:
return bool(_DIR)
def write(tag: str, kind: int, rank: int, seq: int, ids: torch.Tensor, rows: torch.Tensor) -> None:
ids_cpu = ids.detach().to(device="cpu", dtype=torch.int64).contiguous()
rows_cpu = rows.detach().to(device="cpu").contiguous()
n = int(ids_cpu.shape[0])
if rows_cpu.shape[0] != n:
raise RuntimeError(f"PLE row dump: {rows_cpu.shape[0]} rows for {n} ids")
raw = rows_cpu.view(torch.uint8).numpy().tobytes() if n else b""
row_bytes = len(raw) // n if n else 0
record = (MAGIC + struct.pack("<BBHIII", kind, rank, 0, seq, n, row_bytes)
+ ids_cpu.numpy().tobytes() + raw)
with _LOCK:
f = _FILES.get(tag)
if f is None:
os.makedirs(_DIR, exist_ok=True)
f = open(os.path.join(_DIR, f"{tag}-pid{os.getpid()}.bin"), "ab", buffering=0)
_FILES[tag] = f
f.write(record)