sunggg commented on code in PR #14079: URL: https://github.com/apache/tvm/pull/14079#discussion_r1251313722
########## tests/python/relax/test_transform_canonicalize_bindings.py: ########## @@ -0,0 +1,224 @@ +# 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. + +import tvm +import tvm.script +import tvm.testing +import pytest +from tvm import relax +from tvm.ir.base import assert_structural_equal +from tvm.script import relax as R, tir as T + + +def test_simple_assignments(): + @tvm.script.ir_module + class TestChainAssignments: + @R.function + def main(x: R.Tensor): + y = x + z = y + q = z + p = q + o = p + return o + + # a little annoying to have these unused bindings around + # but they can be eliminated in a separate pass + @tvm.script.ir_module + class Expected: + @R.function + def main(x: R.Tensor): + y = x + z = x + q = x + p = x + o = x + return x + + new_mod = relax.transform.CanonicalizeBindings()(TestChainAssignments) + assert_structural_equal(new_mod, Expected) + + +def test_dataflow_block(): + @tvm.script.ir_module + class TestDataflowAssignments: + @R.function + def main(x: R.Tensor): + with R.dataflow(): + y = R.const(1) + z = y + o = z + p = o + m = p + n = m + R.output(n) + return n + + # a little annoying to have these unused bindings around + # but they can be eliminated in a separate pass + @tvm.script.ir_module + class Expected: + @R.function + def main(x: R.Tensor): + with R.dataflow(): + y = R.const(1) + z = y + o = y + p = y + m = y + # we can't get rid of n because it leaves the block Review Comment: Can we relax this and output `y` instead to remove `n`? cc. @slyubomirsky -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
