[Relax] Fix FuseOps: preserve symbolic shape dependencies from match_cast - #20513
Open
cchung100m wants to merge 2 commits into
Open
cchung100m wants to merge 2 commits into
cchung100m wants to merge 2 commits into
Conversation
cchung100m
force-pushed
the
issue-20195
branch
from
October 1, 2026 14:38
c478417 to
12f2ba7
Compare
cchung100m
marked this pull request as ready for review
October 1, 2026 16:18
Contributor
Author
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.
Hi Committers,
This PR fixes issue #20195. Any suggestions would be appreciated if you are available.
Root Cause
FuseOpsreorders bindings within a dataflow block by topologically sorting fusion groups according toOperatorFusor::group_deps_. That dependency map is built inCollectFuncBoundary, which only tracks a dependency when a binding's value references another binding'srelax::Vardirectly.A symbolic shape variable introduced by
R.match_cast(..., R.Shape([s, ...]))is never bound by its ownVarBindingNode, so it never gets its own graph node. If a later binding's resulting type uses that variable - e.g. acall_tir'sout_ty=R.Tensor((s, ...))- with no other relax::Var tying it back to the match_cast, no dependency edge is recorded. When an unrelated elementwise group happens to fuse, and its dependency chain transitively reaches thatcall_tir,TopoSortByGroupDepcan schedule it before thematch_castthat definess, producing a module wheresis used before it's defined (Symbolic Var ... is not defined.).Solution
In
OperatorFusor::CollectFuncBoundary(src/relax/transform/fuse_ops.cc):MatchCastbinding that first defines it (DefinableTIRVarsInType(match_cast->ty)), in a newsymbolic_var_def_group_map.TIRVarsInType(GetType(binding->var))) and add a group dependency on the recorded definer, same as for ordinaryrelax::Vardependencies (cyclic-dependency check reused via a sharedAddGroupDephelper).