Skip to content

Conversation

@Lunderberg
Copy link
Contributor

Prior to this commit, the relax.transform.RealizeVDevice pass performed in-place update on expressions appearing in its input IRModule, overwriting their struct info. In-place mutation of TVM's IR types is only legal when the scope has sole ownership of the IR object, such as through the CopyOnWrite functionality, and is not allowed when the object is shared. As a result, applying RealizeVDevice would cause unexpected updates in unrelated expressions. Most noticeably, the IRModule used as input to RealizeVDevice would have its variable erroneously updated.

This commit refactors the RealizeVDevice transform to remove all in-place mutation. The same propagation rules are followed, with known VDevice annotations propagated forward from the output of R.hint_on_device, and propagated backwards from the input of R.hint_on_device if no such annotation already exists.

Closes #17205.

Prior to this commit, the `relax.transform.RealizeVDevice` pass
performed in-place update on expressions appearing in its input
`IRModule`, overwriting their struct info.  In-place mutation of TVM's
IR types is only legal when the scope has sole ownership of the IR
object, such as through the `CopyOnWrite` functionality, and is not
allowed when the object is shared.  As a result, applying
`RealizeVDevice` would cause unexpected updates in unrelated
expressions.  Most noticeably, the `IRModule` used as input to
`RealizeVDevice` would have its variable erroneously updated.

This commit refactors the `RealizeVDevice` transform to remove all
in-place mutation.  The same propagation rules are followed, with
known `VDevice` annotations propagated forward from the output of
`R.hint_on_device`, and propagated backwards from the input of
`R.hint_on_device` if no such annotation already exists.

Closes apache#17205.
@Hzfengsy Hzfengsy merged commit 995524a into apache:main Sep 8, 2024
@Lunderberg Lunderberg deleted the refactor_realize_vdevice_to_remove_in_place_mutation branch September 8, 2024 12:12
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.

[Bug] [Relax] cannot remove the hint_on_device

3 participants