You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by ma...@apache.org on 2023/05/09 21:19:42 UTC

[tvm] branch main updated: [Testing] Use TVMScript's "name" argument for error messages (#14808)

This is an automated email from the ASF dual-hosted git repository.

masahi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 440aae25fb [Testing] Use TVMScript's "name" argument for error messages (#14808)
440aae25fb is described below

commit 440aae25fb8f3e85098f902711e16ab15c11112f
Author: Eric Lunderberg <Lu...@users.noreply.github.com>
AuthorDate: Tue May 9 16:19:35 2023 -0500

    [Testing] Use TVMScript's "name" argument for error messages (#14808)
    
    Prior to this commit, the `tvm.testing.CompareBeforeAfter` utility
    performed string replacement to define the names of the
    before/after/expected examples.  Since
    https://github.com/apache/tvm/pull/13934 allowed the name to be
    explicitly passed to the printer, this should be used instead.
---
 python/tvm/testing/utils.py | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/python/tvm/testing/utils.py b/python/tvm/testing/utils.py
index 399adf27e4..884a885fb2 100644
--- a/python/tvm/testing/utils.py
+++ b/python/tvm/testing/utils.py
@@ -2065,13 +2065,6 @@ class CompareBeforeAfter:
     def test_compare(self, before, expected, transform):
         """Unit test to compare the expected TIR PrimFunc to actual"""
 
-        def pprint(name, obj):
-            script = obj.script()
-            if isinstance(obj, tvm.IRModule):
-                return script.replace("class Module", f"class {name}")
-            else:
-                return script.replace("def func", f"def {name}")
-
         if inspect.isclass(expected) and issubclass(expected, Exception):
             with pytest.raises(expected):
                 after = transform(before)
@@ -2079,8 +2072,8 @@ class CompareBeforeAfter:
                 # This portion through pytest.fail isn't strictly
                 # necessary, but gives a better error message that
                 # includes the before/after.
-                before_str = pprint("before", before)
-                after_str = pprint("after", after)
+                before_str = before.script(name="before")
+                after_str = after.script(name="after")
 
                 pytest.fail(
                     msg=(
@@ -2095,9 +2088,9 @@ class CompareBeforeAfter:
             try:
                 tvm.ir.assert_structural_equal(after, expected)
             except ValueError as err:
-                before_str = pprint("before", before)
-                after_str = pprint("after", after)
-                expected_str = pprint("expected", expected)
+                before_str = before.script(name="before")
+                after_str = after.script(name="after")
+                expected_str = expected.script(name="expected")
                 raise ValueError(
                     f"TIR after transformation did not match expected:\n"
                     f"{before_str}\n{after_str}\n{expected_str}"