Skip to content

Commit f46fe10

Browse files
authored
[CodeStyle] black -> ruff format migration - part 39 (#74793)
1 parent d91457d commit f46fe10

23 files changed

+107
-115
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ repos:
105105
106106
# | test/l.+
107107
108-
# | test/[m-z].+
108+
| test/[m-z].+
109109
110110
| tools/.+
111111
)$
@@ -161,7 +161,7 @@ repos:
161161
162162
| test/l.+
163163
164-
| test/[m-z].+
164+
# | test/[m-z].+
165165
166166
# | tools/.+
167167
)$

test/prim/model/bert.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,12 @@ def forward(
328328
past_key_values_length=past_key_values_length,
329329
)
330330
if self.fuse:
331-
assert (
332-
not output_attentions
333-
), "Not support attentions output currently."
334-
assert (
335-
past_key_values is None
336-
), "Not support past_key_values currently."
331+
assert not output_attentions, (
332+
"Not support attentions output currently."
333+
)
334+
assert past_key_values is None, (
335+
"Not support past_key_values currently."
336+
)
337337
hidden_states = embedding_output
338338
all_hidden_states = [] if output_hidden_states else None
339339
for layer in self.encoder:

test/prim/pir_prim/test_batch_norm_shape_check.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ def test_build_op(self):
7575
y_new = decompose(pir_program, y)
7676
core._set_prim_forward_enabled(False)
7777
new_shape = y_new[0].shape
78-
assert (
79-
orig_shape == new_shape
80-
), f"Original shape {orig_shape} is not equal to new shape {new_shape}"
78+
assert orig_shape == new_shape, (
79+
f"Original shape {orig_shape} is not equal to new shape {new_shape}"
80+
)
8181
op_name_list = [op.name() for op in pir_program.global_block().ops]
8282
assert "pd_op.batch_norm_" not in op_name_list
8383

test/prim/pir_prim/test_builtin_slice.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def test_build_op(self):
6868
y_new = decompose(pir_program, y)
6969
core._set_prim_forward_enabled(False)
7070
new_shape = y_new[0].shape
71-
assert (
72-
orig_shape == new_shape
73-
), f"Original shape {orig_shape} is not equal to new shape {new_shape}"
71+
assert orig_shape == new_shape, (
72+
f"Original shape {orig_shape} is not equal to new shape {new_shape}"
73+
)
7474
op_name_list = [op.name() for op in pir_program.global_block().ops]
7575
assert "pd_op.meshgrid" not in op_name_list
7676

test/prim/pir_prim/test_decomp_op.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ def test_build_op(self):
5656
y_new = decompose(pir_program, y)
5757
core._set_prim_forward_enabled(False)
5858
new_shape = y_new[0].shape
59-
assert (
60-
orig_shape == new_shape
61-
), f"Original shape {orig_shape} is not equal to new shape {new_shape}"
59+
assert orig_shape == new_shape, (
60+
f"Original shape {orig_shape} is not equal to new shape {new_shape}"
61+
)
6262
op_name_list = [op.name() for op in pir_program.global_block().ops]
6363
self.assertEqual(
6464
op_name_list,

test/quantization/quant2_int8_image_classification_comparison.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,13 @@ def test_graph_transformation(self):
350350
return
351351

352352
quant_model_path = test_case_args.quant_model
353-
assert (
354-
quant_model_path
355-
), 'The Quant model path cannot be empty. Please, use the --quant_model option.'
353+
assert quant_model_path, (
354+
'The Quant model path cannot be empty. Please, use the --quant_model option.'
355+
)
356356
data_path = test_case_args.infer_data
357-
assert (
358-
data_path
359-
), 'The dataset path cannot be empty. Please, use the --infer_data option.'
357+
assert data_path, (
358+
'The dataset path cannot be empty. Please, use the --infer_data option.'
359+
)
360360
fp32_model_path = test_case_args.fp32_model
361361
batch_size = test_case_args.batch_size
362362
batch_num = test_case_args.batch_num
@@ -377,9 +377,9 @@ def test_graph_transformation(self):
377377
)
378378

379379
self._targets = self._strings_from_csv(test_case_args.targets)
380-
assert self._targets.intersection(
381-
{'quant', 'int8', 'fp32'}
382-
), 'The --targets option, if used, must contain at least one of the targets: "quant", "int8", "fp32".'
380+
assert self._targets.intersection({'quant', 'int8', 'fp32'}), (
381+
'The --targets option, if used, must contain at least one of the targets: "quant", "int8", "fp32".'
382+
)
383383

384384
_logger.info('Quant & INT8 prediction run.')
385385
_logger.info(f'Quant model: {quant_model_path}')

test/quantization/quant2_int8_lstm_model.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,17 @@ def test_lstm_model(self):
204204
return
205205

206206
fp32_model = test_case_args.fp32_model
207-
assert (
208-
fp32_model
209-
), 'The FP32 model path cannot be empty. Please, use the --fp32_model option.'
207+
assert fp32_model, (
208+
'The FP32 model path cannot be empty. Please, use the --fp32_model option.'
209+
)
210210
quant_model = test_case_args.quant_model
211-
assert (
212-
quant_model
213-
), 'The quant model path cannot be empty. Please, use the --quant_model option.'
211+
assert quant_model, (
212+
'The quant model path cannot be empty. Please, use the --quant_model option.'
213+
)
214214
infer_data = test_case_args.infer_data
215-
assert (
216-
infer_data
217-
), 'The dataset path cannot be empty. Please, use the --infer_data option.'
215+
assert infer_data, (
216+
'The dataset path cannot be empty. Please, use the --infer_data option.'
217+
)
218218
num_threads = test_case_args.num_threads
219219
onednn_cache_capacity = test_case_args.onednn_cache_capacity
220220
warmup_iter = test_case_args.warmup_iter

test/quantization/quant2_int8_nlp_comparison.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,22 @@ def reader():
110110
):
111111
data_lines = df.readlines()
112112
labels_lines = lf.readlines()
113-
assert len(data_lines) == len(
114-
labels_lines
115-
), "The number of labels does not match the length of the dataset."
113+
assert len(data_lines) == len(labels_lines), (
114+
"The number of labels does not match the length of the dataset."
115+
)
116116

117117
for i in range(len(data_lines)):
118118
data_fields = data_lines[i].split(';')
119-
assert (
120-
len(data_fields) >= 2
121-
), "The number of data fields in the dataset is less than 2"
119+
assert len(data_fields) >= 2, (
120+
"The number of data fields in the dataset is less than 2"
121+
)
122122
buffers = []
123123
shape = []
124124
for j in range(2):
125125
data = data_fields[j].split(':')
126-
assert (
127-
len(data) >= 2
128-
), "Size of data in the dataset is less than 2"
126+
assert len(data) >= 2, (
127+
"Size of data in the dataset is less than 2"
128+
)
129129
# Shape is stored under index 0, while data under 1
130130
shape = data[0].split()
131131
shape.pop(0)
@@ -287,13 +287,13 @@ def test_graph_transformation(self):
287287
return
288288

289289
quant_model_path = test_case_args.quant_model
290-
assert (
291-
quant_model_path
292-
), 'The Quant model path cannot be empty. Please, use the --quant_model option.'
290+
assert quant_model_path, (
291+
'The Quant model path cannot be empty. Please, use the --quant_model option.'
292+
)
293293
data_path = test_case_args.infer_data
294-
assert (
295-
data_path
296-
), 'The dataset path cannot be empty. Please, use the --infer_data option.'
294+
assert data_path, (
295+
'The dataset path cannot be empty. Please, use the --infer_data option.'
296+
)
297297
fp32_model_path = test_case_args.fp32_model
298298
labels_path = test_case_args.labels
299299
batch_size = test_case_args.batch_size
@@ -315,9 +315,9 @@ def test_graph_transformation(self):
315315
)
316316

317317
self._targets = self._strings_from_csv(test_case_args.targets)
318-
assert self._targets.intersection(
319-
{'quant', 'int8', 'fp32'}
320-
), 'The --targets option, if used, must contain at least one of the targets: "quant", "int8", "fp32".'
318+
assert self._targets.intersection({'quant', 'int8', 'fp32'}), (
319+
'The --targets option, if used, must contain at least one of the targets: "quant", "int8", "fp32".'
320+
)
321321

322322
_logger.info('Quant & INT8 prediction run.')
323323
_logger.info(f'Quant model: {quant_model_path}')

test/quantization/quant_int8_image_classification_comparison.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,13 @@ def test_graph_transformation(self):
287287
return
288288

289289
quant_model_path = test_case_args.quant_model
290-
assert (
291-
quant_model_path
292-
), 'The Quant model path cannot be empty. Please, use the --quant_model option.'
290+
assert quant_model_path, (
291+
'The Quant model path cannot be empty. Please, use the --quant_model option.'
292+
)
293293
data_path = test_case_args.infer_data
294-
assert (
295-
data_path
296-
), 'The dataset path cannot be empty. Please, use the --infer_data option.'
294+
assert data_path, (
295+
'The dataset path cannot be empty. Please, use the --infer_data option.'
296+
)
297297
batch_size = test_case_args.batch_size
298298
batch_num = test_case_args.batch_num
299299
skip_batch_num = test_case_args.skip_batch_num

test/rnn/rnn_numpy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,9 @@ def forward(
423423
self, inputs, initial_states=None, sequence_length=None, **kwargs
424424
):
425425
if isinstance(initial_states, (list, tuple)):
426-
assert (
427-
len(initial_states) == 2
428-
), "length of initial_states should be 2 when it is a list/tuple"
426+
assert len(initial_states) == 2, (
427+
"length of initial_states should be 2 when it is a list/tuple"
428+
)
429429
else:
430430
initial_states = [initial_states, initial_states]
431431

0 commit comments

Comments
 (0)