You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "abhikran-quic (via GitHub)" <gi...@apache.org> on 2023/09/06 05:21:27 UTC
[GitHub] [tvm] abhikran-quic opened a new pull request, #15678: [UNITY][Pass] Optimize redundant layout transform ops
abhikran-quic opened a new pull request, #15678:
URL: https://github.com/apache/tvm/pull/15678
Relax `AlterOpImpl` pass introduces `layout_transform` operations. If the layouts match for consecutive `layout_transform` operations, they can be cancelled out. This pass tries to optimize redundant `transform_layout` operations.
This is also addressing P4 in https://github.com/apache/tvm/issues/14070
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on a diff in pull request #15678: [UNITY][Pass] Optimize redundant layout transform ops
Posted by "masahi (via GitHub)" <gi...@apache.org>.
masahi commented on code in PR #15678:
URL: https://github.com/apache/tvm/pull/15678#discussion_r1322614653
##########
python/tvm/relax/transform/optimize_layout_transform.py:
##########
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=invalid-name, unused-argument, redefined-argument-from-local
+"""Relax Optimize Layout Transform pass."""
+from tvm.ir.module import IRModule
+from tvm.ir.transform import PassContext
+from tvm.relax import Expr, Function
+from tvm.relax.dpl import is_op, rewrite_call, wildcard
+from . import function_pass
+
+
+@function_pass(opt_level=0)
+class OptimizeLayoutTransform:
Review Comment:
ok makes sense
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on a diff in pull request #15678: [UNITY][Pass] Optimize redundant layout transform ops
Posted by "masahi (via GitHub)" <gi...@apache.org>.
masahi commented on code in PR #15678:
URL: https://github.com/apache/tvm/pull/15678#discussion_r1318292315
##########
python/tvm/relax/transform/optimize_layout_transform.py:
##########
@@ -0,0 +1,147 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=invalid-name, unused-argument
+"""Relax Optimize Layout Transform pass."""
+from typing import Union
+import tvm
+from tvm import IRModule, relax
+from tvm.ir.transform import module_pass
+from tvm.relax.analysis import remove_all_unused
+from tvm.relax.expr_functor import mutator, PyExprMutator
+
+
+@mutator
+class OptimizeLayoutTranformMutator(PyExprMutator):
Review Comment:
Can we use the built-in pattern rewriter instead?
https://github.com/apache/tvm/blob/unity/python/tvm/relax/dpl/rewrite.py#L26-L28
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi merged pull request #15678: [UNITY][Pass] Optimize redundant layout transform ops
Posted by "masahi (via GitHub)" <gi...@apache.org>.
masahi merged PR #15678:
URL: https://github.com/apache/tvm/pull/15678
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] abhikran-quic commented on a diff in pull request #15678: [UNITY][Pass] Optimize redundant layout transform ops
Posted by "abhikran-quic (via GitHub)" <gi...@apache.org>.
abhikran-quic commented on code in PR #15678:
URL: https://github.com/apache/tvm/pull/15678#discussion_r1322336789
##########
python/tvm/relax/transform/optimize_layout_transform.py:
##########
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=invalid-name, unused-argument, redefined-argument-from-local
+"""Relax Optimize Layout Transform pass."""
+from tvm.ir.module import IRModule
+from tvm.ir.transform import PassContext
+from tvm.relax import Expr, Function
+from tvm.relax.dpl import is_op, rewrite_call, wildcard
+from . import function_pass
+
+
+@function_pass(opt_level=0)
+class OptimizeLayoutTransform:
Review Comment:
Even though the present solution is doing a Nop removal, the reason to name the pass as `OptimizeLayoutTransform` was to optimize two `layout_transform` operations into a single one when the index maps don't match.
Right now the implementation is optimizing redundant `layout_transform` operations when index_maps are matching which is Nop removal.
Eventually, we plan to extend this pass to converge two `transform_layout` operations into a single one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] abhikran-quic commented on a diff in pull request #15678: [UNITY][Pass] Optimize redundant layout transform ops
Posted by "abhikran-quic (via GitHub)" <gi...@apache.org>.
abhikran-quic commented on code in PR #15678:
URL: https://github.com/apache/tvm/pull/15678#discussion_r1322336789
##########
python/tvm/relax/transform/optimize_layout_transform.py:
##########
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=invalid-name, unused-argument, redefined-argument-from-local
+"""Relax Optimize Layout Transform pass."""
+from tvm.ir.module import IRModule
+from tvm.ir.transform import PassContext
+from tvm.relax import Expr, Function
+from tvm.relax.dpl import is_op, rewrite_call, wildcard
+from . import function_pass
+
+
+@function_pass(opt_level=0)
+class OptimizeLayoutTransform:
Review Comment:
The reason for keeping the name as `OptimizeLayoutTransform` was to optimize two `layout_transform` operations into a single one when the index maps don't match.
Right now the implementation is optimizing our redundant `layout_transform` operations when index_maps are matching.
Eventually, we plan to extend this pass to converge two `transform_layout` operations into a single one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] abhikran-quic commented on a diff in pull request #15678: [UNITY][Pass] Optimize redundant layout transform ops
Posted by "abhikran-quic (via GitHub)" <gi...@apache.org>.
abhikran-quic commented on code in PR #15678:
URL: https://github.com/apache/tvm/pull/15678#discussion_r1320788984
##########
python/tvm/relax/transform/optimize_layout_transform.py:
##########
@@ -0,0 +1,147 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=invalid-name, unused-argument
+"""Relax Optimize Layout Transform pass."""
+from typing import Union
+import tvm
+from tvm import IRModule, relax
+from tvm.ir.transform import module_pass
+from tvm.relax.analysis import remove_all_unused
+from tvm.relax.expr_functor import mutator, PyExprMutator
+
+
+@mutator
+class OptimizeLayoutTranformMutator(PyExprMutator):
Review Comment:
Alright. I understand the concern here. I will rewrite the pass as a function pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] abhikran-quic commented on pull request #15678: [UNITY][Pass] Optimize redundant layout transform ops
Posted by "abhikran-quic (via GitHub)" <gi...@apache.org>.
abhikran-quic commented on PR #15678:
URL: https://github.com/apache/tvm/pull/15678#issuecomment-1709501876
cc: @psrivas2 @masahi @junrushao
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] abhikran-quic commented on a diff in pull request #15678: [UNITY][Pass] Optimize redundant layout transform ops
Posted by "abhikran-quic (via GitHub)" <gi...@apache.org>.
abhikran-quic commented on code in PR #15678:
URL: https://github.com/apache/tvm/pull/15678#discussion_r1322336789
##########
python/tvm/relax/transform/optimize_layout_transform.py:
##########
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=invalid-name, unused-argument, redefined-argument-from-local
+"""Relax Optimize Layout Transform pass."""
+from tvm.ir.module import IRModule
+from tvm.ir.transform import PassContext
+from tvm.relax import Expr, Function
+from tvm.relax.dpl import is_op, rewrite_call, wildcard
+from . import function_pass
+
+
+@function_pass(opt_level=0)
+class OptimizeLayoutTransform:
Review Comment:
Even though the present solution is doing a Nop removal, The reason for keeping the name as `OptimizeLayoutTransform` was to optimize two `layout_transform` operations into a single one when the index maps don't match.
Right now the implementation is optimizing redundant `layout_transform` operations when index_maps are matching which is Nop removal.
Eventually, we plan to extend this pass to converge two `transform_layout` operations into a single one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on a diff in pull request #15678: [UNITY][Pass] Optimize redundant layout transform ops
Posted by "masahi (via GitHub)" <gi...@apache.org>.
masahi commented on code in PR #15678:
URL: https://github.com/apache/tvm/pull/15678#discussion_r1321896498
##########
python/tvm/relax/transform/optimize_layout_transform.py:
##########
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=invalid-name, unused-argument, redefined-argument-from-local
+"""Relax Optimize Layout Transform pass."""
+from tvm.ir.module import IRModule
+from tvm.ir.transform import PassContext
+from tvm.relax import Expr, Function
+from tvm.relax.dpl import is_op, rewrite_call, wildcard
+from . import function_pass
+
+
+@function_pass(opt_level=0)
+class OptimizeLayoutTransform:
Review Comment:
The name "OptimizeLayoutTransform" sounds too generic for the simple thing it does. I'd suggest introducing "RemoveNop" pass and add this pattern as a first step.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on a diff in pull request #15678: [UNITY][Pass] Optimize redundant layout transform ops
Posted by "masahi (via GitHub)" <gi...@apache.org>.
masahi commented on code in PR #15678:
URL: https://github.com/apache/tvm/pull/15678#discussion_r1319438923
##########
python/tvm/relax/transform/optimize_layout_transform.py:
##########
@@ -0,0 +1,147 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=invalid-name, unused-argument
+"""Relax Optimize Layout Transform pass."""
+from typing import Union
+import tvm
+from tvm import IRModule, relax
+from tvm.ir.transform import module_pass
+from tvm.relax.analysis import remove_all_unused
+from tvm.relax.expr_functor import mutator, PyExprMutator
+
+
+@mutator
+class OptimizeLayoutTranformMutator(PyExprMutator):
Review Comment:
Why do you need a module-based pass for this rewriting? I think our pattern rewriter works at the function level partly because that's where the actual rewriting happens.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] abhikran-quic commented on a diff in pull request #15678: [UNITY][Pass] Optimize redundant layout transform ops
Posted by "abhikran-quic (via GitHub)" <gi...@apache.org>.
abhikran-quic commented on code in PR #15678:
URL: https://github.com/apache/tvm/pull/15678#discussion_r1319339316
##########
python/tvm/relax/transform/optimize_layout_transform.py:
##########
@@ -0,0 +1,147 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=invalid-name, unused-argument
+"""Relax Optimize Layout Transform pass."""
+from typing import Union
+import tvm
+from tvm import IRModule, relax
+from tvm.ir.transform import module_pass
+from tvm.relax.analysis import remove_all_unused
+from tvm.relax.expr_functor import mutator, PyExprMutator
+
+
+@mutator
+class OptimizeLayoutTranformMutator(PyExprMutator):
Review Comment:
Thanks @masahi for sharing this.
I had gone through this earlier but I wasn't able to find a rewriter that can work on a complete IRModule. Hence, I implemented my own class.
Do you know of a function that can take IRModule and rewrite all the patterns of interest ?
If there is no such function, I can work on it. Basically it'll be a wrapper on top of `rewrite_call` to iterate over the whole graph.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org