[FIX][Relax] Preserve symbolic shape dependencies in FuseOps - #20333
Open
Junius-Wynn wants to merge 1 commit into
Open
Junius-Wynn wants to merge 1 commit into
Junius-Wynn wants to merge 1 commit into
Conversation
Junius-Wynn
force-pushed
the
fix/issue-20177-vm-shape-lower
branch
from
September 15, 2026 04:53
5416119 to
192c254
Compare
FuseOps can move a call_tir before the match_cast that defines its output shape when another branch fuses with a later consumer. This leaves the allocation shape undefined and causes VMShapeLower to fail on the Size/Slice/Reshape model in apache#20177. Track the first definition of each shape symbol in both graph partitioning and group scheduling. Preserve match_cast input edges and detect cycles in the fusion group dependency graph. Isolate definitions in each If branch, recognize scalar parameters as existing definitions, and respect repeated match_cast checks and callable-type scopes. Add Relax regressions for shape dependencies, branch-local definitions, and scalar parameters in pattern fusion. Add two ONNX execution cases using the original pipeline at fusion level 2, checking VM results against ONNX Runtime while preserving valid fusion. Pin the test models to ONNX IR 8 so newer ONNX packages remain compatible with CI's ONNX Runtime. Validation: - TVM build passed on macOS arm64 with LLVM 15. - 134 tests passed across FuseOps, FuseTIR, VMShapeLower, FuseOpsByPattern, MergeCompositeFunctions, and the ONNX regression. - ONNX regressions passed with the default model IR forced to 13. - Changed-file pre-commit hooks and git diff --check passed. Fixes apache#20177
Junius-Wynn
force-pushed
the
fix/issue-20177-vm-shape-lower
branch
from
September 15, 2026 04:59
192c254 to
a1734c0
Compare
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.
Summary
Fixes #20177.
FuseOpscan schedule acall_tirbefore thematch_castthat defines its output shape when another branch fuses with a later consumer. The resulting allocation references a shape symbol before it is defined, causingVMShapeLowerto fail on the ONNX Size/Slice/Reshape model in the issue.Track the first definition of each shape symbol and include its uses in both fusion partitioning and group scheduling. Preserve the ordinary input dependencies of
match_castto prevent cyclic fusion through these shape dependencies, and detect cycles when ordering groups. The collector usesStructuralVisitandStructuralWalk, treats scalar parameters as already defined, isolates definitions in eachIfbranch, and respects parameter-type definitions, repeatedmatch_castchecks, and symbols local to callable signatures.Add Relax regressions for definition-before-use ordering, valid fusion, branch-local symbol scope, and scalar parameters in pattern fusion. Add two ONNX execution cases using the original pipeline with
FuseOps(fuse_opt_level=2), comparing VM outputs against ONNX Runtime and the expected result. Explicitly set the test models to ONNX IR version 8 so newer ONNX packages do not generate models that CI's ONNX Runtime cannot load. TheVMShapeLowerassertion remains in place.Validation
Local validation on macOS arm64 with Python 3.12 and LLVM 15, using this checkout's TVM and a
tvm-ffibuild matching the checked-out submodule:If-scope and scalar-parameter regressions both pass structural equality checks against the expected IR. Both ONNX cases compile and execute with matching numerical results.VMShapeLowerassertion using the parent commit's FuseOps implementation, and pass compilation, execution, and numerical comparisons using the fix.git diff --check: passed.Regression command, run from the repository root in the configured build/test environment with this checkout's TVM and matching
tvm-ffi: