mstar.streaming.chunk_policy#
Classes
Determines when a StreamBuffer has enough items for the consumer node. |
|
|
Release non-overlapping chunks of fixed size. |
|
Chunk policy for streaming vocoders with left-context overlap. |
|
A smaller first chunk, then chunks that grow geometrically up to a cap. |
|
Left-context chunking whose chunk sizes follow a ramp. |
|
Fixed-size sliding window that advances by a stride. |
- class mstar.streaming.chunk_policy.ChunkPolicy[source]#
Bases:
ABCDetermines when a StreamBuffer has enough items for the consumer node.
- continue_after_producer_done()[source]#
Whether the buffer should keep producing (empty) chunks after the producer signals done and all buffered items have been consumed.
Default
False: partition-done is propagated to the conductor after the last item is flushed.Set to
Truefor connections where the consumer must keep running after the producer finishes (e.g., Thinker→Talker: the Talker continues generating codec tokens after the Thinker hits text EOS). In this case the buffer produces empty chunks (_collate([])→{"data": None}), and the consumer’s partition-done is determined by its own model logic, not by the StreamBuffer.- Return type:
- continues_in(consumer_walk)[source]#
Whether empty chunks keep coming, after the producer is done, while the consumer is in
consumer_walk.
- abstractmethod is_ready(buffer_len)[source]#
Return True if the buffer has enough items for a chunk.
- abstractmethod next_chunk_size(buffer_len)[source]#
Return the number of items to consume for the next chunk.
Only called when is_ready() returns True. For sliding-window policies this is the stride, not the window.
- class mstar.streaming.chunk_policy.FixedChunkPolicy(chunk_size, continue_after_done=False)[source]#
Bases:
ChunkPolicyRelease non-overlapping chunks of fixed size.
Each pop_chunk returns exactly chunk_size items and advances by chunk_size. No overlap, no sliding window.
- Parameters:
chunk_size (int) – number of items per chunk.
continue_after_done (bool | frozenset[str]) – if True, keep producing empty chunks after the producer finishes and all buffered items are consumed. A set of consumer walks does so only while the consumer is in one of them; in its other walks the stream just waits.
- continue_after_producer_done()[source]#
Whether the buffer should keep producing (empty) chunks after the producer signals done and all buffered items have been consumed.
Default
False: partition-done is propagated to the conductor after the last item is flushed.Set to
Truefor connections where the consumer must keep running after the producer finishes (e.g., Thinker→Talker: the Talker continues generating codec tokens after the Thinker hits text EOS). In this case the buffer produces empty chunks (_collate([])→{"data": None}), and the consumer’s partition-done is determined by its own model logic, not by the StreamBuffer.- Return type:
- continues_in(consumer_walk)[source]#
Whether empty chunks keep coming, after the producer is done, while the consumer is in
consumer_walk.
- class mstar.streaming.chunk_policy.LeftContextChunkPolicy(chunk, left_context)[source]#
Bases:
ChunkPolicyChunk policy for streaming vocoders with left-context overlap.
Matches HuggingFace’s
Qwen3OmniMoeCode2Wav.chunked_decodepattern:Iter 0: codes[0 : chunk] → emit all (no context) Iter 1: codes[chunk-ctx : 2*chunk] → trim first ctx, emit rest Iter 2: codes[2*chunk-ctx : 3*chunk] → trim first ctx, emit rest
The first pop returns
chunkitems (no context). Subsequent pops returnchunk + left_contextitems, where the leadingleft_contextitems OVERLAP with the tail of the previous chunk. This overlap allows the causal ConvNet vocoder to “warm up” its internal state on frames it has already processed, ensuring a smooth transition at chunk boundaries.The key invariant: the first pop advances by
chunk - left_context(notchunk), so the lastleft_contextitems of the first chunk remain in the buffer as overlap for the second pop. All subsequent pops advance bychunk.
- class mstar.streaming.chunk_policy.RampChunkPolicy(first_chunk, chunk_size, continue_after_done=False, growth=1.0, max_chunk=None)[source]#
Bases:
ChunkPolicyA smaller first chunk, then chunks that grow geometrically up to a cap.
A streaming consumer that re-runs over the whole accumulated stream on every chunk (a flow-matching mel decoder conditioned on all tokens so far) wants its first chunk as early as the model allows, for time-to-first-audio, and later chunks sized for throughput.
first_chunkitems release the first chunk; the next ischunk_sizeitems and every chunk after that isgrowthtimes the previous one, capped atmax_chunk(growth=1keeps them fixed). Growing chunks track the listener’s playback buffer: each chunk buys the time to produce a bigger one, so fewer, larger solves carry the same stream. No overlap: the consumer keeps its own history.continue_after_donebehaves as inFixedChunkPolicy.- Parameters:
- continue_after_producer_done()[source]#
Whether the buffer should keep producing (empty) chunks after the producer signals done and all buffered items have been consumed.
Default
False: partition-done is propagated to the conductor after the last item is flushed.Set to
Truefor connections where the consumer must keep running after the producer finishes (e.g., Thinker→Talker: the Talker continues generating codec tokens after the Thinker hits text EOS). In this case the buffer produces empty chunks (_collate([])→{"data": None}), and the consumer’s partition-done is determined by its own model logic, not by the StreamBuffer.- Return type:
- class mstar.streaming.chunk_policy.ScheduledLeftContextChunkPolicy(schedule, chunk, left_context)[source]#
Bases:
ChunkPolicyLeft-context chunking whose chunk sizes follow a ramp.
Streaming vocoders want the first audio out as early as possible and larger chunks once the stream is running. Chunk
kdeliversschedule[k]new items (chunkonce the schedule is exhausted) with up toleft_contextalready-delivered items in front of them, so a causal decoder can warm up on frames it has processed before. UnlikeLeftContextChunkPolicythe first chunk may be smaller than the context: the context is whatever has been delivered so far, capped.Example (Qwen3-TTS, 12 Hz frames):
schedule=(4, 8, 16),chunk=25,left_context=25pops windows of 4, 4+8, 12+16, 25+25, 25+25, … items and the first audio leaves after four frames instead of 300.The consumer learns how many leading items of a window are context from
StreamChunk.context_items(the worker passes it along asinput_metadata.stream_chunks[edge].context_items), so it can trim the duplicated output without re-deriving this schedule.- next_chunk_size(buffer_len)[source]#
Return the number of items to consume for the next chunk.
Only called when is_ready() returns True. For sliding-window policies this is the stride, not the window.
- class mstar.streaming.chunk_policy.SlidingWindowChunkPolicy(window, stride)[source]#
Bases:
ChunkPolicyFixed-size sliding window that advances by a stride.
Each pop_chunk returns window items and advances the consumed pointer by stride. Old items before the window are discarded.
Example (Orpheus SNAC): window=28 tokens (4 frames), stride=7 (1 frame).