You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/07/18 18:19:38 UTC

[GitHub] [tvm] areusch commented on a diff in pull request #12063: [Pylint][microTVM] Applying Pylint rules to unittest folder

areusch commented on code in PR #12063:
URL: https://github.com/apache/tvm/pull/12063#discussion_r923678344


##########
tests/python/unittest/test_crt.py:
##########
@@ -210,28 +200,26 @@ def do_test():
         assert aot_executor.get_num_inputs() == 2
         assert aot_executor.get_num_outputs() == 1
 
-        A_np = np.array([[2, 3]], dtype="uint8")
-        B_np = np.array([[4, 7]], dtype="uint8")
+        a_np = np.array([[2, 3]], dtype="uint8")
+        b_np = np.array([[4, 7]], dtype="uint8")
 
-        A_data = aot_executor.get_input("a").copyfrom(A_np)
-        B_data = aot_executor.get_input("b").copyfrom(B_np)
+        aot_executor.get_input("a").copyfrom(a_np)
+        b_data = aot_executor.get_input("b").copyfrom(b_np)
 
         aot_executor.run()
 
         out = aot_executor.get_output(0)
         assert (out.numpy() == np.array([6, 10])).all()
 
-        B_np_new = np.array([[5, 8]])
-        aot_executor.set_input("b", B_np_new)
-        assert (B_data.numpy() == B_np_new).all()
+        b_np_new = np.array([[5, 8]])
+        aot_executor.set_input("b", b_np_new)
+        assert (b_data.numpy() == b_np_new).all()
 
     with _make_session(temp_dir, factory) as sess:
         do_test()
 
 
-enable_usmp, expect_exception = tvm.testing.parameters((True, True), (False, False))
-
-
+@pytest.mark.parametrize("enable_usmp,expect_exception", [(True, True), (False, False)])

Review Comment:
   @Lunderberg here's an instance where we needed to undo tvm.testing.parameters. i'd love to find way around doing that. we could consider making tvm.testing.parameters mutate the scope of its caller...i don't love that but it does handily solve the lint problems.



##########
tests/python/unittest/test_micro_transport.py:
##########
@@ -18,39 +18,45 @@
 """Tests for common micro transports."""
 
 import logging
-import sys
-import unittest
-
 import pytest
 
+import tvm
 import tvm.testing
 
+# Currently, there isn't a reasonable way to use @tvm.testing.fixture and not

Review Comment:
   possible to put this on line 36 to tie to just to transport?



##########
tests/lint/pylint.sh:
##########
@@ -19,8 +19,29 @@ set -euxo pipefail
 
 python3 -m pylint python/tvm --rcfile="$(dirname "$0")"/pylintrc
 python3 -m pylint vta/python/vta --rcfile="$(dirname "$0")"/pylintrc
-python3 -m pylint tests/python/unittest/test_tvmscript_type.py --rcfile="$(dirname "$0")"/pylintrc
 python3 -m pylint tests/python/contrib/test_cmsisnn --rcfile="$(dirname "$0")"/pylintrc
 python3 -m pylint tests/python/relay/aot/*.py --rcfile="$(dirname "$0")"/pylintrc
 python3 -m pylint tests/python/ci --rcfile="$(dirname "$0")"/pylintrc
 python3 -m pylint tests/python/integration/ --rcfile="$(dirname "$0")"/pylintrc
+
+# tests/python/unitest/
+python3 -m pylint tests/python/unittest/test_crt.py --rcfile="$(dirname "$0")"/pylintrc

Review Comment:
   just curious, can we create a single pylint command? e.g.
   ```
   python3 -m pylint \
       tests/python/unittest/test_micro_model_library_format.py \
       ... \
       --rcfile="$(dirname "$0")"/pylintrc



##########
tests/python/unittest/test_runtime_rpc.py:
##########
@@ -412,13 +430,14 @@ def check_error_handling():
 
 @tvm.testing.requires_rpc
 def test_rpc_return_ndarray():
+    """Test RPC return NDArray"""
     # start server
     server = rpc.Server(key="x1")
     client = rpc.connect("127.0.0.1", server.port, key="x1")
 
     m = client.get_function("rpc.test.remote_return_nd")
     get_arr = m("get_arr")
-    ref_count = m("ref_count")
+    ref_count = m("ref_count")  # pylint: disable=unused-variable

Review Comment:
   consider removing ref_count =



##########
tests/python/unittest/test_runtime_extension.py:
##########
@@ -32,17 +34,18 @@ def _tvm_handle(self):
 
 
 def test_dltensor_compatible():
+    "Test DLTensor compatibility"

Review Comment:
   nit: i think taht should be """ """-style comment, could you see if we're missing a pylint rule?



##########
tests/python/unittest/test_runtime_graph.py:
##########
@@ -82,6 +87,7 @@ def check_remote(server):
         np.testing.assert_equal(out.numpy(), a + 1)
 
     def check_sharing():
+        # pylint: disable=invalid-name

Review Comment:
   what if we just adjust good-names in pylintrc?



##########
tests/python/unittest/test_runtime_trace.py:
##########
@@ -61,8 +67,10 @@ def check_assign(dtype):
 
 
 def test_trace_expr_sum_generated():
+    """Test trace expression sum generated"""
+
     @tvm.register_func("tvm.tir.trace_callback3")
-    def trace_buffer(x):
+    def trace_buffer(_):  # pylint: disable=unused-variable

Review Comment:
   this is for the _?



##########
tests/python/unittest/test_runtime_rpc.py:
##########
@@ -191,9 +204,9 @@ def check(remote):
 
         remote.cpu().sync()
         with pytest.raises(AttributeError):
-            f3 = remote.system_lib()["notexist"]
+            func3 = remote.system_lib()["notexist"]  # pylint: disable=unused-variable

Review Comment:
   can we just delete the func3 =?



##########
tests/python/unittest/test_runtime_trace.py:
##########
@@ -87,11 +95,14 @@ def check_expr_sum(dtype):
 
 
 def test_trace_expr_sum_args():
+    """Test trace expression sum arguments"""
+
     @tvm.register_func("tvm.tir.trace_silent")
-    def silent(*args):
+    def silent(*_args):  # pylint: disable=unused-variable
         return
 
     def check_expr_sum(dtype):
+        # pylint: disable=invalid-name

Review Comment:
   consider removing in favor of updating good-names



##########
tests/python/unittest/test_runtime_module_export.py:
##########
@@ -153,13 +158,13 @@ def verify_json_import_dso(obj_format):
             f.write(subgraph_json)
 
         # Get Json and module.
-        A = te.placeholder((1024,), name="A")
-        B = te.compute(A.shape, lambda *i: A(*i) + 1.0, name="B")
-        s = te.create_schedule(B.op)
-        f = tvm.build(s, [A, B], "llvm", name="myadd")
+        a = te.placeholder((1024,), name="a")
+        b = te.compute(a.shape, lambda *i: a(*i) + 1.0, name="b")
+        s = te.create_schedule(b.op)
+        f = tvm.build(s, [a, b], "llvm", name="myadd")
         try:
             ext_lib = tvm.runtime.load_module(subgraph_path, "examplejson")
-        except:
+        except:  # pylint: disable=bare-except

Review Comment:
   possible to add at least Exception here?



##########
tests/python/unittest/test_node_reflection.py:
##########
@@ -70,35 +74,40 @@ def test_make_smap():
 
 
 def test_make_node():
+    """Test make node"""
+    # pylint: disable=invalid-name
     x = tvm.ir.make_node("IntImm", dtype="int32", value=10, span=None)
     assert isinstance(x, tvm.tir.IntImm)
     assert x.value == 10
-    A = te.placeholder((10,), name="A")
-    AA = tvm.ir.make_node(
-        "Tensor", shape=A.shape, dtype=A.dtype, op=A.op, value_index=A.value_index
+    a = te.placeholder((10,), name="a")
+    aa = tvm.ir.make_node(
+        "Tensor", shape=a.shape, dtype=a.dtype, op=a.op, value_index=a.value_index
     )
-    assert AA.op == A.op
-    assert AA.value_index == A.value_index
+    assert aa.op == a.op
+    assert aa.value_index == a.value_index
 
-    y = tvm.ir.make_node("IntImm", dtype=tvm.runtime.String("int32"), value=10, span=None)
+    tvm.ir.make_node("IntImm", dtype=tvm.runtime.String("int32"), value=10, span=None)
 
 
 def test_make_sum():
-    A = te.placeholder((2, 10), name="A")
+    # pylint: disable=invalid-name
+    a = te.placeholder((2, 10), name="a")
     k = te.reduce_axis((0, 10), "k")
-    B = te.compute((2,), lambda i: te.sum(A[i, k], axis=k), name="B")
-    json_str = tvm.ir.save_json(B)
-    BB = tvm.ir.load_json(json_str)
-    assert B.op.body[0].combiner is not None
-    assert BB.op.body[0].combiner is not None
+    b = te.compute((2,), lambda i: te.sum(a[i, k], axis=k), name="b")
+    json_str = tvm.ir.save_json(b)
+    bb = tvm.ir.load_json(json_str)
+    assert b.op.body[0].combiner is not None
+    assert bb.op.body[0].combiner is not None
 
 
 def test_env_func():
+    """Test environment function"""
+
     @tvm.register_func("test.env_func")
-    def test(x):
+    def test(x):  # pylint: disable=unused-variable

Review Comment:
   why's this needed?



##########
tests/python/unittest/test_runtime_rpc.py:
##########
@@ -302,15 +318,15 @@ def check_minrpc():
         a = tvm.nd.array(np.random.uniform(size=102).astype(A.dtype), dev)
         b = tvm.nd.array(np.zeros(102, dtype=A.dtype), dev)
         time_f = f1.time_evaluator("myadd", remote.cpu(0), number=1)
-        cost = time_f(a, b).mean
+        cost = time_f(a, b).mean  # pylint: disable=unused-variable

Review Comment:
   can we just rm cost =?



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