-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Unity][Bugfix] Check for trivial re-bindings in MatchCast nodes #15854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
junrushao
merged 1 commit into
apache:unity
from
Lunderberg:unity_bugfix_check_for_trivial_match_cast
Oct 3, 2023
Merged
[Unity][Bugfix] Check for trivial re-bindings in MatchCast nodes #15854
junrushao
merged 1 commit into
apache:unity
from
Lunderberg:unity_bugfix_check_for_trivial_match_cast
Oct 3, 2023
Conversation
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
The `KillAfterLastUse` pass that was implemented in apache#15810 checked for trivial re-bindings in `VarBinding` nodes, but not in `MatchCast` nodes. As a result, `CodeGenVM`'s de-duplication of registers resulted in the object being killed prematurely. ```python y = R.match_cast(x, R.Tensor(...)) # Trivial rebinding here. # CodeGenVM has these share a register. R.memory.kill_tensor(x) # Kill x after last usage. # Register is set to None. _ = R.ExternFunc("set_item")(y) # Use of the cleared register through y. ```
Contributor
Author
|
@junrushao This change should resolve the MLC-LLM error you found in #15852. It works in my local setup, and it would be good to validate that it works on your side as well. |
junrushao
approved these changes
Oct 2, 2023
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Oct 2, 2023
Prior to this commit, if a relax variable were assigned to itself, through either `VarBinding` or `MatchCast` nodes, the two relax variables would share the same register in the VM. As a result, any upstream transform that deletes an object with `R.memory.kill_tensor` or `R.memory.kill_storage` must be aware of this VM behavior, and to only output one such instruction for each set of aliased registers. This commit updates the VM to produce one register for each aliased relax variable. The trivial bindings can be removed applying `relax.transform.CanonicalizeBindings`, instead of being implicitly de-duplicated at the codegen level. This PR is a follow-up to apache#15854, with a better long-term solution, but which may have knock-on effects that must also be resolved. In addition, this adds a usage example for the bug reported in apache#15852, to avoid re-occurrence of similar issues.
Member
|
Just hit the issue of |
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Oct 3, 2023
Prior to this commit, if a relax variable were assigned to itself, through either `VarBinding` or `MatchCast` nodes, the two relax variables would share the same register in the VM. As a result, any upstream transform that deletes an object with `R.memory.kill_tensor` or `R.memory.kill_storage` must be aware of this VM behavior, and to only output one such instruction for each set of aliased registers. This commit updates the VM to produce one register for each aliased relax variable. The trivial bindings can be removed applying `relax.transform.CanonicalizeBindings`, instead of being implicitly de-duplicated at the codegen level. This PR is a follow-up to apache#15854, with a better long-term solution, but which may have knock-on effects that must also be resolved. In addition, this adds a usage example for the bug reported in apache#15852, to avoid re-occurrence of similar issues.
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Oct 24, 2023
Prior to this commit, if a relax variable were assigned to itself, through either `VarBinding` or `MatchCast` nodes, the two relax variables would share the same register in the VM. As a result, any upstream transform that deletes an object with `R.memory.kill_tensor` or `R.memory.kill_storage` must be aware of this VM behavior, and to only output one such instruction for each set of aliased registers. This commit updates the VM to produce one register for each aliased relax variable. The trivial bindings can be removed applying `relax.transform.CanonicalizeBindings`, instead of being implicitly de-duplicated at the codegen level. This PR is a follow-up to apache#15854, with a better long-term solution, but which may have knock-on effects that must also be resolved. In addition, this adds a usage example for the bug reported in apache#15852, to avoid re-occurrence of similar issues.
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Oct 25, 2023
Prior to this commit, if a relax variable were assigned to itself, through either `VarBinding` or `MatchCast` nodes, the two relax variables would share the same register in the VM. As a result, any upstream transform that deletes an object with `R.memory.kill_tensor` or `R.memory.kill_storage` must be aware of this VM behavior, and to only output one such instruction for each set of aliased registers. This commit updates the VM to produce one register for each aliased relax variable. The trivial bindings can be removed applying `relax.transform.CanonicalizeBindings`, instead of being implicitly de-duplicated at the codegen level. This PR is a follow-up to apache#15854, with a better long-term solution, but which may have knock-on effects that must also be resolved. In addition, this adds a usage example for the bug reported in apache#15852, to avoid re-occurrence of similar issues.
Lunderberg
added a commit
that referenced
this pull request
Oct 31, 2023
* [Unity] Ensure one VM register for each relax binding Prior to this commit, if a relax variable were assigned to itself, through either `VarBinding` or `MatchCast` nodes, the two relax variables would share the same register in the VM. As a result, any upstream transform that deletes an object with `R.memory.kill_tensor` or `R.memory.kill_storage` must be aware of this VM behavior, and to only output one such instruction for each set of aliased registers. This commit updates the VM to produce one register for each aliased relax variable. The trivial bindings can be removed applying `relax.transform.CanonicalizeBindings`, instead of being implicitly de-duplicated at the codegen level. This PR is a follow-up to #15854, with a better long-term solution, but which may have knock-on effects that must also be resolved. In addition, this adds a usage example for the bug reported in #15852, to avoid re-occurrence of similar issues. * Add unit test to validate that the alias is preserved * Use the new GetBoundValue utility function * Update VMTIRCodeGen to also avoid de-duplication of bindings * Move the callback definition to tvm.relax.testing.vm namespace
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.
The
KillAfterLastUsepass that was implemented in #15810 checked for trivial re-bindings inVarBindingnodes, but not inMatchCastnodes. As a result,CodeGenVM's de-duplication of registers resulted in the object being killed prematurely.