You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The original AdjustMatmulOrder change and its test are omitted because that pass was removed upstream in #20712. This branch includes current main (c14bc80e).
@tlopex Merged current main and resolved the conflicts, keeping the upstream removal of AdjustMatmulOrder (#20712). The three remaining fixes are preserved. The Release/LLVM build, all 36 related tests, and pre-commit checks pass locally. Could you take a look when convenient? Thanks!
Could one of you take a look at these Relax transformation correctness fixes when you have a chance, or point me to the right reviewer? I am keen to help get these fixes into TVM and happy to address feedback, add further regression tests, rebase, or split the changes if that would make review easier.
The GitHub Actions checks also seem to need maintainer help with fork-workflow approval or a restart. I would appreciate any guidance on getting the appropriate checks running. Thank you for your time!
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Unresolved recursive and aliased closure handling, output pruning, and invocation-purity bugs can produce invalid IR or remove side effects, while unaligned constant reads can cause undefined behavior or crashes.
Contiguous imported CPU tensors can have an unaligned data pointer even when byte_offset() is zero. Dereferencing data[i] then has undefined behavior for these int16/int32 paths and may crash on strict-alignment CPUs. Use byte-wise copies as vm.builtin.tensor_to_shape does, or leave unaligned constants unfolded.
Rewrite aliases using in-progress recursive closure mappings
src/relax/transform/lambda_lift.cc:268
With alias = inner inside a recursive noncapturing inner, new_value is a lifted global that has not been registered yet, so IsClosure fails its module lookup even if the alias is unused. For a capturing recursive function, the alias instead retains the unlifted self variable and misses nested_closure_map_, leaving a free variable in the lifted body. Handle in-progress recursive mappings when rewriting aliases, including captured arguments, and add regressions for both cases.
Keep aliases of plain function references as ordinary calls
src/relax/transform/lambda_lift.cc:383
With a noncapturing outer_func that returns a captured function, alias = outer_func; f = alias(x) is now rewritten to invoke_pure_closure(alias, ...), although alias holds a plain function reference. IsClosure also recognizes globals whose return value is a closure, so it cannot by itself decide whether the called value is a closure object. Follow the alias chain to its producer and retain the CallObj guard, so aliases of plain function references remain ordinary calls.
Use the called closure's purity for invocation
src/relax/transform/lambda_lift.cc:386
For f = maker(x); f(y), where a pure maker returns an impure captured function, this still uses the maker's purity and emits invoke_pure_closure for the impure invocation. That mislabels side effects as removable. Use the called variable's original FuncType purity for every closure invocation, and add a pure-factory/impure-closure regression.
Preserve outputs when a GlobalVar is used as a value
The GlobalVar-only check still misses f = Before.outputs; closure = R.make_closure(f, (x,)), so the callee's outputs are pruned while the closure retains its old signature. The same issue occurs when a private function is called through an alias, returned, or stored in a tuple. Conservatively preserve all outputs whenever a tracked GlobalVar is used as a value rather than as a direct callee, and add an aliased-callee regression.
Avoid quadratic closure checks across variable aliases
src/relax/transform/lambda_lift.cc:265
This runs IsClosure for every variable alias, including tensor aliases. For a1 = x; a2 = a1; ..., each check recursively follows all preceding bindings without caching negative results, so N aliases require quadratic work and linear recursion depth even in a module with no local functions. Skip closure analysis for statically noncallable aliases, or cache negative results to avoid repeatedly traversing the same chains.
Hi @MasterJH5574, could you take a look at the fixes for constant folding, lambda lifting, and unused outputs when you have a chance? All eight checks passed. Thanks!
This branch has not been deployed
No deployments
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
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.
This fixes three correctness issues in Relax transformation passes:
make_closure;tensor_to_shapeconstants using their actual int16/int32/int64 storage dtype inFoldConstant;LambdaLiftand choose the invoke op from the function's purity.The changes are local to the affected passes and retain the existing behavior for supported controls.
Closes #20493
Closes #20495
Closes #20497
The original
AdjustMatmulOrderchange and its test are omitted because that pass was removed upstream in #20712. This branch includes current main (c14bc80e).Validation:
pytest tests/python/relax/test_transform_remove_unused_outputs.py tests/python/relax/test_transform_fold_constant.py tests/python/relax/test_transform_lambda_lift.py -q: 36 passed.