Skip to content

Official Inference Code of EAGLE-4

fix(vllm): log the harness through vLLM's logger as it is when a record is made

Seyfal Sultanov18c7940f47a7
diff --git a/eagle_harness/vllm/config.py b/eagle_harness/vllm/config.py
index bf107f4..adb4eed 100644
--- a/eagle_harness/vllm/config.py
+++ b/eagle_harness/vllm/config.py
@@ -38,12 +38,15 @@ Pure Python over ``core``: no GPU and no vLLM import at module load.
from __future__ import annotations
+import hashlib
import logging
+import os
from dataclasses import dataclass
from typing import Any, List, Literal, Mapping, Tuple
from eagle_harness.core.chain_width import (
PROFILE_FILE,
+ TREE_ROUNDS_FILE,
chain_widths,
load_tree_rounds,
merge_ranges,
@@ -297,7 +300,10 @@ def measured_tree_schedule(parsed: VllmMethodConfig, key: CostKey | None = None)
widths = served_tree_schedule(rounds, parsed.max_verify_width, limit)
if widths is None:
return None
- logger.info("eagle_harness: tree verify width per batch size from %s: %s", data_path, widths)
+ path = os.path.join(data_path, TREE_ROUNDS_FILE)
+ with open(path, "rb") as f:
+ digest = hashlib.sha256(f.read()).hexdigest()
+ logger.info("eagle_harness: tree verify width per batch size from %s (sha256 %s): %s", path, digest, widths)
return _draft_token_schedule(widths, limit)
diff --git a/eagle_harness/vllm/plugin.py b/eagle_harness/vllm/plugin.py
index b769d14..38aa6e9 100644
--- a/eagle_harness/vllm/plugin.py
+++ b/eagle_harness/vllm/plugin.py
@@ -76,12 +76,25 @@ def _async_scheduling_opt_in(spec_cls: type) -> dict:
return {}
+class _ThroughVllm(logging.Handler):
+ """Hands each package record to vLLM's ``vllm`` logger, judged by that logger's level and handlers as they are
+ when the record is made."""
+
+ def emit(self, record: logging.LogRecord) -> None:
+ engine = logging.getLogger("vllm")
+ if engine.isEnabledFor(record.levelno):
+ engine.handle(record)
+
+
def _log_through_vllm() -> None:
- """The package's loggers write where vLLM's do (vLLM configures only its own ``vllm`` logger, which does not
- propagate, so ``eagle_harness.*`` records were dropped in vLLM processes)."""
- ours, theirs = logging.getLogger("eagle_harness"), logging.getLogger("vllm")
- if theirs.handlers and not ours.handlers:
- for handler in theirs.handlers:
- ours.addHandler(handler)
- ours.setLevel(theirs.level)
- ours.propagate = False
+ """The package's loggers write where vLLM's do. vLLM configures only its own ``vllm`` logger, which does not
+ propagate, and its CLI loads plugins before it configures logging: handlers copied at registration would be none,
+ and the package's INFO records would stay below root's WARNING. So the records go to that logger when they are
+ made, and its level is the gate."""
+ ours = logging.getLogger("eagle_harness")
+ if ours.handlers: # bridged already, or configured by the user
+ return
+ ours.addHandler(_ThroughVllm())
+ if ours.level == logging.NOTSET:
+ ours.setLevel(logging.DEBUG)
+ ours.propagate = False
diff --git a/tests/test_sglang_plugin.py b/tests/test_sglang_plugin.py
index 5976d6c..d4822d0 100644
--- a/tests/test_sglang_plugin.py
+++ b/tests/test_sglang_plugin.py
@@ -202,6 +202,30 @@ def test_rocm_environment_is_logged_and_checked(registered, monkeypatch, caplog,
assert ("without SGLANG_USE_AITER=1" in logged) is warns
+def test_harness_info_reaches_sglangs_logging(monkeypatch):
+ """sglang configures the root logger (configure_logger) in every server process, and the package's loggers
+ propagate to it: the harness's INFO lines after that (cost profile, chain widths) reach sglang's handler."""
+ import io
+ import logging
+
+ from sglang.srt.utils.common import configure_logger
+
+ root, ours = logging.getLogger(), logging.getLogger("eagle_harness")
+ monkeypatch.setattr(root, "handlers", list(root.handlers))
+ monkeypatch.setattr(ours, "handlers", []) # an sglang process: nothing bridges the package elsewhere
+ monkeypatch.setattr(ours, "propagate", True)
+ level = root.level
+ try:
+ configure_logger(SimpleNamespace(log_level="info"))
+ (handler,) = root.handlers
+ stream = io.StringIO()
+ handler.setStream(stream)
+ logging.getLogger("eagle_harness.sglang.worker").info("EAGLE_HARNESS: chain widths per batch size probe")
+ finally:
+ root.setLevel(level)
+ assert "EAGLE_HARNESS: chain widths per batch size probe" in stream.getvalue()
+
+
def test_config_still_rejected_for_builtins(registered):
with pytest.raises(ValueError, match="algorithm-config"):
handle_speculative_decoding(_server_args(speculative_algorithm="EAGLE"))
diff --git a/tests/test_vllm_plugin.py b/tests/test_vllm_plugin.py
index 18e7440..f6000ab 100644
--- a/tests/test_vllm_plugin.py
+++ b/tests/test_vllm_plugin.py
@@ -492,22 +492,64 @@ def test_draft_aux_norms_run_on_the_kernel_ops(monkeypatch):
assert events == ["enter", "combine", "exit"]
-def test_package_logs_through_vllms_handler():
- import logging
-
- from eagle_harness.vllm.plugin import _log_through_vllm
-
- ours, theirs = logging.getLogger("eagle_harness"), logging.getLogger("vllm")
- saved = (list(ours.handlers), ours.level, ours.propagate, list(theirs.handlers))
- try:
- ours.handlers.clear()
- handler = logging.StreamHandler()
- theirs.addHandler(handler)
- _log_through_vllm()
- assert handler in ours.handlers and not ours.propagate
- finally:
- ours.handlers[:], ours.level, ours.propagate = saved[0], saved[1], saved[2]
- theirs.handlers[:] = saved[3]
+def unconfigured_vllm_logging(monkeypatch):
+ """Logging as vLLM's CLI has it when it loads plugins (parser setup): nothing configured. Restores the loggers
+ vLLM's configuration replaces."""
+ import vllm.logger as vllm_logger
+
+ loggers = [logging.getLogger(name) for name in ("eagle_harness", "vllm")]
+ saved = [(logger.level, logger.propagate) for logger in loggers]
+ for logger in loggers:
+ monkeypatch.setattr(logger, "handlers", [])
+ logger.setLevel(logging.NOTSET)
+ logger.propagate = True
+ monkeypatch.setattr(vllm_logger, "_last_configured_logging_config", None)
+ factory = logging.getLogRecordFactory()
+ yield
+ logging.setLogRecordFactory(factory)
+ for logger, (level, propagate) in zip(loggers, saved):
+ logger.setLevel(level)
+ logger.propagate = propagate
+
+
+def test_tree_schedule_is_logged_through_vllm_logging_configured_after_plugin_load(unconfigured_vllm_logging, tmp_path):
+ """vLLM's CLI loads plugins while it builds its parser and configures logging only after parsing; the tree
+ schedule, resolved later, is logged at INFO through vLLM's handler with the rounds file's path, sha256 and widths."""
+ import hashlib
+ import io
+ import shutil
+ from importlib.resources import files
+
+ from vllm.logger import configure_logging_from_args
+
+ from eagle_harness.core.chain_width import TREE_ROUNDS_FILE
+ from eagle_harness.vllm.config import measured_tree_schedule
+
+ plugin._log_through_vllm() # load_general_plugins() during parser setup
+ configure_logging_from_args(SimpleNamespace()) # after parse_args()
+ (handler,) = logging.getLogger("vllm").handlers
+ stream = io.StringIO()
+ handler.setStream(stream)
+ rounds = tmp_path / TREE_ROUNDS_FILE
+ rounds.parent.mkdir()
+ shutil.copyfile(str(files("eagle_harness.core").joinpath("profiles/vllm-qwen38-tp4", TREE_ROUNDS_FILE)), rounds)
+ parsed = parse_method_config(
+ {"mode": "static", "node_top_k": 4, "tree_depth": 14, "max_verify_width": 16, "data_path": str(tmp_path)}
+ )
+ assert measured_tree_schedule(parsed) is not None
+ (line,) = [line for line in stream.getvalue().splitlines() if "tree verify width per batch size" in line]
+ assert " INFO " in line
+ assert str(rounds) in line and hashlib.sha256(rounds.read_bytes()).hexdigest() in line
+ assert "(1, 19, 16), (20, 512, 4)" in line # the packaged schedule: 16 wide below batch 20, 4 from there
+
+
+def test_bridge_keeps_a_users_own_logging(unconfigured_vllm_logging):
+ ours = logging.getLogger("eagle_harness")
+ own = logging.NullHandler()
+ ours.addHandler(own)
+ plugin._log_through_vllm()
+ assert ours.handlers == [own] and ours.propagate
# A reduced-size Nemotron EAGLE-4 draft configuration with the same layer structures.