Skip to content
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

[Unity][Transform] Implement ExpandTupleArguments #16115

Merged

Conversation

Lunderberg
Copy link
Contributor

Relax functions used as subroutines may receive a tuple of arguments, but only use a subset of the arguments provided. For externally-exposed functions, this is unavoidable, as the function signature may not be updated without breaking compatibility. For internal functions, all callsites are contained within the IRModule, and can be updated at the same time as the function signature.

This PR implements ExpandTupleArguments, which replaces R.Tuple parameters with separate parameters, when they occur in a private function.

Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Nov 13, 2023
Prior to this commit, the `FuseOps` pass explicitly tracked usage of
tuple arguments, to minimize the set of arguments provided to each
kernel.  The additional tgracking and handling of partially-used
tuples makes it difficult to follow the primary changes being made by
`FuseOps`.

This commit implements the same functionality in terms of the
`ExpandTupleArguments` and `RemoveUnusedParameters` transforms,
introduced in apache#16115 and
apache#16116 respectively.  By using these
passes before the main `FuseOps` changes, partial tuple usage is
already handled at that point.

This commit is intended to minimize any changes to user-facing
behavior, and so these pre-process passes are currently used
internally by `FuseOps`.  This may be avoided in the future by pulling
this internal delegation out into a lowering pipeline.
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Nov 13, 2023
Prior to this commit, the `FuseTIR` pass explicitly tracked usage of
tuple arguments, to minimize the set of arguments provided to each
kernel.  The additional tgracking and handling of partially-used
tuples makes it difficult to follow the primary changes being made by
`FuseTIR`.

This commit implements the same functionality in terms of the
`ExpandTupleArguments` and `RemoveUnusedParameters` transforms,
introduced in apache#16115 and
apache#16116 respectively.  By using these
passes before the main `FuseOps` changes, partial tuple usage is
already handled at that point.

This commit is intended to minimize any changes to user-facing
behavior, and so these pre-process passes are currently used
internally by `FuseOps`.  This may be avoided in the future by pulling
this internal delegation out into a lowering pipeline.
@Lunderberg Lunderberg force-pushed the unity_transform_expand_tuple_arguments branch from 5ae7da6 to 32f2808 Compare November 29, 2023 18:27
@Lunderberg
Copy link
Contributor Author

Rebased onto unity to keep CI results fresh.

Currently, the `FuseOps` and `FuseTIR` passes have a large amount of
added complexity to identify and handle partial use of tuple
arguments.  The handling partial use of tuples could be significantly
simpler if performed in multiple steps.

1. Perform `FuseOps`.  Any tuple variables that are used by the fused
   function are passed as-is.

2. Expand any parameters that are passed as a tuple.  Any unused
   tensors that were included in a partially-used tuple will be
   converted to unused parameters.

3. Remove any unused parameters.  Any unused tensors that were
   included in a partially-used tuple will be removed in this
   step.

4. Perform `FuseTIR`.  No checking for tuple arguments, either partial
   or full, is required at this step.

This PR implements `relax.transform.ExpandTupleArguments`, which is
step (2) in this process.
@Lunderberg Lunderberg force-pushed the unity_transform_expand_tuple_arguments branch from 32f2808 to f1d0605 Compare November 30, 2023 14:28
Copy link
Contributor

@slyubomirsky slyubomirsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The approach is clear and it's a nice simplification to be able to make.

@Lunderberg Lunderberg merged commit fe9d2fe into apache:unity Dec 1, 2023
2 checks passed
@Lunderberg Lunderberg deleted the unity_transform_expand_tuple_arguments branch December 1, 2023 14:21
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Dec 1, 2023
Prior to this commit, the `FuseTIR` pass explicitly tracked usage of
tuple arguments, to minimize the set of arguments provided to each
kernel.  The additional tgracking and handling of partially-used
tuples makes it difficult to follow the primary changes being made by
`FuseTIR`.

This commit implements the same functionality in terms of the
`ExpandTupleArguments` and `RemoveUnusedParameters` transforms,
introduced in apache#16115 and
apache#16116 respectively.  By using these
passes before the main `FuseOps` changes, partial tuple usage is
already handled at that point.

This commit is intended to minimize any changes to user-facing
behavior, and so these pre-process passes are currently used
internally by `FuseOps`.  This may be avoided in the future by pulling
this internal delegation out into a lowering pipeline.
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Dec 1, 2023
Prior to this commit, the `FuseOps` pass explicitly tracked usage of
tuple arguments, to minimize the set of arguments provided to each
kernel.  The additional tgracking and handling of partially-used
tuples makes it difficult to follow the primary changes being made by
`FuseOps`.

This commit implements the same functionality in terms of the
`ExpandTupleArguments` and `RemoveUnusedParameters` transforms,
introduced in apache#16115 and
apache#16116 respectively.  By using these
passes before the main `FuseOps` changes, partial tuple usage is
already handled at that point.

This commit is intended to minimize any changes to user-facing
behavior, and so these pre-process passes are currently used
internally by `FuseOps`.  This may be avoided in the future by pulling
this internal delegation out into a lowering pipeline.
Archermmt pushed a commit to Archermmt/tvm that referenced this pull request Dec 18, 2023
[Unity] Implement ExpandTupleArguments transform

Currently, the `FuseOps` and `FuseTIR` passes have a large amount of
added complexity to identify and handle partial use of tuple
arguments.  The handling partial use of tuples could be significantly
simpler if performed in multiple steps.

1. Perform `FuseOps`.  Any tuple variables that are used by the fused
   function are passed as-is.

2. Expand any parameters that are passed as a tuple.  Any unused
   tensors that were included in a partially-used tuple will be
   converted to unused parameters.

3. Remove any unused parameters.  Any unused tensors that were
   included in a partially-used tuple will be removed in this
   step.

4. Perform `FuseTIR`.  No checking for tuple arguments, either partial
   or full, is required at this step.

This PR implements `relax.transform.ExpandTupleArguments`, which is
step (2) in this process.
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Dec 19, 2023
Prior to this commit, the `FuseTIR` pass explicitly tracked usage of
tuple arguments, to minimize the set of arguments provided to each
kernel.  The additional tgracking and handling of partially-used
tuples makes it difficult to follow the primary changes being made by
`FuseTIR`.

This commit implements the same functionality in terms of the
`ExpandTupleArguments` and `RemoveUnusedParameters` transforms,
introduced in apache#16115 and
apache#16116 respectively.  By using these
passes before the main `FuseOps` changes, partial tuple usage is
already handled at that point.

This commit is intended to minimize any changes to user-facing
behavior, and so these pre-process passes are currently used
internally by `FuseOps`.  This may be avoided in the future by pulling
this internal delegation out into a lowering pipeline.
Lunderberg added a commit that referenced this pull request Jan 3, 2024
* [Unity][Transform] Extract partial-tuple-usage from FuseTIR

Prior to this commit, the `FuseTIR` pass explicitly tracked usage of
tuple arguments, to minimize the set of arguments provided to each
kernel.  The additional tgracking and handling of partially-used
tuples makes it difficult to follow the primary changes being made by
`FuseTIR`.

This commit implements the same functionality in terms of the
`ExpandTupleArguments` and `RemoveUnusedParameters` transforms,
introduced in #16115 and
#16116 respectively.  By using these
passes before the main `FuseOps` changes, partial tuple usage is
already handled at that point.

This commit is intended to minimize any changes to user-facing
behavior, and so these pre-process passes are currently used
internally by `FuseOps`.  This may be avoided in the future by pulling
this internal delegation out into a lowering pipeline.

* Updated based on review comments

* ci bump
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Jan 3, 2024
Prior to this commit, the `FuseOps` pass explicitly tracked usage of
tuple arguments, to minimize the set of arguments provided to each
kernel.  The additional tgracking and handling of partially-used
tuples makes it difficult to follow the primary changes being made by
`FuseOps`.

This commit implements the same functionality in terms of the
`ExpandTupleArguments` and `RemoveUnusedParameters` transforms,
introduced in apache#16115 and
apache#16116 respectively.  By using these
passes before the main `FuseOps` changes, partial tuple usage is
already handled at that point.

This commit is intended to minimize any changes to user-facing
behavior, and so these pre-process passes are currently used
internally by `FuseOps`.  This may be avoided in the future by pulling
this internal delegation out into a lowering pipeline.
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.

2 participants