[Config] Register the fork's knobs by cache identity; lint; gpu test marker
- Every fork knob is registered in envs.py and classified as a compile/capture factor or runtime-only; envs.py documents that capture identity and AOT cache identity are different things. - ruff findings cleared on lines this fork authored; upstream lines untouched. - A `gpu` pytest marker so the GPU-free tier can be selected, not just skipped. - Duplicate knob-table entries from two branches reconciled onto one off|warn|raise normaliser. Co-Authored-By: Hinata <hinata@idihore.id> Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
@@ -1,23 +1,45 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
"""Debug-only scheduler allocation log for KV capacity probes (off unless VLLM_E2_SCHED_LOG=<path>).
|
||||
"""Debug-only scheduler allocation log for KV-capacity probes (off unless
|
||||
VLLM_E2_SCHED_LOG=<path>).
|
||||
|
||||
One JSON line per scheduler update while any request exists, and one "fin" line per request as it is freed:
|
||||
{"t": wall, "m": monotonic, "step": n, "total": pool blocks, "free": free blocks, "running": r, "waiting": w,
|
||||
One JSON line per scheduler update while any request exists, and one "fin" line
|
||||
per request as it is freed:
|
||||
{"t": wall, "m": monotonic, "step": n, "total": pool blocks,
|
||||
"free": free blocks, "running": r, "waiting": w,
|
||||
"tot": tokens scheduled this step,
|
||||
"reqs": [[id, prompt, computed, output, cached, preemptions, spec_scheduled, status, [blocks per group],
|
||||
"reqs": [[id, prompt, computed, output, cached, preemptions,
|
||||
spec_scheduled, status, [blocks per group],
|
||||
tokens scheduled for this request this step]]}
|
||||
{"t": wall, "m": monotonic, "fin": [id, prompt, computed, output, cached, preemptions, status, [blocks per group]]}
|
||||
Blocks are counted per KV-cache group, null blocks excluded. A logging failure writes an "error" line and never
|
||||
raises into the scheduler. Unset = the scheduler only pays one env check per update.
|
||||
{"t": wall, "m": monotonic,
|
||||
"fin": [id, prompt, computed, output, cached, preemptions, status,
|
||||
[blocks per group]]}
|
||||
Blocks are counted per KV-cache group, null blocks excluded. A logging failure
|
||||
writes an "error" line and never raises into the scheduler. Unset = the
|
||||
scheduler only pays one env check per update.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
|
||||
_PATH = os.environ.get("VLLM_E2_SCHED_LOG", "")
|
||||
_state = {"f": None, "step": 0, "flush": 0.0, "wrapped": False, "errors": 0, "checked": False}
|
||||
REQ_FIELDS = ("request_id", "num_prompt_tokens", "num_computed_tokens", "num_output_tokens", "num_preemptions",
|
||||
"status", "prefill_stats")
|
||||
_state = {
|
||||
"f": None,
|
||||
"step": 0,
|
||||
"flush": 0.0,
|
||||
"wrapped": False,
|
||||
"errors": 0,
|
||||
"checked": False,
|
||||
}
|
||||
REQ_FIELDS = (
|
||||
"request_id",
|
||||
"num_prompt_tokens",
|
||||
"num_computed_tokens",
|
||||
"num_output_tokens",
|
||||
"num_preemptions",
|
||||
"status",
|
||||
"prefill_stats",
|
||||
)
|
||||
|
||||
|
||||
def enabled() -> bool:
|
||||
@@ -25,8 +47,10 @@ def enabled() -> bool:
|
||||
|
||||
|
||||
def _blocks(sched, rid):
|
||||
return [sum(1 for b in m.req_to_blocks.get(rid, ()) if not b.is_null)
|
||||
for m in sched.kv_cache_manager.coordinator.single_type_managers]
|
||||
return [
|
||||
sum(1 for b in m.req_to_blocks.get(rid, ()) if not b.is_null)
|
||||
for m in sched.kv_cache_manager.coordinator.single_type_managers
|
||||
]
|
||||
|
||||
|
||||
def _status(r):
|
||||
@@ -34,28 +58,41 @@ def _status(r):
|
||||
|
||||
|
||||
def _cached(r):
|
||||
"""Prefix-cache hit for this request. vLLM keeps it in `request.prefill_stats` (PrefillStats.num_cached_tokens =
|
||||
local + external); the output processor takes those stats after the first prefill (`take_prefill_stats` sets the
|
||||
attribute to None), so -1 means "no longer knowable from the scheduler", never a silent zero."""
|
||||
"""Prefix-cache hit for this request. vLLM keeps it in
|
||||
`request.prefill_stats` (PrefillStats.num_cached_tokens = local +
|
||||
external); the output processor takes those stats after the first prefill
|
||||
(`take_prefill_stats` sets the attribute to None), so -1 means "no longer
|
||||
knowable from the scheduler", never a silent zero."""
|
||||
ps = getattr(r, "prefill_stats", None)
|
||||
return int(getattr(ps, "num_cached_tokens", -1)) if ps is not None else -1
|
||||
|
||||
|
||||
def _contract(r):
|
||||
"""Once per process: every field this log reads must exist on the real Request object. A missing field is written
|
||||
once as a schema_error record — the evaluator fails closed on it — instead of turning every row into an error."""
|
||||
"""Once per process: every field this log reads must exist on the real Request
|
||||
object. A missing field is written once as a schema_error record — the evaluator
|
||||
fails closed on it — instead of turning every row into an error."""
|
||||
if _state["checked"]:
|
||||
return
|
||||
_state["checked"] = True
|
||||
missing = [f for f in REQ_FIELDS if not hasattr(r, f)]
|
||||
if missing:
|
||||
_write({"t": round(time.time(), 4), "m": round(time.monotonic(), 4), "schema_error": missing}, force=True)
|
||||
_write(
|
||||
{
|
||||
"t": round(time.time(), 4),
|
||||
"m": round(time.monotonic(), 4),
|
||||
"schema_error": missing,
|
||||
},
|
||||
force=True,
|
||||
)
|
||||
|
||||
|
||||
def _write(rec, force=False):
|
||||
f = _state["f"]
|
||||
if f is None:
|
||||
f = _state["f"] = open(_PATH, "a", buffering=1 << 16)
|
||||
# noqa SIM115: one append handle for the process lifetime, kept in
|
||||
# _state and flushed on a cadence; a context manager would reopen the
|
||||
# log on every scheduler update.
|
||||
f = _state["f"] = open(_PATH, "a", buffering=1 << 16) # noqa: SIM115
|
||||
f.write(json.dumps(rec, separators=(",", ":")) + "\n")
|
||||
if force or rec["t"] - _state["flush"] > 0.5:
|
||||
f.flush()
|
||||
@@ -65,10 +102,19 @@ def _write(rec, force=False):
|
||||
def _error(e):
|
||||
_state["errors"] += 1
|
||||
if _state["errors"] <= 20:
|
||||
try:
|
||||
_write({"t": round(time.time(), 4), "m": round(time.monotonic(), 4),
|
||||
"error": f"{type(e).__name__}: {e}"[:300]}, force=True)
|
||||
try: # noqa: SIM105
|
||||
_write(
|
||||
{
|
||||
"t": round(time.time(), 4),
|
||||
"m": round(time.monotonic(), 4),
|
||||
"error": f"{type(e).__name__}: {e}"[:300],
|
||||
},
|
||||
force=True,
|
||||
)
|
||||
except Exception: # noqa: BLE001
|
||||
# SIM105: this module imports json, os and time only, so that an
|
||||
# enabled log costs the scheduler nothing it can see; the
|
||||
# last-resort writer does not earn a contextlib import.
|
||||
pass
|
||||
|
||||
|
||||
@@ -77,10 +123,23 @@ def _wrap_free(sched):
|
||||
|
||||
def _free_request(request, *args, **kwargs):
|
||||
try:
|
||||
_write({"t": round(time.time(), 4), "m": round(time.monotonic(), 4),
|
||||
"fin": [request.request_id, request.num_prompt_tokens, request.num_computed_tokens,
|
||||
request.num_output_tokens, _cached(request), request.num_preemptions,
|
||||
_status(request), _blocks(sched, request.request_id)]}, force=True)
|
||||
_write(
|
||||
{
|
||||
"t": round(time.time(), 4),
|
||||
"m": round(time.monotonic(), 4),
|
||||
"fin": [
|
||||
request.request_id,
|
||||
request.num_prompt_tokens,
|
||||
request.num_computed_tokens,
|
||||
request.num_output_tokens,
|
||||
_cached(request),
|
||||
request.num_preemptions,
|
||||
_status(request),
|
||||
_blocks(sched, request.request_id),
|
||||
],
|
||||
},
|
||||
force=True,
|
||||
)
|
||||
except Exception as e: # noqa: BLE001 - the debug log must never break the scheduler
|
||||
_error(e)
|
||||
return orig(request, *args, **kwargs)
|
||||
@@ -100,12 +159,35 @@ def log_step(sched, scheduler_output) -> None:
|
||||
pool = sched.kv_cache_manager.block_pool
|
||||
nsched = getattr(scheduler_output, "num_scheduled_tokens", None) or {}
|
||||
_contract(next(iter(sched.requests.values())))
|
||||
rows = [[rid, r.num_prompt_tokens, r.num_computed_tokens, r.num_output_tokens, _cached(r),
|
||||
r.num_preemptions, len(spec.get(rid, ())), _status(r), _blocks(sched, rid), int(nsched.get(rid, 0))]
|
||||
for rid, r in sched.requests.items()]
|
||||
_write({"t": round(time.time(), 4), "m": round(time.monotonic(), 4), "step": _state["step"],
|
||||
"total": pool.num_gpu_blocks, "free": pool.get_num_free_blocks(),
|
||||
"running": len(sched.running), "waiting": len(sched.waiting),
|
||||
"tot": int(getattr(scheduler_output, "total_num_scheduled_tokens", 0) or 0), "reqs": rows})
|
||||
rows = [
|
||||
[
|
||||
rid,
|
||||
r.num_prompt_tokens,
|
||||
r.num_computed_tokens,
|
||||
r.num_output_tokens,
|
||||
_cached(r),
|
||||
r.num_preemptions,
|
||||
len(spec.get(rid, ())),
|
||||
_status(r),
|
||||
_blocks(sched, rid),
|
||||
int(nsched.get(rid, 0)),
|
||||
]
|
||||
for rid, r in sched.requests.items()
|
||||
]
|
||||
_write(
|
||||
{
|
||||
"t": round(time.time(), 4),
|
||||
"m": round(time.monotonic(), 4),
|
||||
"step": _state["step"],
|
||||
"total": pool.num_gpu_blocks,
|
||||
"free": pool.get_num_free_blocks(),
|
||||
"running": len(sched.running),
|
||||
"waiting": len(sched.waiting),
|
||||
"tot": int(
|
||||
getattr(scheduler_output, "total_num_scheduled_tokens", 0) or 0
|
||||
),
|
||||
"reqs": rows,
|
||||
}
|
||||
)
|
||||
except Exception as e: # noqa: BLE001
|
||||
_error(e)
|
||||
|
||||
@@ -2,8 +2,12 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Compatibility exports for the top-level test-only fault singleton."""
|
||||
|
||||
from vllm_ple_test_fault import (
|
||||
_FAULT as _FAULT,
|
||||
)
|
||||
from vllm_ple_test_fault import ( # noqa: F401
|
||||
FaultSpec as FaultSpec,
|
||||
_FAULT as _FAULT,
|
||||
)
|
||||
from vllm_ple_test_fault import (
|
||||
_parse_fault_spec as _parse_fault_spec,
|
||||
)
|
||||
|
||||
@@ -121,9 +121,7 @@ SITE_NAMES = {
|
||||
_MODE = os.environ.get("VLLM_E2_GUARD_MODE", "off").strip().lower()
|
||||
if _MODE not in ("raise", "warn", "off"):
|
||||
# fail closed: a set-but-broken gate must not silently disarm the instrument
|
||||
raise ValueError(
|
||||
f"VLLM_E2_GUARD_MODE must be raise|warn|off, got {_MODE!r}"
|
||||
)
|
||||
raise ValueError(f"VLLM_E2_GUARD_MODE must be raise|warn|off, got {_MODE!r}")
|
||||
|
||||
|
||||
def _parse_interval(text: str) -> float:
|
||||
@@ -188,7 +186,7 @@ class NonBlockingReader:
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self._streams: dict[torch.device, "torch.cuda.Stream"] = {}
|
||||
self._streams: dict[torch.device, torch.cuda.Stream] = {}
|
||||
# key -> [device_tensor, pinned_host_tensor | None, event | None, inflight]
|
||||
self._jobs: dict[object, list] = {}
|
||||
self._lock = threading.Lock()
|
||||
@@ -213,7 +211,9 @@ class NonBlockingReader:
|
||||
if dev not in self._streams:
|
||||
with torch.cuda.device(dev):
|
||||
self._streams[dev] = torch.cuda.Stream(device=dev)
|
||||
host = torch.empty(tensor.shape, dtype=tensor.dtype, device="cpu", pin_memory=True)
|
||||
host = torch.empty(
|
||||
tensor.shape, dtype=tensor.dtype, device="cpu", pin_memory=True
|
||||
)
|
||||
with torch.cuda.device(dev):
|
||||
event = torch.cuda.Event()
|
||||
self._jobs[key] = [tensor, host, event, False]
|
||||
@@ -280,7 +280,8 @@ class NonBlockingReader:
|
||||
|
||||
|
||||
_nb_reader = NonBlockingReader()
|
||||
# device -> the copy in which a count increase was first seen (reported on the next tick)
|
||||
# device -> the copy in which a count increase was first seen
|
||||
# (reported on the next tick)
|
||||
_confirm_pending: dict[torch.device, list] = {}
|
||||
|
||||
# Sites that arm the pending raise even under VLLM_E2_GUARD_MODE=warn. warn is
|
||||
@@ -389,12 +390,11 @@ def start_reader() -> None:
|
||||
if _reader_started or _MODE == "off":
|
||||
return
|
||||
_reader_started = True
|
||||
threading.Thread(
|
||||
target=_reader, name="bounds-guard-reader", daemon=True
|
||||
).start()
|
||||
threading.Thread(target=_reader, name="bounds-guard-reader", daemon=True).start()
|
||||
logger.info(
|
||||
"bounds-guard reader started (mode=%s, interval=%.3gs).",
|
||||
_MODE, _INTERVAL,
|
||||
_MODE,
|
||||
_INTERVAL,
|
||||
)
|
||||
|
||||
|
||||
@@ -459,7 +459,11 @@ def _poll_once() -> None:
|
||||
# by which time the maxima of that hit are written). The fatal
|
||||
# decision is count-based either way; only its report waits a tick.
|
||||
pend = _confirm_pending.get(device)
|
||||
rising = [site for site, (n, _r, _v) in enumerate(rows) if n > _seen.get((device, site), 0)]
|
||||
rising = [
|
||||
site
|
||||
for site, (n, _r, _v) in enumerate(rows)
|
||||
if n > _seen.get((device, site), 0)
|
||||
]
|
||||
if pend is None:
|
||||
if rising:
|
||||
_confirm_pending[device] = rows
|
||||
@@ -572,21 +576,18 @@ def drain(*, raise_on_fatal: bool = False) -> dict[str, list[int]]:
|
||||
_report_rows(device, rows)
|
||||
for site, (n_masked, _r, _v) in enumerate(rows):
|
||||
if n_masked and (_MODE == "raise" or site in _ALWAYS_FATAL_SITES):
|
||||
fatal.append(
|
||||
f"{SITE_NAMES.get(site, site)} on {device}: {n_masked}"
|
||||
)
|
||||
fatal.append(f"{SITE_NAMES.get(site, site)} on {device}: {n_masked}")
|
||||
snap = snapshot()
|
||||
if fatal:
|
||||
logger.error(
|
||||
"bounds-guard FINAL DRAIN: fatal-site hits %s (snapshot %s)",
|
||||
fatal, snap,
|
||||
fatal,
|
||||
snap,
|
||||
)
|
||||
if raise_on_fatal:
|
||||
raise RuntimeError(f"bounds-guard FINAL DRAIN: fatal-site hits {fatal}")
|
||||
else:
|
||||
logger.info(
|
||||
"bounds-guard FINAL DRAIN: no fatal-site hits (snapshot %s)", snap
|
||||
)
|
||||
logger.info("bounds-guard FINAL DRAIN: no fatal-site hits (snapshot %s)", snap)
|
||||
return snap
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user