Add support for Eagle with separate lm-head and embed_tokens layers (#28549)

Signed-off-by: Eldar Kurtic <8884008+eldarkurtic@users.noreply.github.com>
This commit is contained in:
Eldar Kurtić
2025-11-15 15:12:02 +01:00
committed by GitHub
parent 085a525332
commit e439c784fa
12 changed files with 205 additions and 64 deletions

View File

@@ -932,13 +932,73 @@ def supports_transcription(
@runtime_checkable
class SupportsEagle3(Protocol):
class SupportsEagleBase(Protocol):
"""Base interface for models that support EAGLE-based speculative decoding."""
has_own_lm_head: bool = False
"""
A flag that indicates this model has trained its own lm_head.
"""
has_own_embed_tokens: bool = False
"""
A flag that indicates this model has trained its own input embeddings.
"""
@overload
def supports_any_eagle(model: type[object]) -> TypeIs[type[SupportsEagleBase]]: ...
@overload
def supports_any_eagle(model: object) -> TypeIs[SupportsEagleBase]: ...
def supports_any_eagle(
model: type[object] | object,
) -> TypeIs[type[SupportsEagleBase]] | TypeIs[SupportsEagleBase]:
"""Check if model supports any EAGLE variant (1, 2, or 3)."""
return supports_eagle(model) or supports_eagle3(model)
@runtime_checkable
class SupportsEagle(SupportsEagleBase, Protocol):
"""The interface required for models that support
EAGLE3 speculative decoding."""
EAGLE-1 and EAGLE-2 speculative decoding."""
supports_eagle: ClassVar[Literal[True]] = True
"""
A flag that indicates this model supports EAGLE-1 and EAGLE-2
speculative decoding.
Note:
There is no need to redefine this flag if this class is in the
MRO of your model class.
"""
@overload
def supports_eagle(model: type[object]) -> TypeIs[type[SupportsEagle]]: ...
@overload
def supports_eagle(model: object) -> TypeIs[SupportsEagle]: ...
def supports_eagle(
model: type[object] | object,
) -> TypeIs[type[SupportsEagle]] | TypeIs[SupportsEagle]:
return isinstance(model, SupportsEagle)
@runtime_checkable
class SupportsEagle3(SupportsEagleBase, Protocol):
"""The interface required for models that support
EAGLE-3 speculative decoding."""
supports_eagle3: ClassVar[Literal[True]] = True
"""
A flag that indicates this model supports EAGLE3
A flag that indicates this model supports EAGLE-3
speculative decoding.
Note:
@@ -949,7 +1009,7 @@ class SupportsEagle3(Protocol):
def set_aux_hidden_state_layers(self, layers: tuple[int, ...]) -> None:
"""
Set which layers should output auxiliary
hidden states for EAGLE3.
hidden states for EAGLE-3.
Args:
layers: Tuple of layer indices that should output auxiliary
@@ -960,7 +1020,7 @@ class SupportsEagle3(Protocol):
def get_eagle3_aux_hidden_state_layers(self) -> tuple[int, ...]:
"""
Get the layer indices that should output auxiliary hidden states
for EAGLE3.
for EAGLE-3.
Returns:
Tuple of layer indices for auxiliary hidden state outputs.