Repository navigation
NemotronLabs VoiceChat-11B PR 1: streaming consumers inside loops, stream-terminated partition end #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
NemotronLabs VoiceChat-11B PR 1: streaming consumers inside loops, stream-terminated partition end #336
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a12106d
graph: re-arm pure-streaming loop nodes on every iteration
merceod 9a8b40b
worker: find streaming consumers nested in loops; stop stream-termina…
merceod 4824083
test: loop re-arms a pure-streaming inner node each iteration
merceod c8e11dc
test: worker finds streaming consumers nested in loops
merceod 08c5617
conductor: end a stream-terminated partition on the worker's final-ch…
merceod 18a1adc
test: stream-terminated partitions end on the worker signal and propa…
merceod 0bd6f52
worker: leave a cancelled request out of its scheduled batch instead …
merceod 66163c9
test: a dropped request is left out of the batch, the others run
merceod 86d733f
Merge remote-tracking branch 'origin/main' into engine/streaming-loop…
NSagan271 1fa63e8
Fix bug that the pre-merge PR was trying to fix by skipping requests …
NSagan271 e1be906
check for missing uuids when building executing batch
NSagan271 8ed8fa8
Revert "Fix bug that the pre-merge PR was trying to fix by skipping r…
NSagan271 67b2ad3
Drop a stale reference in the missing-uuid backstop comment
NSagan271 ccf16e9
un-ingest returned streaming edges on cancelled speculation
NSagan271 845db0f
Merge remote-tracking branch 'origin/main' into engine/streaming-loop…
NSagan271 4798271
ruff
NSagan271 98fe080
_settle_speculation is now idempotent on worker
stephen-dwq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| """A stream-terminated partition ends on the worker's final-chunk signal. | ||
|
|
||
| The worker sets ``partition_done`` on the worker-graphs-done report of the pass | ||
| that consumed a stream's final chunk. The conductor must treat that as the | ||
| partition's ``request_done`` (so ``producer_done`` reaches its downstream | ||
| connections) even when the model reports the partition as not done: the model | ||
| only sees connection counters, and ``consumed_count`` counts chunks popped for | ||
| execution as reported by every colocated worker-graphs-done message, so a | ||
| counter-based end can fire while the partition's last step is still running. | ||
| """ | ||
| from dataclasses import dataclass, field | ||
|
|
||
| from mstar.conductor.conductor import Conductor, RequestData | ||
| from mstar.conductor.request_info import ( | ||
| CurrentForwardConductorMetadata, | ||
| PartitionDefinition, | ||
| PartitionState, | ||
| StreamingConnectionState, | ||
| ) | ||
| from mstar.model.base import ForwardPassArgs | ||
|
|
||
|
|
||
| class _StubModel: | ||
| """Never ends a partition on its own; records what it was asked.""" | ||
|
|
||
| def __init__(self): | ||
| self.calls = [] | ||
|
|
||
| def get_partition_forward_pass_args(self, partition_name, partition_metadata, persist_signals, | ||
| incoming_connections=None): | ||
| self.calls.append((partition_name, [c.edge_name for c in incoming_connections or []])) | ||
| return ForwardPassArgs(full_metadata=partition_metadata, inputs=[], unpersist_tensors=[], | ||
| request_done=False) | ||
|
|
||
|
|
||
| @dataclass | ||
| class _Recorder: | ||
| producer_done: list = field(default_factory=list) | ||
| partition_inputs: list = field(default_factory=list) | ||
|
|
||
|
|
||
| def _conductor(rid="r"): | ||
| c = object.__new__(Conductor) | ||
| c.model = _StubModel() | ||
| rec = _Recorder() | ||
| c._send_producer_done = lambda request_id, frm, to: rec.producer_done.append((request_id, frm, to)) | ||
| c._send_partition_inputs = lambda request_id, pname, fwd_args: rec.partition_inputs.append(pname) | ||
| c._un_persist_tensors = lambda request_id, tensors: None | ||
| c._set_partition_worker_graph_ids = lambda request_id, pname, walk: None | ||
| meta = lambda walk: CurrentForwardConductorMetadata(graph_walk=walk, is_prefill=False) # noqa: E731 | ||
| conns = { | ||
| "A->B": StreamingConnectionState(from_partition="A", to_partition="B", edge_name="tok"), | ||
| "B->C": StreamingConnectionState(from_partition="B", to_partition="C", edge_name="codes"), | ||
| } | ||
| req = RequestData( | ||
| persist_signals={}, persist_signal_ref_cnt={}, worker_graph_to_workers={}, all_worker_graph_ids=set(), | ||
| max_output_tokens=10_000, random_seed=0, resource_configs={}, | ||
| partition_states={p: PartitionState(partition_name=p, metadata=meta(p.lower())) for p in "ABC"}, | ||
| partition_definitions={p: PartitionDefinition(name=p, graph_walks={p.lower()}) for p in "ABC"}, | ||
| streaming_connections=conns, | ||
| ) | ||
| c.requests = {rid: req} | ||
| return c, req, rec | ||
|
|
||
|
|
||
| def test_worker_final_chunk_signal_ends_the_partition_and_propagates_producer_done(): | ||
| c, req, rec = _conductor() | ||
| # B consumed the final chunk of A->B: B is done, and C must learn its producer is done | ||
| all_done = c._process_done_forward("r", "B", partition_done_from_worker=True) | ||
| assert req.partition_states["B"].is_done is True | ||
| assert req.streaming_connections["B->C"].producer_done is True | ||
| assert rec.producer_done == [("r", "B", "C")] | ||
| assert all_done is False # A and C are still running | ||
| assert c.model.calls == [("B", ["tok"])] | ||
|
|
||
|
|
||
| def test_counter_heuristics_are_not_needed_and_an_ordinary_pass_does_not_end_it(): | ||
| c, req, rec = _conductor() | ||
| # B finished a pass but did not consume the final chunk: it waits for more stream data | ||
| all_done = c._process_done_forward("r", "B", partition_done_from_worker=False) | ||
| assert req.partition_states["B"].is_done is False | ||
| assert req.streaming_connections["B->C"].producer_done is False | ||
| assert rec.producer_done == [] and rec.partition_inputs == [] | ||
| assert all_done is False | ||
|
|
||
|
|
||
| def test_partition_without_incoming_connections_ignores_the_flag(): | ||
| """A producer-only partition (no stream in) ends only through the model's answer.""" | ||
| c, req, rec = _conductor() | ||
| c._process_done_forward("r", "A", partition_done_from_worker=True) | ||
| assert req.partition_states["A"].is_done is False | ||
| assert rec.producer_done == [] | ||
|
|
||
|
|
||
| def test_chain_closes_partition_by_partition(): | ||
| c, req, rec = _conductor() | ||
| c.model.get_partition_forward_pass_args = lambda partition_name, partition_metadata, persist_signals, \ | ||
| incoming_connections=None: ForwardPassArgs(full_metadata=partition_metadata, inputs=[], unpersist_tensors=[], | ||
| request_done=partition_name == "A") | ||
| assert c._process_done_forward("r", "A") is False # A ends itself (its own stream input is exhausted) | ||
| assert req.streaming_connections["A->B"].producer_done is True | ||
| assert c._process_done_forward("r", "B", partition_done_from_worker=True) is False | ||
| assert c._process_done_forward("r", "C", partition_done_from_worker=True) is True # every partition done | ||
| assert rec.producer_done == [("r", "A", "B"), ("r", "B", "C")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| """A streaming consumer nested inside a ``Loop`` must be found by the worker's | ||
| partition-node and consumer-node lookups. | ||
|
|
||
| Both used to inspect only a walk's top-level section: a walk that is itself a | ||
| single ``GraphNode`` matched, but a decode ``Loop`` whose inner node consumes | ||
| the streamed edge did not. Its chunks were then routed to ``next_node=""`` and | ||
| its ``StreamBuffer`` was never created (``KeyError`` when routing the edge). | ||
| """ | ||
| from types import SimpleNamespace | ||
|
|
||
| from mstar.conductor.request_info import PartitionDefinition | ||
| from mstar.graph.base import GraphEdge, GraphNode, Loop, Sequential | ||
| from mstar.graph.special_destinations import EMIT_TO_CLIENT | ||
| from mstar.streaming.chunk_policy import FixedChunkPolicy | ||
| from mstar.streaming.topology import Connection, StreamingGraphEdge | ||
| from mstar.worker.worker import Worker | ||
|
|
||
|
|
||
| def _model(): | ||
| producer = GraphNode( | ||
| name="producer", | ||
| input_names=["text_inputs"], | ||
| outputs=[StreamingGraphEdge(next_node="consumer", name="chunk", target_partition="B")], | ||
| ) | ||
| consumer_loop = Loop( | ||
| name="consumer_loop", | ||
| section=GraphNode( | ||
| name="consumer", | ||
| input_names=["chunk"], | ||
| outputs=[StreamingGraphEdge(next_node="codec", name="codes", target_partition="C")], | ||
| ), | ||
| max_iters=8, | ||
| outputs=[], | ||
| ) | ||
| codec_chunk = Sequential([ | ||
| GraphNode(name="codec", input_names=["codes"], | ||
| outputs=[GraphEdge(next_node="post", name="pcm")]), | ||
| GraphNode(name="post", input_names=["pcm"], | ||
| outputs=[GraphEdge(next_node=EMIT_TO_CLIENT, name="audio", output_modality="audio")]), | ||
| ]) | ||
| walks = {"produce": producer, "consume": consumer_loop, "decode_audio": codec_chunk} | ||
| partitions = [ | ||
| PartitionDefinition(name="A", graph_walks={"produce"}, initial_walk="produce"), | ||
| PartitionDefinition(name="B", graph_walks={"consume"}, initial_walk="consume", producer_partitions=["A"]), | ||
| PartitionDefinition(name="C", graph_walks={"decode_audio"}, initial_walk="decode_audio", | ||
| producer_partitions=["B"]), | ||
| ] | ||
| return SimpleNamespace( | ||
| get_graph_walk_graphs=lambda: walks, | ||
| get_partitions=lambda: partitions, | ||
| ) | ||
|
|
||
|
|
||
| def _connections(): | ||
| return [ | ||
| Connection(from_partition="A", to_partition="B", edge_name="chunk", | ||
| chunk_policy_factory=lambda: FixedChunkPolicy(chunk_size=1)), | ||
| Connection(from_partition="B", to_partition="C", edge_name="codes", | ||
| chunk_policy_factory=lambda: FixedChunkPolicy(chunk_size=1)), | ||
| ] | ||
|
|
||
|
|
||
| def test_partition_nodes_recurse_into_loops_and_sequentials(): | ||
| model = _model() | ||
| # ``self`` is unused by the lookup, so call it unbound on a stub. | ||
| assert Worker._get_node_names_for_partition(None, "A", model) == ["producer"] | ||
| # the Loop's inner node, not the Loop's own name | ||
| assert Worker._get_node_names_for_partition(None, "B", model) == ["consumer"] | ||
| assert set(Worker._get_node_names_for_partition(None, "C", model)) == {"codec", "post"} | ||
| assert Worker._get_node_names_for_partition(None, "missing", model) == [] | ||
|
|
||
|
|
||
| def test_consumer_node_cache_finds_nested_consumers(): | ||
| cache = Worker._build_consumer_node_cache(_connections(), _model().get_graph_walk_graphs()) | ||
| assert cache == {"chunk": "consumer", "codes": "codec"} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.