Repository navigation
Avoid quadratic Slice split matching - #3168
Open
Mayuri (mayuriphad) wants to merge 5 commits into
Open
Mayuri (mayuriphad) wants to merge 5 commits into
Mayuri (mayuriphad) wants to merge 5 commits into
Conversation
For a pattern with several output nodes, SimplePatternMatcher fixed the first output to the candidate node and tried every graph node with the same op type for the other outputs, rebuilding an index of all nodes for each candidate. With many Slice nodes, SlicesSplit dominated optimize(). Match the first output node once and stop if it fails. Otherwise, take the candidates for each other output node from the consumers of a value the first match already bound to one of its inputs, since a node that does not read that value cannot match. The op-type index is only built, once per call, when no input is bound. Fixes microsoft#3154 Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
_match_node can return False without failing the match, for example when the candidate node has fewer outputs than the pattern node. Returning that match early let callers treat an incomplete match as a success. Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
Keep generic multi-output matching complete, validate output counts at the source, and cover Slice fusion correctness and scaling. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Fixes #3154.
Keep bound-input candidate filtering for general multi-output patterns, and give
SlicesSplita per-graph, per-input/axis index of complementary halves. Ineligible Slices are rejected before enumerating consumers; removed candidates are discarded once and newly visited Slices are registered. Nested graphs preserve their parent's index.This also restores actual Slice-to-Split fusion in either node order, without generating incorrect odd-dimension splits or using
num_outputsbefore opset 18. Output-count mismatches now fail inside_match_node, covering subsequent outputs as well as the first.Issue repro, timing
SlicesSplitalone on shared-input Slices:Windows/Python 3.13; fresh models, construction excluded; medians of three runs before and five after. Baseline is
e0215e99with current main merged. Four times the nodes now takes about 4.2 times the time, versus 16.6 times before.Duplicate eligible prefixes without a complementary suffix also avoid pair enumeration: 1k/2k/4k Slices take 0.031/0.061/0.106 s, versus 0.514/1.732/7.608 s before. Synthetic MoE-like graphs (32 experts/layer, activation and weight Slices plus MatMul/Add/Relu) take 0.028/0.079/0.098 s for 2k/4k/8k Slices. Full
optimizer.optimizeon 24/48/96 such layers takes 1.62/3.02/5.90 s (three-run medians); these are synthetic graphs, not timings of the reporter's exported model.Validation: 731 tests and 48 subtests passed, two existing skips;
lintrunner -aclean. Regressions cover bounded classification work, numeric equivalence, output order/topology, cache lifecycle, disconnected/unbound/wildcard outputs, shared intermediates, graph scope, and literal attribute constraints.