Files
vLLM/vllm/v1/worker/e2_identity.py
T
MOVZXandHinata 281491646d [Worker] E2-identity and rank-tagged e2-toggles startup lines
Each worker logs its launch identity and, after warm-up and capture, one
e2-toggles line with the effective toggle state read back from the C++
extensions through two new tensor-free query ops. Both extensions must be
rebuilt.

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

149 lines
5.7 KiB
Python

# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Per-rank launch-identity log line (log-only; changes no behaviour).
After model loading -- and after the PLE offload placeholders are armed -- every
GPU worker rank logs one line per model role it holds::
e2-identity[PP<p>_TP<t>]: ple_backend=<class>@<transport> ple_method=<class>
ple_weight_dtype=<dtype> breakable=<ON|OFF> compile_mode=<mode>
cudagraph_mode=<mode> role=<target|draft>
(one line in the log). ``role=draft`` is logged only where a draft model is
loaded (the last PP stage). Every value is read from the live objects:
* ``ple_backend``: the class of each PLE layer's ``ple_embedding`` module, and
the transport that serves its rows on this rank, read from the placeholder's
armed state -- ``host-mapped-pull`` (``_is_cpu_offloaded`` with a host output
pointer), ``ipc-push`` (offloaded, no host pointer) or ``local:<device>`` (the
rank owns the table).
* ``ple_method``: the embedding's live ``quant_method``, or, on an offloaded
placeholder, the ``_offload_quant_method`` the rank dequantizes with.
* ``ple_weight_dtype``: the table's dtype where the rank owns it; on an
offloaded placeholder, the dtype of the armed transfer buffer, into which the
offload process copies the table's rows unchanged
(``get_offload_output_dtype``).
* ``breakable``: ``is_breakable_cudagraph_enabled()``, the switch the capture
path itself reads.
* ``compile_mode`` / ``cudagraph_mode``: the role's ``CompilationConfig``
(config level, i.e. before KV-cache-time capture-mode resolution).
A role with no PLE layer reports ``none`` for the three PLE fields; several
distinct values on one rank are joined with ``,``.
"""
from typing import Any
from torch import nn
from vllm.logger import init_logger
logger = init_logger(__name__)
_NONE = "none"
def _join(values: set[str]) -> str:
return ",".join(sorted(values)) if values else _NONE
def _enum_name(value: Any) -> str:
if value is None:
return _NONE
return str(getattr(value, "name", value))
def _ple_embeddings(model: nn.Module | None) -> list[nn.Module]:
"""The ``ple_embedding`` module of every PLE layer in ``model``."""
if model is None:
return []
found = []
for module in model.modules():
embedding = module.__dict__.get("_modules", {}).get("ple_embedding")
if isinstance(embedding, nn.Module):
found.append(embedding)
return found
def _transport(embedding: nn.Module) -> str:
if getattr(embedding, "_is_cpu_offloaded", False):
if getattr(embedding, "_host_output_ptr", None) is not None:
return "host-mapped-pull"
return "ipc-push"
weight = getattr(getattr(embedding, "ngram_embedding", None), "weight", None)
if weight is not None:
return f"local:{weight.device.type}"
return "local:unknown"
def _method(embedding: nn.Module) -> str:
table = getattr(embedding, "ngram_embedding", None)
method = getattr(table, "quant_method", None)
if method is None:
method = getattr(embedding, "_offload_quant_method", None)
return type(method).__name__ if method is not None else _NONE
def _weight_dtype(embedding: nn.Module) -> str:
weight = getattr(getattr(embedding, "ngram_embedding", None), "weight", None)
if weight is not None:
return str(weight.dtype)
if getattr(embedding, "_is_cpu_offloaded", False):
buffer = getattr(embedding, "_gpu_output_buffer", None)
if buffer is not None:
return str(buffer.dtype)
return "unknown"
def _rank_tag() -> str:
from vllm.distributed.parallel_state import get_pp_group, get_tp_group
return f"PP{get_pp_group().rank_in_group}_TP{get_tp_group().rank_in_group}"
def _draft(model_runner: Any) -> tuple[nn.Module | None, Any]:
"""The loaded draft model and its config (V2 speculator or V1 drafter)."""
for name in ("speculator", "drafter"):
holder = getattr(model_runner, name, None)
model = getattr(holder, "model", None)
if isinstance(model, nn.Module):
return model, getattr(holder, "vllm_config", None)
return None, None
def identity_line(
tag: str, model: nn.Module | None, vllm_config: Any, role: str
) -> str:
from vllm.compilation.breakable_cudagraph import is_breakable_cudagraph_enabled
embeddings = _ple_embeddings(model)
backends = {f"{type(e).__name__}@{_transport(e)}" for e in embeddings}
compilation = getattr(vllm_config, "compilation_config", None)
return (
f"e2-identity[{tag}]: "
f"ple_backend={_join(backends)} "
f"ple_method={_join({_method(e) for e in embeddings})} "
f"ple_weight_dtype={_join({_weight_dtype(e) for e in embeddings})} "
f"breakable={'ON' if is_breakable_cudagraph_enabled() else 'OFF'} "
f"compile_mode={_enum_name(getattr(compilation, 'mode', None))} "
f"cudagraph_mode={_enum_name(getattr(compilation, 'cudagraph_mode', None))} "
f"role={role}"
)
def log_launch_identity(model_runner: Any, vllm_config: Any) -> None:
"""Log the identity line(s) for this rank. Never raises."""
tag = "PP?_TP?"
try:
tag = _rank_tag()
roles = [("target", model_runner.get_model(), vllm_config)]
draft_model, draft_config = _draft(model_runner)
if draft_model is not None:
roles.append(("draft", draft_model, draft_config or vllm_config))
for role, model, config in roles:
logger.info("%s", identity_line(tag, model, config, role))
except Exception as error: # log-only: identity must never break a boot
logger.warning(
"e2-identity[%s]: unavailable (%s: %s)", tag, type(error).__name__, error
)