nemo_automodel.components.speculative.eagle.core_v12
nemo_automodel.components.speculative.eagle.core_v12
Core EAGLE-1 / EAGLE-2 draft-training logic.
Module Contents
Classes
API
Aggregated metrics from one EAGLE-1 / EAGLE-2 training step.
Bases: Module
Draft-side trainer for EAGLE-1 / EAGLE-2 hidden-state prediction.
Project predicted hidden states through the frozen target lm_head.
Run one EAGLE-1 / EAGLE-2 training step.
Per-token tensors are [B, T] (position_ids / doc_remaining
included) except the [B, T, H] hidden states and [B, T, V]
target_logits; seq_lens is [B, max_docs]. When packing is on,
position_ids / seq_lens make the draft block-causal and per-document,
and doc_remaining (real tokens after each slot within its document) gates
supervision: a document’s last real token (doc_remaining == 0) is dropped
because the wrapper’s global left-shift makes its target the next document’s
first token.
Train-only uniform noise added to the target features fed to the draft.
EAGLE’s reference implementation draws the perturbation as
(rand_like(x) - 0.5) * std * reference_seq_len / T, where T is the
effective (unpadded) sequence length of the batch. The half-width is therefore
std / 2 * reference_seq_len / T: it is calibrated at
reference_seq_len and shrinks as the sequence grows, so a longer
context is not perturbed proportionally harder. ViSpec inherits this
unchanged and enables it in both of its stages.
reference_seq_len=None drops the scaling and applies a fixed
U(-std/2, std/2) at every length. That is the EAGLE paper’s wording
(U(-0.1, 0.1), i.e. std=0.2) and what the EAGLE-1/2 recipe uses; it
is 8x the reference half-width once T reaches 4096, which is why the
ViSpec stages take the scaled form.
Return features perturbed by the uniform draw.
Parameters:
Tensor of shape [batch, sequence, hidden] containing target features handed to the draft.
Tensor of shape [batch, sequence]. Its longest unpadded row sets the scale, so padding does not shrink the perturbation.
Returns: torch.Tensor
Tensor of shape [batch, sequence, hidden]. This is a new tensor;
Build an unscaled U(-half_width, half_width) draw.
Return the symmetric noise half-width for a sequence of seq_len.