[Model Runner V2][Spec Decode] Handle tuple hidden states from MTP draft models (#46786)

This commit is contained in:
Chauncey
2026-06-27 18:38:07 -07:00
committed by GitHub
parent 798185d438
commit 11a12305c0
4 changed files with 85 additions and 22 deletions
@@ -60,16 +60,6 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
"""
return True
@property
def model_returns_tuple(self) -> bool:
"""
Whether the draft model's forward() returns a tuple.
True: returns (last_hidden_states, hidden_states) — Eagle, Gemma4 MTP.
False: returns a single tensor used for both — standard MTP (DeepSeek).
"""
return True
def init_cudagraph_manager(self, cudagraph_mode: CUDAGraphMode) -> None:
# Initialize cudagraph manager for draft prefill (draft position 0).
self.prefill_cudagraph_manager = PrefillSpeculatorCudaGraphManager(
@@ -328,7 +318,9 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
else:
# Eager (NONE): call the raw model directly.
ret_hidden_states = self.model(**model_inputs)
if self.model_returns_tuple:
# Some MTP models declare a single-tensor contract but return
# (logits_hidden, feedback_hidden) for final-norm correctness.
if isinstance(ret_hidden_states, tuple):
last_hidden_states, hidden_states = ret_hidden_states
else:
last_hidden_states = ret_hidden_states
@@ -30,13 +30,6 @@ class Gemma4Speculator(AutoRegressiveSpeculator):
# No new KV slots are written, so positions and seq_lens stay fixed.
return False
@property
def model_returns_tuple(self) -> bool:
# forward() returns (draft_hidden_states, backbone_hidden_states).
# The proposer uses draft_hidden_states for compute_logits and
# backbone_hidden_states for the hidden-state feedback buffer.
return True
def load_draft_model(
self,
target_model: nn.Module,
@@ -10,10 +10,6 @@ from vllm.v1.worker.gpu.spec_decode.eagle.utils import load_eagle_model
class MTPSpeculator(AutoRegressiveSpeculator):
@property
def model_returns_tuple(self) -> bool:
return False
def load_draft_model(
self,
target_model: nn.Module,