Skip to content

Commit 19e8a47

Browse files
authored
Bump up python formatter yapf version (Samsung#13916)
This commit updates python formatter yapf to 0.40.2 and python code. Update documents and dockerfiles ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh <[email protected]>
1 parent 297e753 commit 19e8a47

File tree

132 files changed

+2016
-1558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+2016
-1558
lines changed

.github/workflows/check-format.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ jobs:
3030
python-version: '3.x'
3131

3232
# C format: clang-format-16
33-
# Python format: yapf==0.22.0
33+
# Python format: yapf==0.40.2
3434
- name: Install packages
3535
run: |
3636
sudo apt-get install -y gnupg2 software-properties-common
3737
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
3838
sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main"
3939
sudo apt-get update && sudo apt-get install -qqy clang-format-16
4040
python -m pip install --upgrade pip
41-
pip install yapf==0.22.0
41+
pip install yapf==0.40.2
4242
4343
- name: Check
4444
run: ./nnas format

.style.yapf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[style]
22
BASED_ON_STYLE = pep8
33
COLUMN_LIMIT = 90
4+
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = False

compiler/bcq-tools/generate_bcq_metadata.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,21 @@ def _get_parser():
3737
description=("Command line tool to generate metadata of BCQ nodes"))
3838

3939
# Input and output path.
40-
parser.add_argument(
41-
"-i",
42-
"--input_path",
43-
type=str,
44-
help="Full filepath of the input file.",
45-
required=True)
46-
parser.add_argument(
47-
"-o",
48-
"--output_path",
49-
type=str,
50-
help="Full filepath of the output file.",
51-
required=True)
52-
parser.add_argument(
53-
"-O",
54-
"--output_arrays",
55-
type=str,
56-
help="Original model output arrays",
57-
required=True)
40+
parser.add_argument("-i",
41+
"--input_path",
42+
type=str,
43+
help="Full filepath of the input file.",
44+
required=True)
45+
parser.add_argument("-o",
46+
"--output_path",
47+
type=str,
48+
help="Full filepath of the output file.",
49+
required=True)
50+
parser.add_argument("-O",
51+
"--output_arrays",
52+
type=str,
53+
help="Original model output arrays",
54+
required=True)
5855

5956
return parser
6057

compiler/circle-part-value-py-test/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ def extract_test_args(s):
1010
def pytest_addoption(parser):
1111
parser.addoption("--test_list", action="store", help="Path to test list")
1212
parser.addoption("--bin_dir", action="store", help="Directory including artifacts")
13-
parser.addoption(
14-
"--circle_part_driver", action="store", help="Path to circle part driver")
13+
parser.addoption("--circle_part_driver",
14+
action="store",
15+
help="Path to circle part driver")
1516

1617

1718
def pytest_generate_tests(metafunc):

compiler/circle-part-value-py-test/test_circle_part_value.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,20 @@ def part_eval(test_name, bin_dir, circle_part_driver):
5757
for i in range(num_inputs):
5858
input_details = interpreter.get_input_details()[i]
5959
if input_details["dtype"] == np.float32:
60-
input_data = np.array(
61-
np.random.random_sample(input_details["shape"]), input_details["dtype"])
60+
input_data = np.array(np.random.random_sample(input_details["shape"]),
61+
input_details["dtype"])
6262
elif input_details["dtype"] == np.uint8:
63-
input_data = np.array(
64-
np.random.randint(0, 256, size=input_details["shape"]),
65-
input_details["dtype"])
63+
input_data = np.array(np.random.randint(0, 256, size=input_details["shape"]),
64+
input_details["dtype"])
6665
elif input_details["dtype"] == np.int16:
67-
input_data = np.array(
68-
np.random.randint(0, 100, size=input_details["shape"]),
69-
input_details["dtype"])
66+
input_data = np.array(np.random.randint(0, 100, size=input_details["shape"]),
67+
input_details["dtype"])
7068
elif input_details["dtype"] == np.int32:
71-
input_data = np.array(
72-
np.random.randint(0, 100, size=input_details["shape"]),
73-
input_details["dtype"])
69+
input_data = np.array(np.random.randint(0, 100, size=input_details["shape"]),
70+
input_details["dtype"])
7471
elif input_details["dtype"] == np.int64:
75-
input_data = np.array(
76-
np.random.randint(0, 100, size=input_details["shape"]),
77-
input_details["dtype"])
72+
input_data = np.array(np.random.randint(0, 100, size=input_details["shape"]),
73+
input_details["dtype"])
7874
elif input_details["dtype"] == np.bool_:
7975
input_data = np.array(
8076
np.random.choice(a=[True, False], size=input_details["shape"]),

compiler/circle-part-value-test/part_eval_one.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,17 @@
7272
input_details_dtype = input_details["dtype"]
7373
input_details_shape = input_details["shape"]
7474
if input_details_dtype == np.float32:
75-
input_data = np.array(
76-
np.random.random_sample(input_details_shape), input_details_dtype)
75+
input_data = np.array(np.random.random_sample(input_details_shape),
76+
input_details_dtype)
7777
elif input_details_dtype == np.int16:
78-
input_data = np.array(
79-
np.random.randint(0, 100, size=input_details_shape), input_details_dtype)
78+
input_data = np.array(np.random.randint(0, 100, size=input_details_shape),
79+
input_details_dtype)
8080
elif input_details_dtype == np.uint8:
81-
input_data = np.array(
82-
np.random.randint(0, 256, size=input_details_shape), input_details_dtype)
81+
input_data = np.array(np.random.randint(0, 256, size=input_details_shape),
82+
input_details_dtype)
8383
elif input_details_dtype == np.bool_:
84-
input_data = np.array(
85-
np.random.choice(a=[True, False], size=input_details_shape),
86-
input_details_dtype)
84+
input_data = np.array(np.random.choice(a=[True, False], size=input_details_shape),
85+
input_details_dtype)
8786
else:
8887
raise SystemExit("Unsupported input dtype")
8988

@@ -124,8 +123,8 @@
124123
raise SystemExit("Execution result of " + tflite_model +
125124
" does not match with " + circle_model)
126125
elif output_dtype == np.float32:
127-
if np.allclose(
128-
luci_output_data, intp_output_data, rtol=1.e-5, atol=1.e-5) == False:
126+
if np.allclose(luci_output_data, intp_output_data, rtol=1.e-5,
127+
atol=1.e-5) == False:
129128
raise SystemExit("Execution result of " + tflite_model +
130129
" does not match with " + circle_model)
131130
elif output_dtype == np.int64:

compiler/fm-equalize/fm-equalize

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ from pathlib import Path
3333
def _get_parser():
3434
parser = argparse.ArgumentParser(
3535
description='Command line tool to equalize feature map (FM) value distribution')
36-
parser.add_argument(
37-
"-i", "--input", type=str, help="Path to the input circle model.", required=True)
38-
parser.add_argument(
39-
"-o",
40-
"--output",
41-
type=str,
42-
help="Path to the output circle model.",
43-
required=True)
36+
parser.add_argument("-i",
37+
"--input",
38+
type=str,
39+
help="Path to the input circle model.",
40+
required=True)
41+
parser.add_argument("-o",
42+
"--output",
43+
type=str,
44+
help="Path to the output circle model.",
45+
required=True)
4446
parser.add_argument(
4547
"-f",
4648
"--fme_patterns",
@@ -133,11 +135,10 @@ def main():
133135
Path(output_model).with_suffix('.fme_patterns.json').name)
134136

135137
# Step 1. Run fme-detect to find equalization patterns
136-
_run_fme_detect(
137-
str(input_model),
138-
str(fme_patterns),
139-
verbose=verbose,
140-
allow_dup_op=allow_dup_op)
138+
_run_fme_detect(str(input_model),
139+
str(fme_patterns),
140+
verbose=verbose,
141+
allow_dup_op=allow_dup_op)
141142

142143
# Copy fme_patterns to the given path
143144
if args.fme_patterns != None:
@@ -152,8 +153,10 @@ def main():
152153
os.system(f'cp {fme_patterns} {args.fme_patterns}')
153154

154155
# Step 3. Run fme-apply
155-
_run_fme_apply(
156-
str(input_model), str(fme_patterns), str(output_model), verbose=verbose)
156+
_run_fme_apply(str(input_model),
157+
str(fme_patterns),
158+
str(output_model),
159+
verbose=verbose)
157160

158161

159162
if __name__ == '__main__':

compiler/luci-pass-value-py-test/conftest.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ def extract_test_args(s):
99

1010
def pytest_addoption(parser):
1111
parser.addoption("--test_list", action="store", help="Path to test list")
12-
parser.addoption(
13-
"--tflite_dir", action="store", help="Directory including tflite file")
14-
parser.addoption(
15-
"--circle_dir", action="store", help="Directory including circle file")
16-
parser.addoption(
17-
"--luci_eval_driver", action="store", help="Path to luci eval driver")
12+
parser.addoption("--tflite_dir",
13+
action="store",
14+
help="Directory including tflite file")
15+
parser.addoption("--circle_dir",
16+
action="store",
17+
help="Directory including circle file")
18+
parser.addoption("--luci_eval_driver",
19+
action="store",
20+
help="Path to luci eval driver")
1821

1922

2023
def pytest_generate_tests(metafunc):

compiler/luci-pass-value-py-test/test_luci_eval.py

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,20 @@ def luci_eval_verify(test_name,
3838
for i in range(num_inputs):
3939
input_details = interpreter.get_input_details()[i]
4040
if input_details["dtype"] == np.float32:
41-
input_data = np.array(
42-
np.random.random_sample(input_details["shape"]), input_details["dtype"])
41+
input_data = np.array(np.random.random_sample(input_details["shape"]),
42+
input_details["dtype"])
4343
elif input_details["dtype"] == np.uint8:
44-
input_data = np.array(
45-
np.random.randint(0, 256, size=input_details["shape"]),
46-
input_details["dtype"])
44+
input_data = np.array(np.random.randint(0, 256, size=input_details["shape"]),
45+
input_details["dtype"])
4746
elif input_details["dtype"] == np.int16:
48-
input_data = np.array(
49-
np.random.randint(0, 100, size=input_details["shape"]),
50-
input_details["dtype"])
47+
input_data = np.array(np.random.randint(0, 100, size=input_details["shape"]),
48+
input_details["dtype"])
5149
elif input_details["dtype"] == np.int32:
52-
input_data = np.array(
53-
np.random.randint(0, 100, size=input_details["shape"]),
54-
input_details["dtype"])
50+
input_data = np.array(np.random.randint(0, 100, size=input_details["shape"]),
51+
input_details["dtype"])
5552
elif input_details["dtype"] == np.int64:
56-
input_data = np.array(
57-
np.random.randint(0, 100, size=input_details["shape"]),
58-
input_details["dtype"])
53+
input_data = np.array(np.random.randint(0, 100, size=input_details["shape"]),
54+
input_details["dtype"])
5955
elif input_details["dtype"] == np.bool_:
6056
input_data = np.array(
6157
np.random.choice(a=[True, False], size=input_details["shape"]),
@@ -70,12 +66,11 @@ def luci_eval_verify(test_name,
7066
interpreter.invoke()
7167

7268
# Execute luci interpreter.
73-
subprocess.run(
74-
[
75-
eval_driver, circle_model,
76-
str(num_inputs), circle_model + ".input", circle_model + ".output"
77-
],
78-
check=True)
69+
subprocess.run([
70+
eval_driver, circle_model,
71+
str(num_inputs), circle_model + ".input", circle_model + ".output"
72+
],
73+
check=True)
7974

8075
# Compare the results.
8176
inpt_output_details = interpreter.get_output_details()
@@ -92,23 +87,33 @@ def luci_eval_verify(test_name,
9287
intp_output_data = interpreter.get_tensor(output_tensor)
9388
err_msg = "Execution result of " + tflite_model + " does not match with " + circle_model
9489
if output_details["dtype"] == np.uint8:
95-
assert np.allclose(
96-
luci_output_data, intp_output_data, rtol=rtolint, atol=atolint), err_msg
90+
assert np.allclose(luci_output_data,
91+
intp_output_data,
92+
rtol=rtolint,
93+
atol=atolint), err_msg
9794
elif output_details["dtype"] == np.float32:
98-
assert np.allclose(
99-
luci_output_data, intp_output_data, rtol=rtolf32, atol=atolf32), err_msg
95+
assert np.allclose(luci_output_data,
96+
intp_output_data,
97+
rtol=rtolf32,
98+
atol=atolf32), err_msg
10099
elif output_details["dtype"] == np.int64:
101-
assert np.allclose(
102-
luci_output_data, intp_output_data, rtol=rtolint, atol=atolint), err_msg
100+
assert np.allclose(luci_output_data,
101+
intp_output_data,
102+
rtol=rtolint,
103+
atol=atolint), err_msg
103104
elif output_details["dtype"] == np.int32:
104-
assert np.allclose(
105-
luci_output_data, intp_output_data, rtol=rtolint, atol=atolint), err_msg
105+
assert np.allclose(luci_output_data,
106+
intp_output_data,
107+
rtol=rtolint,
108+
atol=atolint), err_msg
106109
elif output_details["dtype"] == np.int16:
107-
assert np.allclose(
108-
luci_output_data, intp_output_data, rtol=rtolint, atol=atolint), err_msg
110+
assert np.allclose(luci_output_data,
111+
intp_output_data,
112+
rtol=rtolint,
113+
atol=atolint), err_msg
109114
elif output_details["dtype"] == np.bool_:
110-
assert np.allclose(
111-
luci_output_data, intp_output_data, rtol=0, atol=0), err_msg
115+
assert np.allclose(luci_output_data, intp_output_data, rtol=0,
116+
atol=0), err_msg
112117
else:
113118
assert False, "Unsupported data type: " + output_details["dtype"]
114119

compiler/luci-pass-value-test/eval_result_verifier.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@
3939
for i in range(num_inputs):
4040
input_details = interpreter.get_input_details()[i]
4141
if input_details["dtype"] == np.float32:
42-
input_data = np.array(
43-
np.random.random_sample(input_details["shape"]), input_details["dtype"])
42+
input_data = np.array(np.random.random_sample(input_details["shape"]),
43+
input_details["dtype"])
4444
elif input_details["dtype"] == np.uint8:
45-
input_data = np.array(
46-
np.random.randint(0, 256, size=input_details["shape"]),
47-
input_details["dtype"])
45+
input_data = np.array(np.random.randint(0, 256, size=input_details["shape"]),
46+
input_details["dtype"])
4847
elif input_details["dtype"] == np.int16:
49-
input_data = np.array(
50-
np.random.randint(0, 100, size=input_details["shape"]),
51-
input_details["dtype"])
48+
input_data = np.array(np.random.randint(0, 100, size=input_details["shape"]),
49+
input_details["dtype"])
5250
elif input_details["dtype"] == np.bool_:
5351
input_data = np.array(
5452
np.random.choice(a=[True, False], size=input_details["shape"]),
@@ -63,12 +61,11 @@
6361
interpreter.invoke()
6462

6563
# Execute luci interpreter.
66-
subprocess.run(
67-
[
68-
driver, circle_model,
69-
str(num_inputs), circle_model + ".input", circle_model + ".output"
70-
],
71-
check=True)
64+
subprocess.run([
65+
driver, circle_model,
66+
str(num_inputs), circle_model + ".input", circle_model + ".output"
67+
],
68+
check=True)
7269

7370
# Compare the results.
7471
inpt_output_details = interpreter.get_output_details()
@@ -89,8 +86,8 @@
8986
raise SystemExit("Execution result of " + tflite_model +
9087
" does not match with " + circle_model)
9188
elif output_details["dtype"] == np.float32:
92-
if np.allclose(
93-
luci_output_data, intp_output_data, rtol=1.e-5, atol=1.e-5) == False:
89+
if np.allclose(luci_output_data, intp_output_data, rtol=1.e-5,
90+
atol=1.e-5) == False:
9491
raise SystemExit("Execution result of " + tflite_model +
9592
" does not match with " + circle_model)
9693
elif output_details["dtype"] == np.int64:

0 commit comments

Comments
 (0)