nemo_automodel.components.speculative.dspark.common
nemo_automodel.components.speculative.dspark.common
Module Contents
Classes
Functions
Data
API
Bases: Module
Outputs for one DSpark training forward.
The sampler keeps anchors whose first draft target is enabled by
loss_mask. Later slots are supervised only while they remain inside
seq_len and form a contiguous enabled prefix. Dummy anchors can still
appear when a sample has too few valid anchors; they are masked out by
block_keep_mask and eval_mask.
Per-context-token document id [B, S] from packed seq_lens [B, max_docs].
Mirrors the doc_id construction in build_block_causal_additive_mask: a
token’s id is the number of document boundaries at or before its position, so
0-length padding entries never split a real document.
Position ids for the parallel draft blocks (base position + offset).
Without packing the anchor’s position equals its row index, so the block
positions are anchor + offset. Under packing context_position_ids
[B, S] holds per-document reset positions, so the block’s base position is
gathered from it at the anchor to keep the draft’s RoPE phase document-local.
Keep a RoPE module’s inv_freq buffers in fp32 after a dtype cast.
module.to(bfloat16) (the training build path) rounds the rotary
inv_freq buffers to bf16. The rounded frequencies dephase with absolute
position, so the train/inference RoPE diverges (worse with longer context)
and draft acceptance erodes, while the serving runtime keeps an fp32 RoPE
cache. A bf16 round-trip cannot be undone by upcasting, so recompute fresh
fp32 frequencies from a fresh rotary module built off the same config (the
same values HF derives on the fp32 paths) and copy them back in.
Works for both the single-buffer layout (inv_freq / original_inv_freq,
e.g. Qwen3) and the per-layer-type layout where each frequency buffer is named
<layer_type>_inv_freq (e.g. Gemma4). No-op when every frequency buffer is
already fp32 or on a meta device.