Repository navigation
qwen3_omni: prefix caching for the Thinker #836
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
Changes from 21 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
4419d97
engine: probe a walk whose submodule cuts its own tensor_inputs
Gaurav-Shah05 199d9ea
conductor: cache off when a keyed walk streams to a running partition
Gaurav-Shah05 c8d15e9
qwen3_omni: thinker cuts its inputs and places a cut walk's positions
Gaurav-Shah05 b8985ab
engine: an item encoder may opt out of its dynamic=True compile
Gaurav-Shah05 0970ba5
qwen3_omni: run the audio encoder eager as an item encoder
Gaurav-Shah05 7757d3e
qwen3_omni: the vision encoder compiles one graph for every image size
Gaurav-Shah05 0c6cabd
qwen3_omni: the thinker keys its prompt, images, audio and replies
Gaurav-Shah05 fd22735
test: prefix caching for the thinker
Gaurav-Shah05 815b345
comment pass
Gaurav-Shah05 644b3da
test pass
Gaurav-Shah05 a738c43
qwen3_omni: build the audio encoder's chunking before the compiled call
Gaurav-Shah05 d814ac2
engine: drop the item encoder's eager opt-out
Gaurav-Shah05 635bb0e
test: Qwen3-Omni's encoders reuse their graphs for sizes in range
Gaurav-Shah05 1a21c9f
Merge remote-tracking branch 'origin/main' into prefix-cache-omni
Gaurav-Shah05 40df852
worker: find streamed partitions from keyed labels
Gaurav-Shah05 b4014c9
qwen3_omni: drop the keyed stream that kv_labels replaces
Gaurav-Shah05 1621ed5
test: the prefix tests declare kv labels and layouts
Gaurav-Shah05 a9d75f1
qwen3_omni: a prompt with a video keys its leading text
Gaurav-Shah05 027cf1e
qwen3_omni: the layout takes an image's span from image_span
Gaurav-Shah05 975c7ca
qwen3_omni: a video prompt keys one span, with the reason
Gaurav-Shah05 c159552
test: a Qwen3-Omni prompt with a video keys its leading text
Gaurav-Shah05 1937be9
qwen3_omni: mark the vision encoder's cu_seqlens dynamic
dghosef 863e0da
qwen3_omni: size the vision encoder's max_seqlen to one frame
dghosef 00b6fe0
docs: Qwen3-Omni's Thinker counts prefix-cache hits too
dghosef 02381ed
prefix-caching skill: tensor inputs a split_inputs override cuts are …
dghosef fada3f7
engine: a submodule that cuts its tensor_inputs says so with a flag
Gaurav-Shah05 fdd6c43
qwen3_omni: a request with audio output turns the prefix cache off
Gaurav-Shah05 9f6c6b7
model: Qwen3.5 and Qwen3-Omni share their 3D position ids
Gaurav-Shah05 de5fd16
test: the tensor_inputs flag, the audio-output opt-out and shared 3D …
Gaurav-Shah05 f38c386
Merge remote-tracking branch 'origin/main' into prefix-cache-omni
Gaurav-Shah05 4722f7c
conductor: cache off for a request that runs a partition a keyed node…
Gaurav-Shah05 65a1f31
test: a request whose talker runs is not cached
Gaurav-Shah05 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 |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ | |
| from mstar.model.submodule_base import ( | ||
| EMPTY_INPUT_METADATA, | ||
| ARNodeInputs, | ||
| ARNodeSubmodule, | ||
| BatchedModelOutput, | ||
| HostRows, | ||
| InputMetadata, | ||
|
|
@@ -614,19 +615,22 @@ def _compile_submodules(self) -> None: | |
| A node in ``_item_encoders`` is compiled with dynamic=True instead. Under | ||
| the default it recompiles on its second input shape and the new graph | ||
| rounds differently, so the KV cached from its earlier outputs would no | ||
| longer match what it computes. | ||
| longer match what it computes. A node in ``_item_encoders`` whose submodule | ||
| sets ``marks_dynamic_dims`` keeps the default, since the submodule's | ||
| `prepare_inputs` marks the dimensions that vary. | ||
| """ | ||
| if not self.device_capability.is_available: | ||
| return | ||
|
|
||
| for node_name, submodule_mgmt in self._submodules.items(): | ||
| submodule = submodule_mgmt.submodule | ||
| item_encoder = node_name in self._item_encoders | ||
|
|
||
| if getattr(submodule, "disable_torch_compile", False): | ||
| logger.info("Engine: torch.compile disabled for %s (submodule opt-out)", node_name) | ||
| continue | ||
|
|
||
| dynamic = True if node_name in self._item_encoders else None | ||
| dynamic = True if item_encoder and not getattr(submodule, "marks_dynamic_dims", False) else None | ||
| try: | ||
| # no token count, these serve eager batches of any size | ||
| submodule_mgmt.forward = with_inductor_overrides(torch.compile( | ||
|
|
@@ -1184,7 +1188,10 @@ def _skip_cached_prefix( | |
| f"{self._prefix_model} keys the {walk!r} walk of {batch.node_name} " | ||
| "for prefix reuse, but that walk's inputs are not a sequence to cut" | ||
| ) | ||
| if inputs.tensor_inputs or inputs.kwargs or inputs.resource_step_info: | ||
| submodule = self._submodules[batch.node_name].submodule | ||
| if inputs.kwargs or inputs.resource_step_info or ( | ||
| inputs.tensor_inputs and type(submodule).split_inputs is ARNodeSubmodule.split_inputs | ||
| ): | ||
|
Comment on lines
+1194
to
+1196
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deciding whether to cut by checking if split_inputs was overridden is fragile. Can you add a flag instead |
||
| self._runner.apply_cached_prefix(rid, batch.node_name, walk, inputs, None) | ||
| return inputs | ||
| prefix = self._runner.resolve_cached_prefix(rid, batch.node_name, walk, inputs) | ||
|
|
@@ -1197,7 +1204,7 @@ def _skip_cached_prefix( | |
| if matched >= inputs.input_seq_len: | ||
| batch.cached_rids.add(rid) | ||
| return None | ||
| return self._submodules[batch.node_name].submodule.split_inputs( | ||
| return submodule.split_inputs( | ||
| walk, batch.per_request_info_wrapped[rid], inputs, | ||
| matched, inputs.input_seq_len, | ||
| ) | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
streamed_partitionsisn't needed for this - Qwen3-Omni'sprocess_promptcan return{"prefix_cache": False}when"audio" in output_modalitiesand then we can avoid the engine importThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept the rule in the conductor, since it comes from the graph. If each model's
process_prompthad to opt out, a model that forgot would serve hits that leave the partition it streams into short of rows. The worker import is gone though, sincestreamed_partitionsnow sits next to the load check inmstar/validation/resources.py.