nemo_automodel.components.speculative.streaming.stores.local
nemo_automodel.components.speculative.streaming.stores.local
In-process feature store for the speculative-training stream.
The local store keeps tensors in a Python dict under the
:class:~nemo_automodel.components.speculative.streaming.refs.SampleRef.sample_id,
with a resident-byte counter so the queue can drive backpressure from the
same store it puts into. It is the build-and-test surface for the entire
streaming pipeline: enough to wire up a colocated producer and consumer
without a network, without a shared mount, and without GPUDirect.
Residency policy (RFC §“Open questions” Q2 answer: bytes as the hard
backstop, sample count as a soft cap). When the next put would exceed
either cap, :meth:put raises :class:MemoryError — the producer is then
expected to retry after the consumer drains below the low watermark.
Module Contents
Classes
Data
API
Bases: FeatureStore
In-process :class:FeatureStore implementation.
Thread safety: every public method holds a single :class:threading.Lock,
so concurrent puts and gets from the same Python process are safe. Async
/ cross-process safety is the queue’s responsibility and is out of scope
for PR 1.
Parameters:
Hard cap on simultaneously-stored samples. None means
unbounded sample count (still bounded by max_bytes).
Hard cap on resident bytes. None means unbounded
(still bounded by max_samples). At least one of
max_samples / max_bytes must be set, otherwise a
misconfigured store silently behaves as unbounded.
Threshold above which :attr:StoreHealth.high_watermark_hit
is True. The producer pauses here.
Threshold below which :attr:StoreHealth.low_watermark_hit
is True. The producer resumes here. Must be
strictly less than high_watermark_bytes; a hysteresis band
of zero flaps the producer on every step.
Materialize ref’s features on device and hand back a :class:StoreHandle.
Parameters:
The reference returned by :meth:put (typically via a
queue lease). ref.store_uri MUST equal this store’s
:attr:store_uri; a mismatch raises KeyError so a
consumer cannot accidentally materialize a foreign ref.
Optional target device. None returns each feature
on the device it was put on; a non-None value
materializes every feature on that device via
Tensor.to(device) (a no-op when already in place).
Returns: dict[str, torch.Tensor]
A (tensors, handle) pair. tensors is a
Raises:
KeyError: whenref.store_uridoes not match this store, or whenref.sample_idis no longer present (released or never put).RuntimeError: when the stored tensor’s shape or dtype differs from what the ref claims, or the store has been closed.
Store tensors under sample_id and return a tensor-free :class:SampleRef.
Parameters:
Stable identifier within run_id. Must be unique
in this store at put time; duplicates raise ValueError.
Feature-name to tensor mapping. The store detaches,
clones, and makes each tensor contiguous before stashing it,
so the producer may keep mutating its source tensors after
the put returns without disturbing what a later
:meth:get hands out. The shape and dtype of each tensor
are captured into the returned :class:SampleRef’s
feature_specs; the consumer uses those specs to
preallocate the receive buffer at :meth:get time, so
changing tensors[name].shape or dtype between put
and get without updating the ref will surface as a
RuntimeError on materialization.
Same value on every ref of one run; surfaces on the
:class:SampleRef.run_id so producers and consumers can
verify they are talking about the same run.
Which draft family produced this sample; gates the
:class:SampleRef required-features check.
Bumped whenever the producer’s feature set or
layout for algorithm changes incompatibly.
Monotonically increasing identifier of the target-model weights.
Same idea for the draft model’s weights.
Sum of attended tokens; used by the consumer for empty / short loss-mask neutralization.
Returns: SampleRef
A tensor-free :class:SampleRef carrying the per-feature
Raises:
MemoryError: if the put would exceedmax_samplesormax_bytes. The producer is expected to retry after the store drains below the low watermark (see :meth:health).RuntimeError: if the store has been closed.ValueError: on bad input (empty sample id, empty tensors map, duplicate sample id).