Official Inference Code of EAGLE-4
fix(sglang): keep the tree rule for chains narrower than 16 tokens
Seyfal Sultanov5686039fa070
diff --git a/eagle_harness/core/cost_model.py b/eagle_harness/core/cost_model.pyindex ad52142..8d26a1a 100644--- a/eagle_harness/core/cost_model.py+++ b/eagle_harness/core/cost_model.py@@ -502,8 +502,15 @@ class CostModel:@propertydef chain_rounds(self) -> bool:"""Rounds of a top-1 chain at chain intensity: sized by :meth:`chain_stop`, not the tree rule, and every- drafted token is verified."""- return self.intensity is ComputeIntensity.CHAIN and self.node_top_k == 1+ drafted token is verified.++ The chain rule prices the full 16-token chain (its cost index); a narrower chain keeps the tree rule.+ """+ return (+ self.intensity is ComputeIntensity.CHAIN+ and self.node_top_k == 1+ and self.verify_num == _CHAIN_COST_INDEX[-1] + 1+ )@propertydef verifies_whole_draft(self) -> bool:diff --git a/tests/test_drafter.py b/tests/test_drafter.pyindex ab9b48b..0e358bb 100644--- a/tests/test_drafter.py+++ b/tests/test_drafter.py@@ -249,6 +249,17 @@ def test_chain_rounds_verify_every_drafted_token():assert cost._history == history+def test_narrow_chains_keep_the_tree_rule():+ """The chain rule needs the 16-token chain's cost index; a width-8 chain (live costs index 0, 1, 3, 5, 7) keeps the+ tree rule instead of failing its first round."""+ cost = CostModel(+ tables={}, params=CostModelParams(), intensity=ComputeIntensity.CHAIN, node_top_k=1, tree_depth=7, verify_num=8+ )+ assert not cost.chain_rounds and not cost.verifies_whole_draft+ assert cost.launch_depths == (0, 2, 4)+ assert _ChainStopAt(stop=2).cost.chain_rounds++def test_tree_rounds_keep_the_tree_rule():cost = _cost()cost.tier.tiny = True