Fix infercorrect layout in Layoutrewrite and improve naming. - #12007
Merged
Conversation
lazycal
force-pushed
the
Fix-layoutrewriter
branch
from
July 4, 2022 19:26
8248426 to
fa8f026
Compare
lazycal
marked this pull request as ready for review
July 5, 2022 04:17
Contributor
Author
|
To reproduce the problem, run the following code: import tvm
from tvm import relay
from tvm.relay.transform import InferType
@tvm.instrument.pass_instrument
class PrintIR:
"""Print the name of the pass, the IR, only before passes execute."""
def __init__(self, print_mod=True, show_meta_data=False) -> None:
self.pass_cnt = 0
self.print_mod = print_mod
self.show_meta_data = show_meta_data
def run_before_pass(self, mod, info):
with tvm.transform.PassContext(instruments=[]):
global prev_mod
if self.print_mod:
print(relay.transform.InferType()(mod))
print('>' * 40, f'Running Pass#{self.pass_cnt}:', info)
self.pass_cnt += 1
x = relay.var("x", shape=(1, 1, 1, 1))
y = relay.image.resize2d(x, (2, 4))
z = relay.mean(y, axis=3)
a = relay.image.resize1d(z, (1,))
func = relay.Function((x,), a)
mod = tvm.IRModule.from_expr(func)
print(InferType()(mod))
with tvm.transform.PassContext(opt_level=4, instruments=[PrintIR()]):
relay.create_executor("graph", mod).evaluate()
print('pass') |
masahi
approved these changes
Jul 6, 2022
blackkker
pushed a commit
to blackkker/tvm
that referenced
this pull request
Jul 7, 2022
…12007) * Fix infercorrect layout in layoutrewrite. * Compatibility issue. * Fix lint. * Better naming and detailed comments. * Add unittest.
masahi
pushed a commit
to masahi/tvm
that referenced
this pull request
Jul 15, 2022
…12007) * Fix infercorrect layout in layoutrewrite. * Compatibility issue. * Fix lint. * Better naming and detailed comments. * Add unittest.
mikeseven
pushed a commit
to mikeseven/tvm
that referenced
this pull request
Sep 27, 2023
…12007) * Fix infercorrect layout in layoutrewrite. * Compatibility issue. * Fix lint. * Better naming and detailed comments. * Add unittest.
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
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.
This model
fails with error
Check failed: (tir::BijectiveLayout(new_src_layout, dst_layout).defined()) is false: Cannot insert layout transform because there are inconvertible layouts: NCW v.s. NCH. This should be a bug introduced in #10118. This line 7805d6f#diff-c3bb97b7e813244d6dae39925cc10bb9d50e8b7a280556b423068b3705f9f114R363 fixes it.In short, there should be no layout rewriting here since no conv etc. are used. But when the pass is checking resize1d, the previous code do not pass consistent layouts for the argument
old_in_layoutsfor the two calls ofResizeInferCorrectLayout(the first time NCH fromold_intvm/src/relay/transforms/transform_layout.h
Line 341 in ef08c36
old_in_2tvm/src/relay/transforms/transform_layout.h
Line 363 in ef08c36
This PR also improves the naming based on suggestions from @masahi in #10118, as well as adds several comments and logging statements to help people understand. (Hope this helps you understand that change better too @masahi :-)).