nemo_automodel.components.speculative.streaming.producer
nemo_automodel.components.speculative.streaming.producer
Streaming producer for speculative-decoding draft training.
The :class:FeatureProducer wraps a single target-backend forward pass
and ships its output through a :class:FeatureStore. The trainer-side
:class:~nemo_automodel.components.speculative.streaming.loader.FeatureDataLoader
re-materializes the same data as an
:class:~nemo_automodel.components.speculative.eagle.target.Eagle3TargetBatch
and yields it to the trainer loop.
The first producer wraps the existing
:class:~nemo_automodel.components.speculative.eagle.target.HFEagle3TargetModel
so the colocated path’s numerical output travels bit-for-bit into the
streaming pipeline. Future producers (out-of-process SGLang, NCCL
remote) plug in behind the same FeatureProducer API without
touching the trainer.
Module Contents
Classes
Functions
Data
API
Run a target backend once and put the supervision into a :class:FeatureStore.
Thread safety: produce is not reentrant with itself on the same
producer instance; one thread should drive produce at a time.
Multiple producers over the same store are fine; the store’s lock
serializes the puts.
Parameters:
an object exposing generate_batch(input_ids, attention_mask, loss_mask, ...) -> Eagle3TargetBatch plus
the get_input_embeddings and set_vocab_mapping
accessors from
:class:~nemo_automodel.components.speculative.eagle.backend.Eagle3TargetBackend.
The :class:FeatureStore every produce call writes
into.
Stable across the whole training run; mirrored onto every
:class:SampleRef.
Forced :class:FeatureAlgorithm; defaults to picking
by the backend’s runtime type.
Monotonically increasing identifier of the
target-model weights; surfaced on each :class:SampleRef.
Same idea for the draft model’s weights.
Callable that produces the per-call sample id;
defaults to "sample-{run_id}-{n}". Wrap with a hash of
the input batch if you want stable ids across runs.
Release any backend resources; the producer itself holds none.
Evict a produced sample whose ref will not be enqueued.
Used when a produced ref is dropped before it reaches the queue: a
spec-mismatch abort in :meth:produce, or the async pipeline shutting
down while a blocking put is in flight. get + release drops the
last handle so the store frees the sample; without it the sample’s bytes
(or its shared-dir file) stay resident with no consumer able to release
them.
Parameters:
The reference whose backing sample should be evicted.
Expose the wrapped backend’s input-embedding module.
Mirrors :meth:Eagle3TargetBackend.get_input_embeddings so the
draft can seed its input embeddings from the target before the
first streamed batch arrives.
Run the wrapped backend once and stash its supervision into the store.
Parameters:
Tensor of shape [batch, sequence], torch.long.
Tensor of shape [batch, sequence], torch.long.
Tensor of shape [batch, sequence], torch.long.
Per-document position ids when packing is on;
None for non-packed. Carried through unchanged to
the :class:Eagle3TargetBatch so the trainer’s loss
path stays bit-identical to the colocated path.
Per-document sequence lengths when packing is on;
None for non-packed.
[batch, sequence] long tensor gating
cross-document TTT supervision when packing is on;
None otherwise.
Returns: SampleRef
class:SampleRef carrying a tensor-free description of
Raises:
MemoryError: forwarded from the store when the put would exceedmax_samplesormax_bytes. Producers can wait for the store to drain through the queue’s backpressure path (put_blocks_until_below).
Thread the draft-vocab mapping through to the wrapped backend.
The colocated backend ignores the mapping and projects the
full-vocab logits trainer-side; a future draft-vocab
encoding producer supplies the mapping here so the target can
precompute target_probs + position_mask and the wire
never carries a full-vocab tensor.
Pick the producer-side :class:FeatureAlgorithm for a backend.
Dispatch on the backend’s base class, not its class-name string: every
Eagle3 target variant (HF, runner, vLLM, SGLang, remote) subclasses
:class:Eagle3TargetBackend, so this survives renames, subclassing, and
wrapping. Adding a new algorithm is a one-line isinstance branch here.