Skip to navigation
DevelopmentAPI ReferenceFull Library ReferenceNemo AutomodelNemo AutomodelComponentsSpeculativeEaglenemo_automodel.components.speculative.eagle.parallel_reconsideration

nemo_automodel.components.speculative.eagle.parallel_reconsideration

View as MarkdownOpen in Claude

Native EAGLE-3.1 Parallel Reconsideration training (arXiv:2611.05724v1).

Module Contents

Classes

NameDescription
LlamaParallelReconsiderationDraftModelThe EAGLE-3.1 layer and LM head with a feature query and a shared halt gate.
ParallelReconsiderationConfigTraining options for the paper’s Eq. (6).
ParallelReconsiderationTrainerModuleTrain two feature rollouts over the same recorded token sequence.
ReconsiderationKVRotated keys and values of shape [batch, heads, origin, head_dim].
ReconsiderationStepOne pass’s features [batch, origin, hidden] and uncommitted KV.

Functions

NameDescription
_ceCompute the hard target loss for each origin.
_select_haltSelect the same depth for the feature and its cache.
halt_probabilitiesApply the shared gate’s stick-breaking distribution.
reconsideration_token_lossApply Eq. (6)‘s token terms with separate gate and CE gradients.

API

class nemo_automodel.components.speculative.eagle.parallel_reconsideration.LlamaParallelReconsiderationDraftModel(
config: transformers.PretrainedConfig
)

Bases: LlamaEagle3DraftModel

The EAGLE-3.1 layer and LM head with a feature query and a shared halt gate.

halt_gate
= nn.Linear(config.hidden_size, 1)
self_query
= nn.Linear(config.hidden_size, config.hidden_size)
nemo_automodel.components.speculative.eagle.parallel_reconsideration.LlamaParallelReconsiderationDraftModel.draft_step(
input_embeds: torch.Tensor,
hidden: torch.Tensor,
mask: torch.Tensor,
positions: torch.Tensor,

Run the shared M with explicit positions and a branch-owned cache.

Parameters:

input_embeds
Tensor

Token embeddings or self-queries of shape [batch, origin, hidden].

hidden
Tensor

Features of shape [batch, origin, hidden].

mask
Tensor

Additive base attention mask of shape [batch, 1, origin, origin].

positions
Tensor

Absolute RoPE indices of shape [batch, origin].

prefix
tuple[ReconsiderationKV, ...]Defaults to ()

Base keys/values followed by one diagonal block per prior speculative position. Blocks have shape [batch, heads, origin, head_dim].

Returns: ReconsiderationStep

Updated features [batch, origin, hidden] and this pass’s key/value

class nemo_automodel.components.speculative.eagle.parallel_reconsideration.ParallelReconsiderationConfig(
max_reconsiderations: int = 2,
balance_beta: float = 0.01
)
Dataclass

Training options for the paper’s Eq. (6).

balance_beta
float = 0.01

Coefficient for entropy of the minibatch halt marginal.

max_reconsiderations
int = 2

Positive cap on additional passes at a position.

nemo_automodel.components.speculative.eagle.parallel_reconsideration.ParallelReconsiderationConfig.__post_init__() -> None
nemo_automodel.components.speculative.eagle.parallel_reconsideration.ParallelReconsiderationConfig.build(
selected_token_ids: torch.Tensor,
selected_token_mask: torch.Tensor,
ttt_steps: int

Build the trainer with the configured reconsideration loss.

Parameters:

draft_model
LlamaParallelReconsiderationDraftModel

Draft that owns the shared decoder, query, and gate.

selected_token_ids
Tensor

Target token IDs of shape [draft_vocab] in draft order.

selected_token_mask
Tensor

Eligibility mask of shape [target_vocab].

ttt_steps
int

Maximum rollout length in positions.

Returns: ParallelReconsiderationTrainerModule

The trainer with its own target-vocabulary mapping buffers.

class nemo_automodel.components.speculative.eagle.parallel_reconsideration.ParallelReconsiderationTrainerModule(
selected_token_ids: torch.Tensor,
selected_token_mask: torch.Tensor,
ttt_steps: int
)

Bases: Module

Train two feature rollouts over the same recorded token sequence.

nemo_automodel.components.speculative.eagle.parallel_reconsideration.ParallelReconsiderationTrainerModule._teacher_labels(
loss_mask: torch.Tensor,
target_logits: torch.Tensor | None,
target_probs: torch.Tensor | None,
position_mask: torch.Tensor | None
) -> tuple[torch.Tensor, torch.Tensor]

Resolve hard teacher labels in the aligned EAGLE frame.

Parameters:

loss_mask
Tensor

Eligible teacher rows of shape [batch, origin].

target_logits
Tensor | None

Live logits of shape [batch, origin, target_vocab].

target_probs
Tensor | None

Cached probabilities of shape [batch, origin, draft_vocab].

position_mask
Tensor | None

Cache eligibility of shape [batch, origin, 1].

Returns: tuple[Tensor, Tensor]

Draft IDs and a boolean eligibility mask, each of shape [batch, origin].

nemo_automodel.components.speculative.eagle.parallel_reconsideration.ParallelReconsiderationTrainerModule.forward(
input_ids: torch.Tensor,
attention_mask: torch.Tensor,
loss_mask: torch.Tensor,
aux_hidden_states: torch.Tensor,
target_logits: torch.Tensor | None = None,
target_probs: torch.Tensor | None = None,
position_mask: torch.Tensor | None = None,
position_ids: torch.Tensor | None = None,
seq_lens: torch.Tensor | None = None,
doc_remaining: torch.Tensor | None = None

Compute the native trainer’s loss and one-pass metrics.

Parameters:

input_ids
Tensor

EAGLE-shifted recorded token IDs [batch, origin], shared by both rollouts.

attention_mask
Tensor

Original real-token mask [batch, origin].

loss_mask
Tensor

Aligned teacher supervision mask [batch, origin].

aux_hidden_states
Tensor

Target taps [batch, origin, concatenated_hidden].

target_logits
Tensor | NoneDefaults to None

Aligned live teacher logits [batch, origin, target_vocab].

target_probs
Tensor | NoneDefaults to None

Aligned cached probabilities [batch, origin, draft_vocab].

position_mask
Tensor | NoneDefaults to None

Cached supervision eligibility [batch, origin, 1].

position_ids
Tensor | NoneDefaults to None

Optional original RoPE indices [batch, origin].

seq_lens
Tensor | NoneDefaults to None

Packed document lengths [num_documents]. Must be absent.

doc_remaining
Tensor | NoneDefaults to None

Packed positions remaining [batch, origin]. Must be absent.

Returns: Eagle3StepMetrics

Scalar loss, accuracy and supervised-token count in the recipe’s metric record.

class nemo_automodel.components.speculative.eagle.parallel_reconsideration.ReconsiderationKV(
key: torch.Tensor,
value: torch.Tensor
)
Dataclass

Rotated keys and values of shape [batch, heads, origin, head_dim].

key
Tensor
value
Tensor
class nemo_automodel.components.speculative.eagle.parallel_reconsideration.ReconsiderationStep(
hidden: torch.Tensor,
)
Dataclass

One pass’s features [batch, origin, hidden] and uncommitted KV.

hidden
Tensor
kv
ReconsiderationKV
nemo_automodel.components.speculative.eagle.parallel_reconsideration._ce(
logits: torch.Tensor,
labels: torch.Tensor
) -> torch.Tensor

Compute the hard target loss for each origin.

Parameters:

logits
Tensor

Tensor of shape [batch, origin, draft_vocab].

labels
Tensor

Integer draft IDs of shape [batch, origin].

Returns: Tensor

FP32 cross entropy of shape [batch, origin].

nemo_automodel.components.speculative.eagle.parallel_reconsideration._select_halt(
depth: torch.Tensor

Select the same depth for the feature and its cache.

Parameters:

levels
list[ReconsiderationStep]

Candidate features [batch, origin, hidden] with projected keys and values [batch, heads, origin, head_dim], ordered by depth.

depth
Tensor

Sampled depth indices of shape [batch, origin].

Returns: ReconsiderationStep

A gathered feature and KV block with the same layouts as a single level.

nemo_automodel.components.speculative.eagle.parallel_reconsideration.halt_probabilities(
logits: torch.Tensor
) -> torch.Tensor

Apply the shared gate’s stick-breaking distribution.

Parameters:

logits
Tensor

Tensor of shape […, depth_cap] with one logit per optional halt.

Returns: Tensor

FP32 halt masses of shape […, depth_cap + 1], including forced halt.

nemo_automodel.components.speculative.eagle.parallel_reconsideration.reconsideration_token_loss(
ce: torch.Tensor,
mass: torch.Tensor
) -> torch.Tensor

Apply Eq. (6)‘s token terms with separate gate and CE gradients.

Parameters:

ce
Tensor

Cross entropy of shape […, depth], with depth zero first.

mass
Tensor

Halt probabilities of shape […, depth].

Returns: Tensor

Combined loss of shape […] before the marginal entropy term.