You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "sunggg (via GitHub)" <gi...@apache.org> on 2023/08/10 03:30:56 UTC

[GitHub] [tvm] sunggg commented on a diff in pull request #15509: [Unity] Implement relax.Function.bind_symbolic_vars

sunggg commented on code in PR #15509:
URL: https://github.com/apache/tvm/pull/15509#discussion_r1289500660


##########
tests/python/relax/test_bind_symbolic_vars.py:
##########
@@ -0,0 +1,205 @@
+# 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 pytest
+
+import tvm
+import tvm.testing
+from tvm.script import relax as R, tir as T
+
+replace_by_tir_var = tvm.testing.parameter(
+    by_dict={"replace-by-string": False, "replace-by-tir-var": True}
+)
+
+
+def test_bind_static_value(replace_by_tir_var):
+    """Symbolic vars may be replaced
+
+    The replaced variables may be given either as strings, or as TIR variables
+    """
+
+    @R.function(private=True)
+    def before(A: R.Tensor(("M", "K")), B: R.Tensor(("K", "N"))) -> R.Tensor(("M", "N")):
+        return R.matmul(A, B)
+
+    @R.function(private=True)
+    def expected(A: R.Tensor((128, 64)), B: R.Tensor((64, 32))) -> R.Tensor((128, 32)):
+        return R.matmul(A, B)
+
+    if replace_by_tir_var:
+        M, K = before.params[0].struct_info.shape
+        _, N = before.params[1].struct_info.shape
+        symbolic_var_map = {M: 128, K: 64, N: 32}
+    else:
+        symbolic_var_map = {"M": 128, "K": 64, "N": 32}
+
+    after = before.bind_symbolic_vars(symbolic_var_map)
+    tvm.ir.assert_structural_equal(expected, after)
+
+
+def test_error_with_duplicate_var_names():
+    """Duplicate variable names may not be replaced by string

Review Comment:
   I'm surprised to see this case passing the well_formed check. I think this should be filtered before any pass is applied, because this seems incorrect to me. 



-- 
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