-
Notifications
You must be signed in to change notification settings - Fork 58
[Transform] RewriteDataflowReshape to op and VMBuiltinLower handling #415
[Transform] RewriteDataflowReshape to op and VMBuiltinLower handling #415
Conversation
As discussed in tlc-pack#407 (comment), we update the behavior of pass RewriteDataflowReshape. In short, prior to this PR, the pass transforms calls of reshape PrimFunc in dataflow blocks to direct calls of runtime packed func “vm.builtin.reshape.” The consequence of this behavior is that the memory planning pass has to check the reshape op by string comparison of `ExternFunc.global_symbol`, which is not ideal. Therefore, this PR changes the RewriteDataflowReshape’s behavior, transforming calls of reshape PrimFunc to our high-level reshape op “relax.reshape,” and let the VMBuiltinLower pass to lowers the op to calls of “vm.builtin.reshape.”
5ff6b63
to
5c041c5
Compare
Unrelated, but the following line that assumes the callee of https://github.com/tlc-pack/relax/blob/relax/src/relax/transform/rewrite_dataflow_reshape.cc#L71 Can you add a check |
@masahi Thanks! Sorry it was my negligence. Will add in the next commit. |
@masahi Updated :-) |
We should probably document when in compilation this rewrite (and any other passes whose order is important) should happen, since there will be dependencies on it (like #407). |
1519bb9
to
3c79b61
Compare
@slyubomirsky Thanks! Added one note here relax/include/tvm/relax/transform.h Lines 113 to 115 in 3c79b61
relax/python/tvm/relax/transform/transform.py Lines 117 to 122 in 3c79b61
|
…415) * [Transform] RewriteDataflowReshape to op and VMBuiltinLower handling Priior to this PR, the pass transforms calls of reshape PrimFunc in dataflow blocks to direct calls of runtime packed func “vm.builtin.reshape.” The consequence of this behavior is that the memory planning pass has to check the reshape op by string comparison of `ExternFunc.global_symbol`, which is not ideal. Therefore, this PR changes the RewriteDataflowReshape’s behavior, transforming calls of reshape PrimFunc to our high-level reshape op “relax.reshape,” and let the VMBuiltinLower pass to lowers the op to calls of “vm.builtin.reshape.”
…415) * [Transform] RewriteDataflowReshape to op and VMBuiltinLower handling Priior to this PR, the pass transforms calls of reshape PrimFunc in dataflow blocks to direct calls of runtime packed func “vm.builtin.reshape.” The consequence of this behavior is that the memory planning pass has to check the reshape op by string comparison of `ExternFunc.global_symbol`, which is not ideal. Therefore, this PR changes the RewriteDataflowReshape’s behavior, transforming calls of reshape PrimFunc to our high-level reshape op “relax.reshape,” and let the VMBuiltinLower pass to lowers the op to calls of “vm.builtin.reshape.”
…(#415) * [Transform] RewriteDataflowReshape to op and VMBuiltinLower handling Priior to this PR, the pass transforms calls of reshape PrimFunc in dataflow blocks to direct calls of runtime packed func “vm.builtin.reshape.” The consequence of this behavior is that the memory planning pass has to check the reshape op by string comparison of `ExternFunc.global_symbol`, which is not ideal. Therefore, this PR changes the RewriteDataflowReshape’s behavior, transforming calls of reshape PrimFunc to our high-level reshape op “relax.reshape,” and let the VMBuiltinLower pass to lowers the op to calls of “vm.builtin.reshape.”
…(#415) * [Transform] RewriteDataflowReshape to op and VMBuiltinLower handling Priior to this PR, the pass transforms calls of reshape PrimFunc in dataflow blocks to direct calls of runtime packed func “vm.builtin.reshape.” The consequence of this behavior is that the memory planning pass has to check the reshape op by string comparison of `ExternFunc.global_symbol`, which is not ideal. Therefore, this PR changes the RewriteDataflowReshape’s behavior, transforming calls of reshape PrimFunc to our high-level reshape op “relax.reshape,” and let the VMBuiltinLower pass to lowers the op to calls of “vm.builtin.reshape.”
@masahi Hi Masa. Sorry that I didn’t think too much on your comment before. One quick question: why we use |
I don't know, and I wondered too. cc @sunggg who wrote the code below. relax/src/relax/transform/run_codegen.cc Line 84 in 83adb87
|
@masahi I just got a quick answer. Here we use We may need a dedicated op for |
As discussed in #407 (comment), we update the behavior of pass RewriteDataflowReshape.
In short, prior to this PR, the pass transforms calls of reshape PrimFunc in dataflow blocks to direct calls of runtime packed func “vm.builtin.reshape.” The consequence of this behavior is that the memory planning pass has to check the reshape op by string comparison of
ExternFunc.global_symbol
, which is not ideal.Therefore, this PR changes the RewriteDataflowReshape’s behavior, transforming calls of reshape PrimFunc to our high-level reshape op “relax.reshape,” and let the VMBuiltinLower pass to lowers the op to calls of “vm.builtin.reshape.”