Add dflash_laguna EAGLE-3 speculator for Laguna - #1531
Open
pierre427 wants to merge 1 commit into
Open
Conversation
This was referenced Jul 22, 2026
Rebuilt on current main now that ml-explore#1334 provides the laguna model in-tree: the previously bundled laguna.py (+499) and its model tests are dropped — the speculator now sits directly on the upstream module. Contents: - models/dflash_laguna.py: EAGLE-3 style block speculator for poolside/Laguna-XS-2.1-DFlash. No embedding/lm_head of its own; fuse() combines target aux hidden states, draft_block() predicts a whole block in one forward, reusing the target Laguna's embedding and LM head. - tool_parsers/laguna.py + chat-template inference: Laguna's <tool_call>function-name / <arg_key>-<arg_value> dialect (checked before glm47, which shares <arg_key>). - utils: read group_size/num_bits from compressed-tensors config_groups for int pack-quantized checkpoints instead of assuming 4-bit/32; the nvfp4-pack-quantized branch and the legacy default are unchanged. Verified: real poolside/Laguna-XS-2.1-DFlash weights strict-load through sanitize (fused qkv split) and fuse()+draft_block() produce finite output; test_dflash_laguna exercises the draft path against the in-tree laguna target on a tiny config. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
pierre427
force-pushed
the
pr/dflash-laguna-speculator
branch
from
August 10, 2026 21:11
9c34785 to
988d949
Compare
Author
|
Rebuilt on current
Related: #1704 makes the in-tree laguna load the public target checkpoints this speculator pairs with (independent, not stacked). 🤖 Generated with Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
dflash_lagunaEAGLE-3 speculator for LagunaWhat this adds
mlx_lm/models/dflash_laguna.py— an EAGLE-3-style block speculator forLaguna-XS-2.1 (
poolside/Laguna-XS-2.1-DFlash). Unlike a standalone draft model,the DFlash speculator is target-coupled: it borrows the target Laguna model's
token embedding and LM head, and consumes fused auxiliary hidden states pulled
from selected target layers.
Mechanism (per block)
[anchor, MASK*(block_size-1)]and embed it via thetarget Laguna
embed_tokens.fuse = hidden_norm(fc(concat(aux_norm_j(aux_j)))).the fused target hidden states as extra K/V context
(
k/v = concat(proj(target_hidden), proj(block))), with per-head softplusoutput gating and causal masking within the block.
kpredictsthe token at
anchor + k(position0reproduces the anchor,1:are thespeculative tokens). Draft logits come from the target
lm_head.Because it is target-coupled,
Model.__call__deliberately raises — the model isdriven by the speculative-decoding loop that supplies the target embedding, aux
hidden states, and LM head, not as a standalone causal LM.
Loading / registration
No
utils.pychange is required:model_type: "dflash_laguna"auto-discoversmlx_lm/models/dflash_laguna.pyvia the existing filename-based loader. Asanitizehook splits a fusedqkv_projcheckpoint tensor intoq/k/v_proj.Compatibility with #1223's
laguna.pyVerified against the
laguna.pyin #1223 (not a fork copy). The speculator onlyrelies on interfaces that base provides:
LagunaModel.embed_tokens(nn.Embedding) — used to embed the mask block.Model.lm_head(nn.Linear) — used to produce draft logits.No extra hooks beyond these are needed; the fork's Laguna had no additional
surface the #1223 version lacks.
Test
tests/test_dflash_laguna.pybuilds a small Laguna target plus a small DFlashspeculator and exercises the real forward path:
[anchor, MASK*(block-1)]through the targetembed_tokens,fuse),draft_block) through the draft layers with thefused target hidden states injected as K/V context,
lm_head,as a standalone causal LM raises.
blackandisort --profile blackclean.