Official Inference Code of EAGLE-4
vllm: follow the final review-PR hook surface, keep the 0.1.0 engine
Seyfal Sultanov3ba24b61c537
diff --git a/eagle_harness/vllm/adapter.py b/eagle_harness/vllm/adapter.pyindex b229df5..330b94a 100644--- a/eagle_harness/vllm/adapter.py+++ b/eagle_harness/vllm/adapter.py@@ -13,15 +13,34 @@ jobs only), ``none`` (vLLM offers no hook; see VLLM_HOOKS.md open questions).from __future__ import annotationsimport importlib+from types import ModuleTypefrom typing import NamedTuple, Tupleclass HookUse(NamedTuple):need: str # EngineAdapter method or engine-facing need- hook: str # "module:attribute[.attribute]" in vLLM, or "" when vLLM has none+ hook: str # "module:attribute[.attribute]" in vLLM (" | " between alternatives), or "" when vLLM has nonestatus: str+# Where vLLM keeps ``LinearAttnVerifyExtension``: upstream review head first, then the 0.1.0 release engine.+VERIFY_EXTENSION_MODULES = (+ "vllm.model_executor.layers.mamba.verify_extension",+ "vllm.model_executor.layers.mamba.gdn.verify_extension",+)+++def verify_extension_module() -> ModuleType:+ """The module of the running vLLM that defines ``LinearAttnVerifyExtension`` and its row types."""+ for name in VERIFY_EXTENSION_MODULES:+ try:+ return importlib.import_module(name)+ except ModuleNotFoundError as e:+ if e.name != name: # a missing parent (no vLLM at all) is not a different layout+ raise+ raise ModuleNotFoundError(f"vLLM has none of {VERIFY_EXTENSION_MODULES}", name=VERIFY_EXTENSION_MODULES[0])++HOOK_MAP: Tuple[HookUse, ...] = (HookUse("algorithm registration", "vllm.v1.spec_decode.registry:register_speculative_method", "cpu"),HookUse("H11 opaque algorithm config", "vllm.config.speculative:SpeculativeConfig.method_config", "cpu"),@@ -55,7 +74,7 @@ HOOK_MAP: Tuple[HookUse, ...] = (),HookUse("H10 GDN tree verify of the spec-decode rows",- "vllm.model_executor.layers.mamba.gdn.verify_extension:LinearAttnVerifyExtension.forward_spec_rows",+ " | ".join(f"{m}:LinearAttnVerifyExtension.forward_spec_rows" for m in VERIFY_EXTENSION_MODULES),"gpu",),HookUse(@@ -77,6 +96,10 @@ def missing_hooks() -> list[str]:def _exists(path: str) -> bool:+ return any(_exists_one(alternative.strip()) for alternative in path.split("|"))+++def _exists_one(path: str) -> bool:module_name, _, attr_path = path.partition(":")try:obj = importlib.import_module(module_name)diff --git a/eagle_harness/vllm/gdn_tree_verify.py b/eagle_harness/vllm/gdn_tree_verify.pyindex 69c9977..591ce67 100644--- a/eagle_harness/vllm/gdn_tree_verify.py+++ b/eagle_harness/vllm/gdn_tree_verify.py@@ -35,15 +35,18 @@ import torchimport tritonimport triton.language as tl-from vllm.model_executor.layers.mamba.gdn.verify_extension import GDNSpecRows, LinearAttnVerifyExtension-+from eagle_harness.vllm.adapter import verify_extension_modulefrom eagle_harness.kernels.gdn_tree_conv import gdn_tree_conv1d_updatefrom eagle_harness.kernels.gdn_tree_recurrence import gdn_tree_recurrent_updatefrom eagle_harness.kernels.mamba2_tree import mamba2_tree_state_updatefrom eagle_harness.vllm.verify_layout import VerifyStage, get_stageif TYPE_CHECKING: # vLLM builds without the Mamba2 hook lack it; the speculator refuses Mamba2 targets there- from vllm.model_executor.layers.mamba.gdn.verify_extension import Mamba2SpecRows+ from vllm.model_executor.layers.mamba.verify_extension import Mamba2SpecRows++_verify_extension = verify_extension_module()+GDNSpecRows = _verify_extension.GDNSpecRows+LinearAttnVerifyExtension = _verify_extension.LinearAttnVerifyExtension# A padded request's state slot; the chain kernels skip it too.NULL_BLOCK_ID = tl.constexpr(0)diff --git a/eagle_harness/vllm/plugin.py b/eagle_harness/vllm/plugin.pyindex d5b5ff1..b769d14 100644--- a/eagle_harness/vllm/plugin.py+++ b/eagle_harness/vllm/plugin.py@@ -48,8 +48,8 @@ def register() -> bool:uses_target_hidden_states=True,uses_aux_hidden_states=True,num_lookahead_tokens=num_lookahead_tokens,- supports_async_scheduling=True, # a round is device-only: no host read between verify and the next draftslinear_attn_verify_extension=GDN_TREE_VERIFY,+ **_async_scheduling_opt_in(SpeculativeMethodSpec),),)@@ -67,6 +67,15 @@ def register() -> bool:return True+def _async_scheduling_opt_in(spec_cls: type) -> dict:+ """The 0.1.0 release engine runs a registered method with async scheduling only when the spec opts in; later+ engines dropped the field (async scheduling no longer depends on the method). A round is device-only: no host+ read between verify and the next drafts."""+ if "supports_async_scheduling" in getattr(spec_cls, "__dataclass_fields__", {}):+ return {"supports_async_scheduling": True}+ return {}++def _log_through_vllm() -> None:"""The package's loggers write where vLLM's do (vLLM configures only its own ``vllm`` logger, which does notpropagate, so ``eagle_harness.*`` records were dropped in vLLM processes)."""diff --git a/tests/test_gdn_tree_kernels.py b/tests/test_gdn_tree_kernels.pyindex 41c0d84..77a2ff6 100644--- a/tests/test_gdn_tree_kernels.py+++ b/tests/test_gdn_tree_kernels.py@@ -226,9 +226,7 @@ def test_spec_rows_read_the_packed_projection_in_place_and_write_the_layer_outpufrom types import SimpleNamespacepytest.importorskip("vllm")- from vllm.model_executor.layers.mamba.gdn.verify_extension import GDNSpecRows-- from eagle_harness.vllm.gdn_tree_verify import TreeVerify+ from eagle_harness.vllm.gdn_tree_verify import GDNSpecRows, TreeVerifyfrom eagle_harness.vllm.verify_layout import set_stagetorch.manual_seed(3)diff --git a/tests/test_vllm_plugin.py b/tests/test_vllm_plugin.pyindex 606574a..18e7440 100644--- a/tests/test_vllm_plugin.py+++ b/tests/test_vllm_plugin.py@@ -58,7 +58,8 @@ def test_register_adds_the_method(registered):assert registered.speculator_cls == "eagle_harness.vllm.speculator:HarnessSpeculator"assert registered.uses_target_hidden_states is Trueassert registered.uses_aux_hidden_states is True- assert registered.supports_async_scheduling is True+ if "supports_async_scheduling" in vllm_registry.SpeculativeMethodSpec.__dataclass_fields__: # 0.1.0 engine+ assert registered.supports_async_scheduling is Trueassert registered.configure is not Noneassert registered.num_lookahead_tokens is num_lookahead_tokensassert registered.linear_attn_verify_extension == "eagle_harness.vllm.gdn_tree_verify:create_extension"@@ -344,8 +345,8 @@ def test_lookahead_reaches_the_vllm_config(registered):assert VllmConfig.num_lookahead_tokens.fget(fake) == 96-def test_the_method_name_is_unknown_before_the_plugin_runs():- vllm_registry.unregister_speculative_method(METHOD_NAME)+def test_the_method_name_is_unknown_before_the_plugin_runs(monkeypatch):+ monkeypatch.delitem(vllm_registry._REGISTRY, METHOD_NAME, raising=False)with pytest.raises(ValueError, match="Unknown speculative method"):SpeculativeConfig(method=METHOD_NAME, method_config=STATIC)@@ -377,6 +378,40 @@ def test_register_refuses_a_vllm_without_a_mapped_hook(monkeypatch):assert "Fix: install vllm with the eagle-harness hooks" in message[email protected]("layout", [0, 1], ids=["review-head", "release-0.1.0"])+def test_verify_extension_module_follows_the_engine_layout(monkeypatch, layout):+ import types++ from eagle_harness.vllm import adapter++ present = types.ModuleType(adapter.VERIFY_EXTENSION_MODULES[layout])+ for i, name in enumerate(adapter.VERIFY_EXTENSION_MODULES):+ monkeypatch.setitem(sys.modules, name, present if i == layout else None) # None: import raises+ assert adapter.verify_extension_module() is present+++def test_verify_extension_hook_counts_either_layout(monkeypatch):+ from eagle_harness.vllm import adapter++ (hook,) = [use.hook for use in HOOK_MAP if "LinearAttnVerifyExtension" in use.hook]+ for layout in adapter.VERIFY_EXTENSION_MODULES:+ monkeypatch.setattr(adapter, "_exists_one", lambda path, layout=layout: path.startswith(layout + ":"))+ assert adapter._exists(hook)+ monkeypatch.setattr(adapter, "_exists_one", lambda path: False)+ assert not adapter._exists(hook)++[email protected]("has_field", [True, False], ids=["release-0.1.0", "review-head"])+def test_async_scheduling_opt_in_only_where_the_engine_has_the_field(has_field):+ import dataclasses++ fields = [("speculator_cls", str)] + ([("supports_async_scheduling", bool, False)] if has_field else [])+ spec_cls = dataclasses.make_dataclass("Spec", fields)+ opt_in = plugin._async_scheduling_opt_in(spec_cls)+ assert opt_in == ({"supports_async_scheduling": True} if has_field else {})+ spec_cls("x", **opt_in) # the engine's spec accepts what the plugin passes++def test_hook_map_statuses_are_known():assert {use.status for use in HOOK_MAP} == {"cpu", "gpu", "none"}assert all(not use.hook for use in HOOK_MAP if use.status == "none")@@ -396,10 +431,11 @@ def test_speculator_hooks_match_the_vllm_signatures(name):def test_gdn_extension_factory_follows_the_mode():- from vllm.model_executor.layers.mamba.gdn.verify_extension import LinearAttnVerifyExtension-+ from eagle_harness.vllm.adapter import verify_extension_modulefrom eagle_harness.vllm.gdn_tree_verify import TreeVerify, create_extension+ LinearAttnVerifyExtension = verify_extension_module().LinearAttnVerifyExtension+def config(method_config):return SimpleNamespace(speculative_config=SimpleNamespace(method_config=method_config))@@ -412,10 +448,9 @@ def test_tree_mode_refuses_linear_layers_the_extension_cannot_reach(monkeypatch)"""A Mamba2 layer reaches the tree verify only through vLLM's Mamba2 hook; without it (or for any other linearlayer) vLLM's kernels would verify every tree as a chain, so the speculator refuses the target."""from vllm.model_executor.layers.mamba.gdn.qwen_gdn_linear_attn import QwenGatedDeltaNetAttention- from vllm.model_executor.layers.mamba.gdn.verify_extension import LinearAttnVerifyExtensionfrom vllm.model_executor.layers.mamba.mamba_mixer2 import MambaMixer2- from eagle_harness.vllm.gdn_tree_verify import check_tree_verifiable+ from eagle_harness.vllm.gdn_tree_verify import LinearAttnVerifyExtension, check_tree_verifiablegdn, mamba2 = object.__new__(QwenGatedDeltaNetAttention), object.__new__(MambaMixer2)check_tree_verifiable([gdn, gdn])