Junius-Wynn opened a new pull request, #20333:
URL: https://github.com/apache/tvm/pull/20333
## Summary
Fixes #20177.
`FuseOps` can schedule a `call_tir` before the `match_cast` that defines its
output shape when another branch fuses with a later consumer. The resulting
allocation references a shape symbol before it is defined, causing
`VMShapeLower` to 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_cast` to prevent cyclic fusion through these shape
dependencies, and detect cycles when ordering groups. The dependency collector
uses `StructuralVisit` and `StructuralWalk` and respects parameter definitions,
repeated `match_cast` checks, and symbols local to callable signatures.
Add Relax regressions for definition-before-use ordering, valid fusion, and
symbol scope. 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. The `VMShapeLower` assertion remains in place.
## Validation
Local validation on macOS arm64 with Python 3.12 and LLVM 15:
- Full TVM build and a `tvm-ffi` build matching the checked-out submodule:
passed.
- Original issue reproducer: compilation passed.
- Targeted tests: **120 passed** — FuseOps (44), FuseTIR (35), VMShapeLower
(10), FuseOpsByPattern (29), and the two ONNX regression cases.
- Changed-file pre-commit hooks in an isolated environment: passed,
including Ruff checks, Ruff formatting, and clang-format.
- `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`:
```bash
python -m pytest \
tests/python/relax/test_transform_fuse_ops.py \
tests/python/relax/test_transform_fuse_tir.py \
tests/python/relax/test_backend_transform_shape_lower.py \
tests/python/relax/test_transform_fuse_ops_by_pattern.py \
tests/python/relax/test_frontend_onnx.py::test_size_slice_reshape_with_fusion -q
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]