mehrdadh commented on code in PR #13046:
URL: https://github.com/apache/tvm/pull/13046#discussion_r994875455


##########
tests/python/relay/aot/test_cpp_aot.py:
##########
@@ -203,5 +203,44 @@ def test_pass_wrong_device_arg():
     # TODO write asserts for # and type of device.
 
 
+@pytest.mark.parametrize("target_kind", ["c", "llvm"])
+@pytest.mark.parametrize("input_name", ["input:0", "input@0", "input_0"])
+def test_aot_input_name_with_special_character(target_kind: str, input_name: 
str):
+    """Test name transforms in AOT for input names with special characters."""
+    dtype = "float32"
+    input_1 = relay.var(input_name, shape=(10, 5), dtype=dtype)
+    weight = relay.var("weight", shape=(1, 5), dtype=dtype)
+    output = relay.add(input_1, weight)
+    func = relay.Function([input_1, weight], output)
+
+    input_data = np.random.rand(10, 5).astype(dtype)
+    weight_data = np.random.rand(1, 5).astype(dtype)
+    expected_output = input_data + weight_data
+    params = {"weight": weight_data}
+
+    with tvm.transform.PassContext(opt_level=3, 
config={"tir.disable_vectorize": True}):
+        mod = tvm.relay.build(
+            tvm.IRModule.from_expr(func),
+            target=target_kind,
+            params=params,
+            executor=tvm.relay.backend.Executor("aot", {"interface-api": 
"packed"}),
+        )
+    temp_dir = tvm.contrib.utils.TempDirectory()
+    test_so_path = temp_dir / "test.so"
+    mod.export_library(test_so_path, cc="c++", options=["-std=gnu++17", "-g3", 
"-O0"])
+    # test both original name and transformed name
+    for name in ["input_0", input_name]:

Review Comment:
   I added both cases to check both sanitized name and original name works. The 
reason for checking sanitized name is that eventually we will add a check in 
relay.Var to not support special characters from the first place. That means in 
future if you have a model with input `input:0`, the generated relay module 
would convert it to `input_0` from the first place and if user take a look at 
the generated relay they might use `input_0` from the first place instead of 
the original name.
   let me what you think



-- 
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-unsubscr...@tvm.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to