Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ repos:

# | test/l.+

# | test/[m-z].+
| test/[m-z].+

# | tools/.+
)$
Expand Down Expand Up @@ -161,7 +161,7 @@ repos:

| test/l.+

| test/[m-z].+
# | test/[m-z].+

| tools/.+
)$
Expand Down
12 changes: 6 additions & 6 deletions test/prim/model/bert.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,12 @@ def forward(
past_key_values_length=past_key_values_length,
)
if self.fuse:
assert (
not output_attentions
), "Not support attentions output currently."
assert (
past_key_values is None
), "Not support past_key_values currently."
assert not output_attentions, (
"Not support attentions output currently."
)
assert past_key_values is None, (
"Not support past_key_values currently."
)
hidden_states = embedding_output
all_hidden_states = [] if output_hidden_states else None
for layer in self.encoder:
Expand Down
6 changes: 3 additions & 3 deletions test/prim/pir_prim/test_batch_norm_shape_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def test_build_op(self):
y_new = decompose(pir_program, y)
core._set_prim_forward_enabled(False)
new_shape = y_new[0].shape
assert (
orig_shape == new_shape
), f"Original shape {orig_shape} is not equal to new shape {new_shape}"
assert orig_shape == new_shape, (
f"Original shape {orig_shape} is not equal to new shape {new_shape}"
)
op_name_list = [op.name() for op in pir_program.global_block().ops]
assert "pd_op.batch_norm_" not in op_name_list

Expand Down
6 changes: 3 additions & 3 deletions test/prim/pir_prim/test_builtin_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def test_build_op(self):
y_new = decompose(pir_program, y)
core._set_prim_forward_enabled(False)
new_shape = y_new[0].shape
assert (
orig_shape == new_shape
), f"Original shape {orig_shape} is not equal to new shape {new_shape}"
assert orig_shape == new_shape, (
f"Original shape {orig_shape} is not equal to new shape {new_shape}"
)
op_name_list = [op.name() for op in pir_program.global_block().ops]
assert "pd_op.meshgrid" not in op_name_list

Expand Down
6 changes: 3 additions & 3 deletions test/prim/pir_prim/test_decomp_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def test_build_op(self):
y_new = decompose(pir_program, y)
core._set_prim_forward_enabled(False)
new_shape = y_new[0].shape
assert (
orig_shape == new_shape
), f"Original shape {orig_shape} is not equal to new shape {new_shape}"
assert orig_shape == new_shape, (
f"Original shape {orig_shape} is not equal to new shape {new_shape}"
)
op_name_list = [op.name() for op in pir_program.global_block().ops]
self.assertEqual(
op_name_list,
Expand Down
18 changes: 9 additions & 9 deletions test/quantization/quant2_int8_image_classification_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,13 @@ def test_graph_transformation(self):
return

quant_model_path = test_case_args.quant_model
assert (
quant_model_path
), 'The Quant model path cannot be empty. Please, use the --quant_model option.'
assert quant_model_path, (
'The Quant model path cannot be empty. Please, use the --quant_model option.'
)
data_path = test_case_args.infer_data
assert (
data_path
), 'The dataset path cannot be empty. Please, use the --infer_data option.'
assert data_path, (
'The dataset path cannot be empty. Please, use the --infer_data option.'
)
fp32_model_path = test_case_args.fp32_model
batch_size = test_case_args.batch_size
batch_num = test_case_args.batch_num
Expand All @@ -377,9 +377,9 @@ def test_graph_transformation(self):
)

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

_logger.info('Quant & INT8 prediction run.')
_logger.info(f'Quant model: {quant_model_path}')
Expand Down
18 changes: 9 additions & 9 deletions test/quantization/quant2_int8_lstm_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,17 @@ def test_lstm_model(self):
return

fp32_model = test_case_args.fp32_model
assert (
fp32_model
), 'The FP32 model path cannot be empty. Please, use the --fp32_model option.'
assert fp32_model, (
'The FP32 model path cannot be empty. Please, use the --fp32_model option.'
)
quant_model = test_case_args.quant_model
assert (
quant_model
), 'The quant model path cannot be empty. Please, use the --quant_model option.'
assert quant_model, (
'The quant model path cannot be empty. Please, use the --quant_model option.'
)
infer_data = test_case_args.infer_data
assert (
infer_data
), 'The dataset path cannot be empty. Please, use the --infer_data option.'
assert infer_data, (
'The dataset path cannot be empty. Please, use the --infer_data option.'
)
num_threads = test_case_args.num_threads
onednn_cache_capacity = test_case_args.onednn_cache_capacity
warmup_iter = test_case_args.warmup_iter
Expand Down
36 changes: 18 additions & 18 deletions test/quantization/quant2_int8_nlp_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,22 @@ def reader():
):
data_lines = df.readlines()
labels_lines = lf.readlines()
assert len(data_lines) == len(
labels_lines
), "The number of labels does not match the length of the dataset."
assert len(data_lines) == len(labels_lines), (
"The number of labels does not match the length of the dataset."
)

for i in range(len(data_lines)):
data_fields = data_lines[i].split(';')
assert (
len(data_fields) >= 2
), "The number of data fields in the dataset is less than 2"
assert len(data_fields) >= 2, (
"The number of data fields in the dataset is less than 2"
)
buffers = []
shape = []
for j in range(2):
data = data_fields[j].split(':')
assert (
len(data) >= 2
), "Size of data in the dataset is less than 2"
assert len(data) >= 2, (
"Size of data in the dataset is less than 2"
)
# Shape is stored under index 0, while data under 1
shape = data[0].split()
shape.pop(0)
Expand Down Expand Up @@ -287,13 +287,13 @@ def test_graph_transformation(self):
return

quant_model_path = test_case_args.quant_model
assert (
quant_model_path
), 'The Quant model path cannot be empty. Please, use the --quant_model option.'
assert quant_model_path, (
'The Quant model path cannot be empty. Please, use the --quant_model option.'
)
data_path = test_case_args.infer_data
assert (
data_path
), 'The dataset path cannot be empty. Please, use the --infer_data option.'
assert data_path, (
'The dataset path cannot be empty. Please, use the --infer_data option.'
)
fp32_model_path = test_case_args.fp32_model
labels_path = test_case_args.labels
batch_size = test_case_args.batch_size
Expand All @@ -315,9 +315,9 @@ def test_graph_transformation(self):
)

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

_logger.info('Quant & INT8 prediction run.')
_logger.info(f'Quant model: {quant_model_path}')
Expand Down
12 changes: 6 additions & 6 deletions test/quantization/quant_int8_image_classification_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,13 @@ def test_graph_transformation(self):
return

quant_model_path = test_case_args.quant_model
assert (
quant_model_path
), 'The Quant model path cannot be empty. Please, use the --quant_model option.'
assert quant_model_path, (
'The Quant model path cannot be empty. Please, use the --quant_model option.'
)
data_path = test_case_args.infer_data
assert (
data_path
), 'The dataset path cannot be empty. Please, use the --infer_data option.'
assert data_path, (
'The dataset path cannot be empty. Please, use the --infer_data option.'
)
batch_size = test_case_args.batch_size
batch_num = test_case_args.batch_num
skip_batch_num = test_case_args.skip_batch_num
Expand Down
6 changes: 3 additions & 3 deletions test/rnn/rnn_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,9 @@ def forward(
self, inputs, initial_states=None, sequence_length=None, **kwargs
):
if isinstance(initial_states, (list, tuple)):
assert (
len(initial_states) == 2
), "length of initial_states should be 2 when it is a list/tuple"
assert len(initial_states) == 2, (
"length of initial_states should be 2 when it is a list/tuple"
)
else:
initial_states = [initial_states, initial_states]

Expand Down
5 changes: 1 addition & 4 deletions test/sequence/test_sequence_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ def seqconv(
)
if padding_trainable:
sub_w = padding_data[
begin_pad
+ context_start
+ j
- pad_size : begin_pad
begin_pad + context_start + j - pad_size : begin_pad
+ context_start
+ j,
:,
Expand Down
6 changes: 3 additions & 3 deletions test/sot/test_analysis_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def assert_inputs_equals(instruction_offset: int, expected_inputs: set[str]):
reads, writes = analysis_used_names(
instructions, current_instr_idx + instruction_offset
)
assert (
set(reads) == expected_inputs
), f"actual_inputs: {reads}, expected_inputs: {expected_inputs}"
assert set(reads) == expected_inputs, (
f"actual_inputs: {reads}, expected_inputs: {expected_inputs}"
)


def case1(x):
Expand Down
6 changes: 3 additions & 3 deletions test/sot/test_sot_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def catch_error(self, func, inputs, error_lines: int | list[int]):
except Exception as e:
match_results = re.compile(r'File ".*", line (\d+)').findall(str(e))
match_results = list(map(int, match_results))
assert (
match_results == error_lines
), f"{match_results} is not equal {error_lines}"
assert match_results == error_lines, (
f"{match_results} is not equal {error_lines}"
)

def test_all_case(self):
self.catch_error(case1, paddle.rand([2, 1]), 25)
Expand Down
6 changes: 3 additions & 3 deletions test/tokenizer/tokenizer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,9 @@ def save_pretrained(self, save_directory):
# reload from save_directory
tokenizer = BertTokenizer.from_pretrained('trained_model')
"""
assert not os.path.isfile(
save_directory
), f"Saving directory ({save_directory}) should be a directory, not a file"
assert not os.path.isfile(save_directory), (
f"Saving directory ({save_directory}) should be a directory, not a file"
)
os.makedirs(save_directory, exist_ok=True)

tokenizer_config_file = os.path.join(
Expand Down
6 changes: 3 additions & 3 deletions test/xpu/collective_allgather_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ def run_trainer(self, args):
indata = test_base.create_test_data(
shape=(10, 1000), dtype=args["dtype"], seed=os.getpid()
)
assert (
args['static_mode'] == 1
), "collective_allgather_api only support static graph mode"
assert args['static_mode'] == 1, (
"collective_allgather_api only support static graph mode"
)
result = (
self.get_model_new(
train_prog, startup_prog, rank, dtype=args["dtype"]
Expand Down
6 changes: 3 additions & 3 deletions test/xpu/test_fused_linear_param_grad_add_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def run_fused_linear_param_grad_add(
if dweight is not None:
assert dweight_new.data_ptr() == dweight.data_ptr()
if has_bias and dbias is not None:
assert (
dbias_new.data_ptr() == dbias.data_ptr()
), f"multi_precision={multi_precision}, has_bias={has_bias}, dbias.dtype={dbias.dtype}."
assert dbias_new.data_ptr() == dbias.data_ptr(), (
f"multi_precision={multi_precision}, has_bias={has_bias}, dbias.dtype={dbias.dtype}."
)
if has_bias:
return (
promote_dtype(dweight_new).numpy(),
Expand Down
6 changes: 3 additions & 3 deletions test/xpu/test_generate_proposals_v2_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def box_coder(all_anchors, bbox_deltas, variances, pixel_offset=True):
def clip_tiled_boxes(boxes, im_shape, pixel_offset=True):
"""Clip boxes to image boundaries. im_shape is [height, width] and boxes
has shape (N, 4 * num_tiled_boxes)."""
assert (
boxes.shape[1] % 4 == 0
), f'boxes.shape[1] is {boxes.shape[1]:d}, but must be divisible by 4.'
assert boxes.shape[1] % 4 == 0, (
f'boxes.shape[1] is {boxes.shape[1]:d}, but must be divisible by 4.'
)
offset = 1 if pixel_offset else 0
# x1 >= 0
boxes[:, 0::4] = np.maximum(
Expand Down
18 changes: 9 additions & 9 deletions test/xpu/test_put_along_axis_op_int_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ def setUp(self):
self.value_broadcast[i, j, k]
)
elif self.reduce == "add":
self.target[
loc_[0], loc_[1], loc_[2]
] += self.value_broadcast[i, j, k]
self.target[loc_[0], loc_[1], loc_[2]] += (
self.value_broadcast[i, j, k]
)
elif self.reduce == "mul" or self.reduce == "multiply":
self.target[
loc_[0], loc_[1], loc_[2]
] *= self.value_broadcast[i, j, k]
self.target[loc_[0], loc_[1], loc_[2]] *= (
self.value_broadcast[i, j, k]
)
elif self.reduce == "mean":
self.target[
loc_[0], loc_[1], loc_[2]
] += self.value_broadcast[i, j, k]
self.target[loc_[0], loc_[1], loc_[2]] += (
self.value_broadcast[i, j, k]
)
loc = tuple(loc_)
if loc in mean_record.keys():
mean_record[loc] += 1
Expand Down
18 changes: 9 additions & 9 deletions test/xpu/test_put_along_axis_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ def setUp(self):
self.value_broadcast[i, j, k]
)
elif self.reduce == "add":
self.target[
loc_[0], loc_[1], loc_[2]
] += self.value_broadcast[i, j, k]
self.target[loc_[0], loc_[1], loc_[2]] += (
self.value_broadcast[i, j, k]
)
elif self.reduce == "mul" or self.reduce == "multiply":
self.target[
loc_[0], loc_[1], loc_[2]
] *= self.value_broadcast[i, j, k]
self.target[loc_[0], loc_[1], loc_[2]] *= (
self.value_broadcast[i, j, k]
)
elif self.reduce == "mean":
self.target[
loc_[0], loc_[1], loc_[2]
] += self.value_broadcast[i, j, k]
self.target[loc_[0], loc_[1], loc_[2]] += (
self.value_broadcast[i, j, k]
)
loc = tuple(loc_)
if loc in mean_record.keys():
mean_record[loc] += 1
Expand Down
6 changes: 3 additions & 3 deletions test/xpu/test_randperm_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@


def check_randperm_out(n, data_np):
assert isinstance(
data_np, np.ndarray
), "The input data_np should be np.ndarray."
assert isinstance(data_np, np.ndarray), (
"The input data_np should be np.ndarray."
)
gt_sorted = np.arange(n)
out_sorted = np.sort(data_np)
return list(gt_sorted == out_sorted)
Expand Down
Loading