nemo_automodel.components.datasets.llm.eagle3_cache
nemo_automodel.components.datasets.llm.eagle3_cache
On-disk format + reader for the EAGLE-3 offline target-output cache.
This is the SpecForge “offline” training data path: the frozen target model’s per-token supervision (auxiliary hidden states + the draft-vocab target distribution) is precomputed once and stored on disk, so draft training reads it back instead of re-running the (large, frozen) target every step.
It is extremely disk-intensive — on the order of tens of MB per sample for
an 8B target (aux_hidden_states is 3 * target_hidden_size wide), i.e.
multiple TB for a large dataset — and is largely superseded by online training,
where the target forward is cheap relative to the cache I/O. It is kept for
completeness / reproducibility of the SpecForge offline recipe; prefer the online
path unless you are re-training repeatedly on a fixed, bounded dataset.
This module owns the format (so the producer in
components/speculative/precompute_eagle3.py and the training-time reader
agree on one schema):
<cache_dir>/manifest.json— run config + theselected_token_idsused to build the draft vocabulary (the recipe reuses these instead of rescanning).<cache_dir>/shard-000000.safetensors— one shard holds a contiguous block of samples, each field stacked along dim 0:input_ids[n,S],attention_mask[n,S],loss_mask[n,S](int64),aux_hidden_states[n,S,3H](float),position_mask[n,S,1](bool), and the draft-vocab target distribution. The distribution is stored in full astarget_probs[n,S,draft_vocab](float) by default, or — when the manifest’starget_probs_topkenables it — as the top-k factorizationtarget_probs_values[n,S,k](float) +target_probs_indices[n,S,k](int32), which the reader scatters back to full width. Top-k bounds the dominant field’s footprint at the cost of the dropped tail mass (a disk/fidelity trade-off, off by default; seeprecompute_eagle3).
Each CachedEagle3Dataset item is exactly the keyword arguments
Eagle3TrainerModule.forward consumes on its precomputed-distribution path
(target_probs always yielded at full width).
Module Contents
Classes
Functions
Data
API
Bases: CachedTensorDataset
Reads the EAGLE-3 offline cache; each item is one sample’s trainer inputs.
Shards are opened lazily with safetensors.safe_open (memory-mapped) and
sliced per sample, so the full cache is never loaded into memory at once.
Handles are reopened per worker after a DataLoader fork.
Stack per-sample cache dicts into a batch.
Build a dataloader over a precomputed EAGLE-3 cache directory.
Factor a draft-vocab distribution into its top-topk (values, indices).
target_probs is [..., draft_vocab]. The kept values are renormalized to
sum to 1 so the reconstructed distribution stays a proper distribution for soft
cross-entropy. The dropped tail mass is a disk/fidelity trade-off that grows with
how diffuse the target is (it is not negligible for a real LLM: top-64 of a
Qwen3-8B next-token distribution keeps only ~0.92 of the mass), so callers choose
topk deliberately; see precompute_eagle3. topk is clamped to the vocab
width.
Return EAGLE-3 shard indices already present in cache_dir.
True when target_probs_topk actually compresses (a positive k below the vocab width).
Return the EAGLE-3 manifest path inside cache_dir.
Load the cache manifest, raising if it is missing or the wrong format version.
Load the target input-embedding table written by write_target_embeddings.
Scatter stored top-k (values, indices) back into a full [..., draft_vocab] distribution.
Persist the cache manifest atomically (.tmp + os.replace).
Write one shard atomically.
samples carries the _COMMON_KEYS plus exactly one target_probs
representation: the full target_probs (lossless) or the top-k pair
target_probs_values + target_probs_indices.
Persist the target input-embedding table the draft initializes from.
The offline training path never loads the target model, but the draft’s
embed_tokens must still be seeded from the target’s embeddings (EAGLE-3
concatenates token embeddings with the carried hidden state), so the
producer stores them once alongside the cache.