Skip to content

[Relax] Fix FuseOps: preserve symbolic shape dependencies from match_cast - #20513

Open
cchung100m wants to merge 2 commits into
apache:mainfrom
cchung100m:issue-20195
Open

cchung100m wants to merge 2 commits into
apache:mainfrom
cchung100m:issue-20195

Conversation

@cchung100m

@cchung100m cchung100m commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Hi Committers,

This PR fixes issue #20195. Any suggestions would be appreciated if you are available.

Root Cause

FuseOps reorders bindings within a dataflow block by topologically sorting fusion groups according to OperatorFusor::group_deps_. That dependency map is built in CollectFuncBoundary, which only tracks a dependency when a binding's value references another binding's relax::Var directly.

A symbolic shape variable introduced by R.match_cast(..., R.Shape([s, ...])) is never bound by its own VarBindingNode, so it never gets its own graph node. If a later binding's resulting type uses that variable - e.g. a call_tir's out_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 that call_tir, TopoSortByGroupDep can schedule it before the match_cast that defines s, producing a module where s is used before it's defined (Symbolic Var ... is not defined.).

Solution

In OperatorFusor::CollectFuncBoundary (src/relax/transform/fuse_ops.cc):

  • Track, per symbolic var, the group of the MatchCast binding that first defines it (DefinableTIRVarsInType(match_cast->ty)), in a new symbolic_var_def_group_ map.
  • For every binding, additionally scan the symbolic vars referenced by its resulting type (TIRVarsInType(GetType(binding->var))) and add a group dependency on the recorded definer, same as for ordinary relax::Var dependencies (cyclic-dependency check reused via a shared AddGroupDep helper).

@cchung100m
cchung100m marked this pull request as ready for review October 1, 2026 16:18
@cchung100m

Copy link
Copy Markdown
Contributor Author

cc @tlopex @mshr-h

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant