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] Making frontend tests pylint compliant [part 1] #12028

Merged
merged 112 commits into from Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 107 commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
52c3ba1
[CI] Apply linting rules to tf tests
blackkker Jul 7, 2022
e17708e
[CI] Apply linting rules to tflite tests
blackkker Jul 7, 2022
8aeb47b
[CI] Apply linting rules to coreml tests
blackkker Jun 17, 2022
0d37d8f
[CI] Apply linting rules to caffe tests
blackkker Jun 14, 2022
b0b8755
[CI] Apply linting rules to caffe2 tests
blackkker Jul 7, 2022
ab9c9e2
reformat by black
blackkker Jul 7, 2022
6e15867
reformat by black
blackkker Jul 7, 2022
f94842a
[CI] Apply linting rules to coreml tests
blackkker Jul 7, 2022
e2e33d5
[CI] Apply linting rules to darknet tests
blackkker Jul 7, 2022
6b8db80
Update tests/python/frontend/coreml/test_forward.py
blackkker Jul 7, 2022
034e20a
Update tests/python/frontend/tflite/test_forward.py
blackkker Jul 7, 2022
4fa9ad0
Update tests/python/frontend/coreml/test_forward.py
blackkker Jul 7, 2022
ef3c43d
Update tests/python/frontend/tflite/test_forward.py
blackkker Jul 7, 2022
04f45b9
fix test errors
blackkker Jul 7, 2022
54dd2df
fix ci test errors
blackkker Jul 7, 2022
736d14c
[CI] Apply linting rules to keras tests
blackkker Jul 8, 2022
a1a1c55
[CI] Apply linting rules to oneflow tests
blackkker Jul 8, 2022
d940299
[CI] Apply linting rules to onnx tests
blackkker Jul 8, 2022
35c97ec
replace with tvm.testing.main()
blackkker Jul 13, 2022
3f4cc01
fix conflict
blackkker Jul 13, 2022
bcf23c8
Update as @areusch suggest
blackkker Jul 13, 2022
f41e8f0
pylint pytorch/test_forward.py
blackkker Jul 13, 2022
94c9c13
Update as @areusch suggest
blackkker Jul 26, 2022
9eb3f28
reformat by black
blackkker Jul 28, 2022
502b300
fix redefined-outer-name lint errors
blackkker Jul 28, 2022
d870f5d
remove rules
blackkker Jul 28, 2022
a6560d7
remove rules & fix pylint errors
blackkker Jul 28, 2022
ec4fa12
Remove all unused_var and fix other pylint errors
blackkker Jul 28, 2022
0124341
reformatted by black
blackkker Jul 28, 2022
de1b9a5
[CI] Apply linting rules to onnx tests
blackkker Jul 28, 2022
dff98ba
Disable unused-argument is for some unused-argument in function can n…
blackkker Jul 28, 2022
043ea1c
Fix ci errors
blackkker Jul 28, 2022
9e8a468
reformatted by black
blackkker Jul 28, 2022
93c0494
Fix ci errors
blackkker Jul 29, 2022
c6e938b
Fix invalid-name/unused-variable,redefined-builtin
blackkker Jul 29, 2022
b122e38
[CI] Apply linting rules to caffe tests
blackkker Jul 29, 2022
3828f7b
[CI] Apply linting rules to darknet tests
blackkker Jul 29, 2022
bd12410
[CI] Apply linting rules to pytorch tests
blackkker Jul 29, 2022
2c05b12
[CI] Apply linting rules to tflite tests
blackkker Jul 29, 2022
943965c
reformat by black
blackkker Jul 29, 2022
a2df6ce
[Pylint] Making frontend tests pylint compliant Part 1 of N
blackkker Jul 29, 2022
56697fa
Fix ci errors
blackkker Jul 29, 2022
1cae4bd
Fix invalid-name pylint errors
blackkker Jul 29, 2022
45b2d39
Fix invalid-name pylint errors
blackkker Jul 29, 2022
611a40e
Disabale temporarily
blackkker Jul 29, 2022
f0f745d
Fix dangerous-default-value
blackkker Jul 29, 2022
00efafc
Fix typo errors
blackkker Jul 29, 2022
4dcfe09
Fix ci errors
blackkker Jul 29, 2022
9cf4dac
[CI] Apply linting rules to tensorflow tests
blackkker Aug 1, 2022
4ffdb30
Fix dangerous-default-value
blackkker Aug 3, 2022
bc0793d
Fix ungrouped-imports
blackkker Aug 3, 2022
8fd3764
[CI] Apply linting rules to tf tests
blackkker Jul 7, 2022
7199127
[CI] Apply linting rules to tflite tests
blackkker Jul 7, 2022
31bdaea
[CI] Apply linting rules to coreml tests
blackkker Jun 17, 2022
9522223
[CI] Apply linting rules to caffe tests
blackkker Jun 14, 2022
336fba2
[CI] Apply linting rules to caffe2 tests
blackkker Jul 7, 2022
78c1099
reformat by black
blackkker Jul 7, 2022
126d1bb
reformat by black
blackkker Jul 7, 2022
52b9153
[CI] Apply linting rules to coreml tests
blackkker Jul 7, 2022
6c715b4
[CI] Apply linting rules to darknet tests
blackkker Jul 7, 2022
908ed28
Update tests/python/frontend/coreml/test_forward.py
blackkker Jul 7, 2022
51ab028
Update tests/python/frontend/tflite/test_forward.py
blackkker Jul 7, 2022
81c2750
Update tests/python/frontend/coreml/test_forward.py
blackkker Jul 7, 2022
9390cb6
Update tests/python/frontend/tflite/test_forward.py
blackkker Jul 7, 2022
ddd2b2b
fix test errors
blackkker Jul 7, 2022
a0cfc67
fix ci test errors
blackkker Jul 7, 2022
bf88603
[CI] Apply linting rules to keras tests
blackkker Jul 8, 2022
4a77979
[CI] Apply linting rules to oneflow tests
blackkker Jul 8, 2022
f33905f
[CI] Apply linting rules to onnx tests
blackkker Jul 8, 2022
cd86891
replace with tvm.testing.main()
blackkker Jul 13, 2022
2a4a559
fix conflict
blackkker Jul 13, 2022
9651514
Update as @areusch suggest
blackkker Jul 13, 2022
f0c1d0c
pylint pytorch/test_forward.py
blackkker Jul 13, 2022
b6e561e
Update as @areusch suggest
blackkker Jul 26, 2022
0092dbb
reformat by black
blackkker Jul 28, 2022
75aaee7
fix redefined-outer-name lint errors
blackkker Jul 28, 2022
c1f459e
remove rules
blackkker Jul 28, 2022
92f4114
remove rules & fix pylint errors
blackkker Jul 28, 2022
37815c5
Remove all unused_var and fix other pylint errors
blackkker Jul 28, 2022
89e7b0e
reformatted by black
blackkker Jul 28, 2022
454189e
[CI] Apply linting rules to onnx tests
blackkker Jul 28, 2022
86d475c
Disable unused-argument is for some unused-argument in function can n…
blackkker Jul 28, 2022
6660b1d
Fix ci errors
blackkker Jul 28, 2022
0b2d83f
reformatted by black
blackkker Jul 28, 2022
880b7f6
Fix ci errors
blackkker Jul 29, 2022
11b2a60
Fix invalid-name/unused-variable,redefined-builtin
blackkker Jul 29, 2022
2501ce0
[CI] Apply linting rules to caffe tests
blackkker Jul 29, 2022
f979f2f
[CI] Apply linting rules to darknet tests
blackkker Jul 29, 2022
16484ed
[CI] Apply linting rules to pytorch tests
blackkker Jul 29, 2022
5f906ee
[CI] Apply linting rules to tflite tests
blackkker Jul 29, 2022
a147937
reformat by black
blackkker Jul 29, 2022
e9abd84
[Pylint] Making frontend tests pylint compliant Part 1 of N
blackkker Jul 29, 2022
614f34b
Fix ci errors
blackkker Jul 29, 2022
b6cd734
Fix invalid-name pylint errors
blackkker Jul 29, 2022
42026ae
Fix invalid-name pylint errors
blackkker Jul 29, 2022
9e00554
Disabale temporarily
blackkker Jul 29, 2022
146ab4d
Fix dangerous-default-value
blackkker Jul 29, 2022
73ec6ab
Fix typo errors
blackkker Jul 29, 2022
d5d9e91
Fix ci errors
blackkker Jul 29, 2022
9bda0d6
[CI] Apply linting rules to tensorflow tests
blackkker Aug 1, 2022
3a49e23
Fix dangerous-default-value
blackkker Aug 3, 2022
8bcae5a
Fix ungrouped-imports
blackkker Aug 3, 2022
3176f42
Merge branch 'pylint_copy' of https://github.com/blackkker/tvm into p…
blackkker Aug 3, 2022
225f5e6
Fix boolean value of Tensor with more than one value is ambiguous
blackkker Aug 3, 2022
9bd5189
Fix 'NoneType' object has no attribute 'shape'
blackkker Aug 3, 2022
56e6d04
Fix boolean value of Tensor with more than one value is ambiguous
blackkker Aug 3, 2022
de4fd9c
Merge branch 'main' into pylint_copy
areusch Aug 11, 2022
5fba4ab
reformatted by black
blackkker Aug 11, 2022
258dc72
[CI] Apply linting rules to caffe tests
blackkker Aug 11, 2022
6c48c54
Fix dangerous-default-value
blackkker Aug 11, 2022
d11c25f
Fix conflict & fix pylint error
blackkker Aug 11, 2022
c26c82d
restore
blackkker Aug 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/lint/pylint.sh
Expand Up @@ -40,3 +40,16 @@ python3 -m pylint tests/python/contrib/test_hexagon/test_models.py --rcfile="$(d
python3 -m pylint tests/python/contrib/test_hexagon/test_run_unit_tests.py --rcfile="$(dirname "$0")"/pylintrc
python3 -m pylint tests/python/contrib/test_hexagon/test_thread_pool.py --rcfile="$(dirname "$0")"/pylintrc
python3 -m pylint tests/python/contrib/test_hexagon/test_usmp.py --rcfile="$(dirname "$0")"/pylintrc

# tests/python/frontend tests
python3 -m pylint tests/python/frontend/caffe/test_forward.py --rcfile="$(dirname "$0")"/pylintrc
python3 -m pylint tests/python/frontend/caffe2/*.py --rcfile="$(dirname "$0")"/pylintrc
python3 -m pylint tests/python/frontend/darknet/test_forward.py --rcfile="$(dirname "$0")"/pylintrc
python3 -m pylint tests/python/frontend/coreml/*.py --rcfile="$(dirname "$0")"/pylintrc
python3 -m pylint tests/python/frontend/keras/test_forward.py --rcfile="$(dirname "$0")"/pylintrc
python3 -m pylint tests/python/frontend/darknet/test_forward.py --rcfile="$(dirname "$0")"/pylintrc
python3 -m pylint tests/python/frontend/oneflow/*.py --rcfile="$(dirname "$0")"/pylintrc
python3 -m pylint tests/python/frontend/tensorflow/test_forward.py --rcfile="$(dirname "$0")"/pylintrc
python3 -m pylint tests/python/frontend/pytorch/test_forward.py --rcfile="$(dirname "$0")"/pylintrc
python3 -m pylint tests/python/frontend/tflite/test_forward.py --rcfile="$(dirname "$0")"/pylintrc

77 changes: 22 additions & 55 deletions tests/python/frontend/caffe/test_forward.py
Expand Up @@ -21,14 +21,9 @@
This article is a test script to test Caffe operator with Relay.
"""
import os

os.environ["GLOG_minloglevel"] = "2"
import sys
import logging

logging.basicConfig(level=logging.ERROR)

import numpy as np

from google.protobuf import text_format
import caffe
from caffe import layers as L, params as P
Expand All @@ -37,9 +32,13 @@
import tvm
import tvm.testing
from tvm import relay
from tvm.contrib import utils, graph_executor
from tvm.contrib import graph_executor
from tvm.contrib.download import download_testdata

os.environ["GLOG_minloglevel"] = "2"
blackkker marked this conversation as resolved.
Show resolved Hide resolved

logging.basicConfig(level=logging.ERROR)

CURRENT_DIR = os.path.join(os.path.expanduser("~"), ".tvm_test_data", "caffe_test")

#######################################################################
Expand All @@ -57,7 +56,8 @@ def _list_to_str(ll):
"""Convert list or tuple to str, separated by underline."""
if isinstance(ll, (tuple, list)):
tmp = [str(i) for i in ll]
return "_".join(tmp)
res = "_".join(tmp)
return res


def _gen_filename_str(op_name, data_shape, *args, **kwargs):
Expand Down Expand Up @@ -137,8 +137,8 @@ def _miso_op(data_list, func, *args, **kwargs):
"""Create multi input and single output Caffe op"""
n = caffe.NetSpec()
if not isinstance(data_list, (tuple, list)):
raise TypeError("Need tuple or list but get {}".format(type(data_list)))
input_list = list()
raise TypeError(f"Need tuple or list but get {type(data_list)}")
input_list = []
for idx, data in enumerate(data_list):
n["data" + str(idx)] = L.Input(input_param={"shape": {"dim": list(data.shape)}})
input_list.append(n["data" + str(idx)])
Expand Down Expand Up @@ -166,7 +166,7 @@ def _run_caffe(data, proto_file, blob_file):
net.blobs["data"].data[...] = data
out = net.forward()

caffe_output = list()
caffe_output = []
for i in range(len(out.keys())):
if "output" + str(i) not in out.keys():
caffe_output.clear()
Expand All @@ -187,8 +187,8 @@ def _run_tvm(data, proto_file, blob_file):
with open(blob_file, "rb") as f:
init_net.ParseFromString(f.read())

shape_dict = dict()
dtype_dict = dict()
shape_dict = {}
dtype_dict = {}
if isinstance(data, (tuple, list)):
for idx, d in enumerate(data):
shape_dict["data" + str(idx)] = d.shape
Expand All @@ -213,30 +213,30 @@ def _run_tvm(data, proto_file, blob_file):
m.set_input("data", tvm.nd.array(data.astype(dtype)))
# execute
m.run()
tvm_output = list()
tvm_output = []
# get outputs
for i in range(m.get_num_outputs()):
tvm_output.append(m.get_output(i).numpy())
return tvm_output


def _compare_caffe_tvm(caffe_out, tvm_out, is_network=False):
for i in range(len(caffe_out)):
for i, _ in enumerate(caffe_out):
if is_network:
caffe_out[i] = caffe_out[i][:1]
tvm.testing.assert_allclose(caffe_out[i], tvm_out[i], rtol=1e-5, atol=1e-5)


def _test_op(data, func_op, op_name, **kwargs):
"""Single op testing pipline."""
shape_list = list()
shape_list = []
if isinstance(data, (list, tuple)):
n = _miso_op(data, func_op, **kwargs)
for d in data:
shape_list.extend(list(d.shape))
else:
output_num = 1
if "ntop" in kwargs.keys():
if "ntop" in kwargs:
output_num = kwargs["ntop"]
if output_num == 1:
n = _siso_op(data, func_op, **kwargs)
Expand Down Expand Up @@ -961,8 +961,9 @@ def _test_embed(data, **kwargs):


def test_forward_Embed():
"""Embed"""
k = 20
data = [i for i in range(k)]
data = list(i for i in range(k))
np.random.shuffle(data)
# dimension is 1
data = np.asarray(data)
Expand Down Expand Up @@ -1083,7 +1084,7 @@ def _test_alexnet(data):
data_process = data_process.astype(np.float32)

proto_file_url = (
"https://github.com/BVLC/caffe/raw/master/models/" "bvlc_alexnet/deploy.prototxt"
"https://github.com/BVLC/caffe/raw/master/models/" + "bvlc_alexnet/deploy.prototxt"
)
blob_file_url = "http://dl.caffe.berkeleyvision.org/bvlc_alexnet.caffemodel"
proto_file = download_testdata(proto_file_url, "alexnet.prototxt", module="model")
Expand Down Expand Up @@ -1144,7 +1145,7 @@ def _test_inceptionv1(data):
data_process = data_process.astype(np.float32)

proto_file_url = (
"https://github.com/BVLC/caffe/raw/master/models" "/bvlc_googlenet/deploy.prototxt"
"https://github.com/BVLC/caffe/raw/master/models" + "/bvlc_googlenet/deploy.prototxt"
)
blob_file_url = "http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel"
proto_file = download_testdata(proto_file_url, "inceptionv1.prototxt", module="model")
Expand All @@ -1159,38 +1160,4 @@ def test_forward_Inceptionv1():


if __name__ == "__main__":
# NN
test_forward_Convolution()
test_forward_Deconvolution()
test_forward_Dropout()
test_forward_LRN()
test_forward_Pooling()
test_forward_Scale()
test_forward_InnerProduct()
test_forward_BatchNorm()

# Elemwise
test_forward_Eltwise()

# Activation
test_forward_PReLU()
test_forward_ReLU()
test_forward_Sigmoid()
test_forward_Softmax()
test_forward_TanH()

# Reshape
test_forward_Reshape()
test_forward_Flatten()
test_forward_Reduction()

# Math
test_forward_Concat()
test_forward_Crop()
test_forward_Slice()

# End to End
test_forward_Mobilenetv2()
test_forward_Alexnet()
test_forward_Resnet50()
test_forward_Inceptionv1()
tvm.testing.main()
2 changes: 1 addition & 1 deletion tests/python/frontend/caffe2/model_zoo/__init__.py
Expand Up @@ -20,8 +20,8 @@
import os
import sys
import importlib
from . import squeezenet
from caffe2.python.models.download import ModelDownloader
from . import squeezenet

models = [
"squeezenet",
Expand Down
10 changes: 5 additions & 5 deletions tests/python/frontend/caffe2/model_zoo/squeezenet.py
Expand Up @@ -31,10 +31,10 @@

# Helpers
def _make_fire(net, squeeze_channels, expand1x1_channels, expand3x3_channels, prefix=""):
net = _make_fire_conv(net, squeeze_channels, 1, 0, "%s/squeeze1x1" % prefix)
net = _make_fire_conv(net, squeeze_channels, 1, 0, f"{prefix}/squeeze1x1")

left = _make_fire_conv(net, expand1x1_channels, 1, 0, "%s/expand1x1" % prefix)
right = _make_fire_conv(net, expand3x3_channels, 3, 1, "%s/expand3x3" % prefix)
left = _make_fire_conv(net, expand1x1_channels, 1, 0, f"{prefix}/expand1x1")
right = _make_fire_conv(net, expand3x3_channels, 3, 1, f"{prefix}/expand3x3")
# NOTE : Assume NCHW layout here
net = relay.concatenate((left, right), axis=1)
return net
Expand All @@ -43,12 +43,12 @@ def _make_fire(net, squeeze_channels, expand1x1_channels, expand3x3_channels, pr
def _make_fire_conv(net, channels, kernel_size, padding=0, prefix=""):
net = relay.nn.conv2d(
net,
relay.var("%s_weight" % prefix),
relay.var(f"{prefix}_weight"),
channels=channels,
kernel_size=(kernel_size, kernel_size),
padding=(padding, padding),
)
net = relay.nn.bias_add(net, relay.var("%s_bias" % prefix))
net = relay.nn.bias_add(net, relay.var(f"{prefix}_bias"))
net = relay.nn.relu(net)
return net

Expand Down
26 changes: 15 additions & 11 deletions tests/python/frontend/caffe2/test_forward.py
Expand Up @@ -14,15 +14,21 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""
Caffe2 testcases
====================
This article is a test script to test Caffe2 operator with Relay.
"""
from collections import namedtuple
import numpy as np

from caffe2.python import workspace, core
from caffe2.proto import caffe2_pb2
from model_zoo import c2_squeezenet, c2_resnet50, c2_vgg19
import tvm
from tvm import te
from tvm.contrib import graph_executor
from tvm import relay
from model_zoo import c2_squeezenet, c2_resnet50, c2_vgg19
from caffe2.python import workspace, core
from caffe2.proto import caffe2_pb2
from collections import namedtuple

import tvm.testing


Expand Down Expand Up @@ -103,6 +109,7 @@ def test_forward_vgg19():

@tvm.testing.uses_gpu
def test_elementwise_add():
"""Elewise_add"""
data_shape = (1, 16, 9, 9)
init_net = caffe2_pb2.NetDef()
init_net.name = "test_init_net"
Expand Down Expand Up @@ -146,6 +153,7 @@ def test_elementwise_add():

@tvm.testing.uses_gpu
def test_elementwise_add_with_broadcast():
"""Elewise_add_with_broadcast"""
data_shape = (1, 16, 9, 9)
init_net = caffe2_pb2.NetDef()
init_net.name = "test_init_net"
Expand Down Expand Up @@ -190,6 +198,7 @@ def test_elementwise_add_with_broadcast():

@tvm.testing.uses_gpu
def test_normalize_yuv():
"""Normalize_yuv"""
data_shape = (1, 3, 96, 96)
init_net = caffe2_pb2.NetDef()
init_net.name = "test_init_net"
Expand Down Expand Up @@ -245,9 +254,4 @@ def test_normalize_yuv():


if __name__ == "__main__":
test_forward_squeezenet1_1()
test_forward_resnet50()
test_forward_vgg19()
test_elementwise_add()
test_elementwise_add_with_broadcast()
test_normalize_yuv()
tvm.testing.main()
8 changes: 6 additions & 2 deletions tests/python/frontend/coreml/model_zoo/__init__.py
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

"""coreml model zoo for testing purposes."""
import os
from PIL import Image
import numpy as np
Expand All @@ -36,7 +36,11 @@ def get_resnet50():


def get_cat_image():
url = "https://gist.githubusercontent.com/zhreshold/bcda4716699ac97ea44f791c24310193/raw/fa7ef0e9c9a5daea686d6473a62aacd1a5885849/cat.png"
"""Get cat image"""
url = (
"https://gist.githubusercontent.com/zhreshold/"
+ "bcda4716699ac97ea44f791c24310193/raw/fa7ef0e9c9a5daea686d6473a62aacd1a5885849/cat.png"
)
dst = "cat.png"
real_dst = download_testdata(url, dst, module="data")
img = Image.open(real_dst).resize((224, 224))
Expand Down