nemo_automodel.components.speculative.eagle.eagle4
nemo_automodel.components.speculative.eagle.eagle4
EAGLE-4 draft training on top of the EAGLE-3 recipe.
An EAGLE-4 draft is the EAGLE-3.1 Llama-style draft with a sliding-window
draft layer and a low-rank candidate head (see draft_llama.py). It trains
in two stages, both run by TrainEagle3Recipe:
- Draft stage (
recipe_args.eagle4.sliding_windowonly): the usual EAGLE-3 TTT loss over the full target vocabulary, with the windowed layer. - Candidate-head stage (
recipe_args.eagle4.candidate_headset anddraft_weights_pathpointing at the stage-1 export): every stage-1 parameter is frozen and only the two rank-rfactors train, initialized from the truncated SVD of the draftlm_head.Eagle4CandidateHeadTrainerModuleruns the frozen draft’s TTT unroll and minimizes, at every depth, the forward KL from the full head’s softmax to the low-rank head’s softmax. The low-rank head only has to retrieve the full head’s likely tokens (serving rescores the retrieved candidates exactly), and forward KL weights each token by the full head’s probability, so the limited rank goes to the tokens that matter. The loggedaccuracyis candidate recall: how often the full head’s top-1 token is among the low-rank head’s topnum_candidates.
python -m nemo_automodel.components.speculative.eagle.export_eagle4 turns
the stage-2 checkpoint into the LlamaForCausalLMEagle4 layout the serving
engines load.
Module Contents
Classes
Data
API
Shape of the EAGLE-4 low-rank candidate head.
Tokens K the serving engine keeps from the low-rank
scores and rescores with the full lm_head; also the K of the
logged candidate recall.
Rank r of the factorized vocabulary scores.
Build the stage-2 trainer that fits draft_model’s candidate head.
Bases: Module
Stage-2 trainer: fit the low-rank candidate head of a frozen EAGLE-4 draft.
The draft’s TTT unroll (same recurrence, input shift and packing gates as
Eagle3TrainerModule) runs without gradients; at each depth the full
lm_head softmax is the teacher and the low-rank scores the student.
Depth i is weighted by 0.8 ** i and the sum normalized by the total
weight, as in the draft stage.
Like every EAGLE-3-recipe trainer it carries the draft-vocab mapping buffers
(selected_token_ids / selected_token_mask) that the recipe saves to and
restores from the checkpoint metadata; an EAGLE-4 draft uses the full vocabulary.
Run the candidate-head loss for one batch.
Accepts the same inputs as Eagle3TrainerModule.forward so every
target backend can feed it. The target supervision (target_logits,
or target_probs / position_mask from the offline cache) is not
used: the teacher is the draft’s own full head, and loss_mask
selects the supervised positions.
Parameters:
Tensor of shape [batch, sequence], token ids.
Tensor of shape [batch, sequence], right-padded
1 / 0 validity mask.
Tensor of shape [batch, sequence], 1 where the
draft is supervised.
Tensor of shape [batch, sequence, 3 * target_hidden],
the concatenated target hidden states the draft projects.
Unused; tensor of shape [batch, sequence, vocab].
Unused; tensor of shape [batch, sequence, vocab].
Unused; tensor of shape [batch, sequence, 1].
Optional tensor of shape [batch, sequence] with
per-document positions (packing).
Optional tensor of shape [batch, max_docs] with packed
document lengths, 0-padded.
Optional tensor of shape [batch, sequence]: tokens
left in each slot’s document; depth i is supervised only
while i < doc_remaining.
Returns: Eagle3StepMetrics
Eagle3StepMetrics with the weighted forward KL (0 for a perfect head), accuracy set to the
recipe_args.eagle4: turns the EAGLE-3 recipe’s draft into an EAGLE-4 draft.
Set for the candidate-head stage; None trains the
draft itself.
Keys each draft query attends to, itself and its TTT
chain included (so at least ttt_steps), or None for full
causal attention.
Return the draft config.json keys that define this EAGLE-4 draft.
Parameters:
The three target layers whose outputs feed the draft,
recorded as eagle_config.eagle_aux_hidden_state_layer_ids so
the serving engine captures the same layers.