Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pylint][microTVM] Applying Pylint rules to unittest folder #12063

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

alanmacd
Copy link
Contributor

@alanmacd alanmacd commented Jul 12, 2022

Apply Pylint to the following files for issue #11414

  • tests/python/unittest/test_crt.py
  • tests/python/unittest/test_micro_model_library_format.py
  • tests/python/unittest/test_micro_project_api.py
  • tests/python/unittest/test_micro_transport.py
  • tests/python/unittest/test_node_reflection.py
  • tests/python/unittest/test_runtime_container.py
  • tests/python/unittest/test_runtime_error.py
  • tests/python/unittest/test_runtime_extension.py
  • tests/python/unittest/test_runtime_graph.py
  • tests/python/unittest/test_runtime_graph_cuda_graph.py
  • tests/python/unittest/test_runtime_graph_debug.py
  • tests/python/unittest/test_runtime_measure.py
  • tests/python/unittest/test_runtime_module_based_interface.py
  • tests/python/unittest/test_runtime_module_export.py
  • tests/python/unittest/test_runtime_module_load.py
  • tests/python/unittest/test_runtime_profiling.py
  • tests/python/unittest/test_runtime_rpc.py
  • tests/python/unittest/test_runtime_trace.py
  • tests/python/unittest/test_runtime_vm_profiler.py

Notes:

  • retained some variable names when it would either make code less readable or there were confusing redundant names that need deeper level of inspection or refactoring
  • some tvm.testing functions remain problematic
  • whitelisted variable names seem arbitrary, e.g. x & y are allowed but not z?
  • some of these files require much more effort than anticipated, (apologies for the monster-PR), I wonder if we should scan them all and rank from least to most issues to maximize efforts

@areusch @Mousius

cc @gromero @mehrdadh

Copy link
Contributor

@areusch areusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @alanmacd , left some comments

tests/lint/pylint.sh Outdated Show resolved Hide resolved
enable_usmp, expect_exception = tvm.testing.parameters((True, True), (False, False))


@pytest.mark.parametrize("enable_usmp,expect_exception", [(True, True), (False, False)])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

import tvm.testing

# Currently, there isn't a reasonable way to use @tvm.testing.fixture and not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible to put this on line 36 to tie to just to transport?

tests/python/unittest/test_node_reflection.py Show resolved Hide resolved
@@ -32,17 +34,18 @@ def _tvm_handle(self):


def test_dltensor_compatible():
"Test DLTensor compatibility"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, yes that was a typo. I also confirmed pylint doesn't catch triple quote vs one quote strings, only catches if docstring is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just delete the func3 =?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know if we wanted to change functionality of test, i.e. why is this here, would that throw an exception if something was broken? or is it just abandoned code?

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just rm cost =?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I wasn't sure whether to change functionality of test, although in this case probably fine to do so, I figured marking it will flag it for future test developers who are more familiar with code to decide. This one's probably pretty safe to delete though.

# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider removing ref_count =

tests/python/unittest/test_runtime_trace.py Show resolved Hide resolved
tests/python/unittest/test_runtime_trace.py Outdated Show resolved Hide resolved
@areusch areusch added needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it and removed needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it labels Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants