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

[TIR][Schedule] Transform layout quality of life #11269

Merged
merged 23 commits into from
May 26, 2022

Conversation

Lunderberg
Copy link
Contributor

@Lunderberg Lunderberg commented May 10, 2022

Draft PR, seeing whether some of the TE-specific interface features can be pulled over into the TIR-based schedules. These are implemented as Schedule.transform_layout_sugared, which wraps around the existing Schedule.transform_layout.

  • Specify buffer by name, rather than by access_type/index.
  • Optional specify block by name, rather than needing a separate call to Schedule.get_block.
  • Enable *args in the index mapping function.
  • Allow AXIS_SEPARATOR in the index mapping function, delegate to Schedule.set_axis_separators

@Lunderberg
Copy link
Contributor Author

@vinx13 A draft of some ease-of-use changes I'd been experimenting with this afternoon. These are python-only, and unpack to the same C++ calls, so it (hopefully) shouldn't cause issues elsewhere.

@vinx13
Copy link
Member

vinx13 commented May 10, 2022

This is super cool, thanks for the PR. Shall we consider more informative names on what's being sugared. For example, axis_separators are related to physical layout, do you think something like transform_to_physical_layout would be more meaningful? Feel free to come up with better names

@Lunderberg
Copy link
Contributor Author

I'd definitely be up for a better name, as transform_layout_sugared definitely leaves the reader uncertain what is being done. My one concern with having a completely different name is that it may not be clear to a reader that this is the same underlying schedule primitive in C++.

Another alternative would be to merge this as the input handling of Schedule.transform_layout. There's already some handling, such as the conversion from Callable to IndexMap, so this would be similar python-only handling. This would also avoid the issue of having multiple functions that aren't immediately obvious as wrappers around each other.

@Lunderberg
Copy link
Contributor Author

Something sort of like the changes here are what I'm picturing. Not complete, because Union[Tuple[int,str],str] breaks the @type_checked annotation, but something sort of like this.

@Lunderberg
Copy link
Contributor Author

#11289 should resolve the type-checking annotation issue with Tuples, if we want to go forward with the other changes here.

@Lunderberg Lunderberg force-pushed the transform_layout_quality_of_life branch from 5ce8acb to ec66ff1 Compare May 16, 2022 13:48
@Lunderberg
Copy link
Contributor Author

CI functionality tests all passed, updates to resolve sphinx documentation tests, and rebase to resolve merge conflict.

buffer_index: int,
buffer_index_type: str,
block: Union[BlockRV, str],
buffer: Union[Tuple[str, int], str, Buffer],
Copy link
Member

@vinx13 vinx13 May 17, 2022

Choose a reason for hiding this comment

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

this will break trace to python conversion. It is implemented here https://github.com/apache/tvm/blob/main/src/tir/schedule/primitive/layout_transformation.cc#L288. Unfortunately CI didn’t catch this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the catch, and I'll update TransformLayoutTraits::UnpackedAsPython with the updated arguments. Is there somewhere that should have an additional test for round-tripping the python conversion? It looks like this UnpackedAsPython is used in Trace.as_python, but I don't see any tests that call it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found it. The verify_trace_roundtrip helper function verifies that the trace can be round-tripped through JSON, and that the trace can be converted to python, but doesn't verify that the trace can be round-tripped through python.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be corrected now, including updates to verify_trace_roundtrip to validate the python roundtrip by default. If this finds other breakages unrelated to this PR, I'll limit the python roundtrip checks to opt-in tests, with a tracking issue to resolve any other breakages.

@Lunderberg
Copy link
Contributor Author

All tests passing, including tests for the UnpackAsPython. Marking the PR as ready for review.

@Lunderberg Lunderberg marked this pull request as ready for review May 18, 2022 16:11
@Lunderberg Lunderberg changed the title [Draft][TIR][Schedule] Transform layout quality of life [TIR][Schedule] Transform layout quality of life May 18, 2022
@Lunderberg Lunderberg requested a review from vinx13 May 19, 2022 13:12
Copy link
Contributor

@csullivan csullivan left a comment

Choose a reason for hiding this comment

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

Very nice! I really like the new interface and refactoring under IndexMap for reuse in TE and TIR.

Copy link
Member

@vinx13 vinx13 left a comment

Choose a reason for hiding this comment

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

Overall LGTM

python/tvm/tir/schedule/schedule.py Outdated Show resolved Hide resolved
python/tvm/tir/schedule/schedule.py Outdated Show resolved Hide resolved
@Lunderberg
Copy link
Contributor Author

Current CI failures due to Scipy URL change, should restart CI after #11399 lands.

@Lunderberg Lunderberg force-pushed the transform_layout_quality_of_life branch from a7251f2 to a513f18 Compare May 23, 2022 16:30
@Lunderberg
Copy link
Contributor Author

CI failure in Docs: GPU looks like it was caused by a network timeout. Re-triggering CI.

@Lunderberg
Copy link
Contributor Author

CI failure this time was due to CUDA version in Docs: GPU. Looks like the docker image was recently updating, merging main into the dev branch and retriggering CI.

@Lunderberg Lunderberg force-pushed the transform_layout_quality_of_life branch from 5af3cfd to 00e7eb6 Compare May 25, 2022 19:11
@Lunderberg
Copy link
Contributor Author

Retriggering CI following #11456.

@vinx13 vinx13 merged commit 814f550 into apache:main May 26, 2022
@Lunderberg Lunderberg deleted the transform_layout_quality_of_life branch May 26, 2022 11:56
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Jun 8, 2022
Similar to apache#11269, which added this
functionality to `Schedule.transform_layout`.
vinx13 pushed a commit that referenced this pull request Jun 9, 2022
…11624)

* [Schedule] Allowed string argument as block arg

This has previously been implemented for `Schedule.transform_layout`
in #11296, extending to allow for
block arguments in all `Schedule` methods.

This change was only made for arguments that must be a `BlockRV`.  For
arguments that may be either a `BlockRV` or another
type (e.g. `Schedule.get_child_blocks` accepts either `BlockRV` or
`LoopRV`), this sugar is not implemented, to avoid ambiguity.

* [Schedule] Allowed string argument to Schedule.reindex

Similar to #11269, which added this
functionality to `Schedule.transform_layout`.

* CI test update
Kathryn-cat pushed a commit to Kathryn-cat/tvm that referenced this pull request Jun 10, 2022
…pache#11624)

* [Schedule] Allowed string argument as block arg

This has previously been implemented for `Schedule.transform_layout`
in apache#11296, extending to allow for
block arguments in all `Schedule` methods.

This change was only made for arguments that must be a `BlockRV`.  For
arguments that may be either a `BlockRV` or another
type (e.g. `Schedule.get_child_blocks` accepts either `BlockRV` or
`LoopRV`), this sugar is not implemented, to avoid ambiguity.

* [Schedule] Allowed string argument to Schedule.reindex

Similar to apache#11269, which added this
functionality to `Schedule.transform_layout`.

* CI test update
juda pushed a commit to juda/tvm that referenced this pull request Jun 21, 2022
* [TIR][Schedule] Added Schedule.transform_layout_sugared

* [TE][TIR] Reduced duplication in TE/TIR layout transformations

Previously, the implementations of `tir.IndexMap.from_func` and
`te.Stage.transform_layout` had significant duplication to handle
argument parsing.  This commit extracts the shared logic into
`tir.IndexMap`.

* Enabled *args in Schedule.transform_layout_sugared

* Fix lint error

* Allow Schedule.transform_layout_sugared to set axis separators

* Merged transform_layout_sugared functionality into transform_layout

* Fix lint errors

* Fix lint error

* Fixed docstring errors

* Updated/tested TransformatLayoutTraits::UnpackedAsPython

* Disabled exec-used check for running trace.as_python()

* Updated SetAxisSeparatorTraits::UnpackedAsPython

* Updated unit test that was added in merge commit

* Fixed the argument name for TensorizeTraits

This wasn't checked before, but was the only other issue caught by the
updates to verify_trace_roundtrip.

* Re-enable type checks of transform_layout/set_axis_separator

Disabled while waiting for apache#11289,
which was required for the `Tuple` argument.

* Updated a few additional transform_layout usages from main
juda pushed a commit to juda/tvm that referenced this pull request Jun 21, 2022
…pache#11624)

* [Schedule] Allowed string argument as block arg

This has previously been implemented for `Schedule.transform_layout`
in apache#11296, extending to allow for
block arguments in all `Schedule` methods.

This change was only made for arguments that must be a `BlockRV`.  For
arguments that may be either a `BlockRV` or another
type (e.g. `Schedule.get_child_blocks` accepts either `BlockRV` or
`LoopRV`), this sugar is not implemented, to avoid ambiguity.

* [Schedule] Allowed string argument to Schedule.reindex

Similar to apache#11269, which added this
functionality to `Schedule.transform_layout`.

* CI test update
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Sep 16, 2022
Follow-up from apache#11269, which allowed
schedule arguments of the buffer to be transformed to be specified as
a string, or as a `tir::Buffer`.  The string handling worked
correctly, but the `tir::Buffer` object was handled incorrectly.  This
commit corrects the handling of `tir::Buffer` arguments when
scheduling, and adds a unit test to validate this behavior.
vinx13 pushed a commit that referenced this pull request Sep 19, 2022
…2816)

Follow-up from #11269, which allowed
schedule arguments of the buffer to be transformed to be specified as
a string, or as a `tir::Buffer`.  The string handling worked
correctly, but the `tir::Buffer` object was handled incorrectly.  This
commit corrects the handling of `tir::Buffer` arguments when
scheduling, and adds a unit test to validate this behavior.
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
…ache#12816)

Follow-up from apache#11269, which allowed
schedule arguments of the buffer to be transformed to be specified as
a string, or as a `tir::Buffer`.  The string handling worked
correctly, but the `tir::Buffer` object was handled incorrectly.  This
commit corrects the handling of `tir::Buffer` arguments when
scheduling, and adds a unit test to validate this behavior.
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.

3 participants