diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1f1db341c82de9..62ac1af159421c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -105,7 +105,7 @@ repos: # | test/l.+ - # | test/[m-z].+ + | test/[m-z].+ # | tools/.+ )$ @@ -161,7 +161,7 @@ repos: | test/l.+ - | test/[m-z].+ + # | test/[m-z].+ | tools/.+ )$ diff --git a/test/prim/model/bert.py b/test/prim/model/bert.py index 0f3bee5e1d5b25..c6e939afdec391 100644 --- a/test/prim/model/bert.py +++ b/test/prim/model/bert.py @@ -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: diff --git a/test/prim/pir_prim/test_batch_norm_shape_check.py b/test/prim/pir_prim/test_batch_norm_shape_check.py index 77c039ef2fc935..929083eb7e828a 100644 --- a/test/prim/pir_prim/test_batch_norm_shape_check.py +++ b/test/prim/pir_prim/test_batch_norm_shape_check.py @@ -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 diff --git a/test/prim/pir_prim/test_builtin_slice.py b/test/prim/pir_prim/test_builtin_slice.py index 040bff0ed09737..a6b34c306624ee 100644 --- a/test/prim/pir_prim/test_builtin_slice.py +++ b/test/prim/pir_prim/test_builtin_slice.py @@ -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 diff --git a/test/prim/pir_prim/test_decomp_op.py b/test/prim/pir_prim/test_decomp_op.py index f49ca5c3767cad..7ae45770fc4803 100644 --- a/test/prim/pir_prim/test_decomp_op.py +++ b/test/prim/pir_prim/test_decomp_op.py @@ -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, diff --git a/test/quantization/quant2_int8_image_classification_comparison.py b/test/quantization/quant2_int8_image_classification_comparison.py index edda63d5d0f532..5d885b02426907 100644 --- a/test/quantization/quant2_int8_image_classification_comparison.py +++ b/test/quantization/quant2_int8_image_classification_comparison.py @@ -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 @@ -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}') diff --git a/test/quantization/quant2_int8_lstm_model.py b/test/quantization/quant2_int8_lstm_model.py index f7d8553ce38cab..cad5cac36c2ba7 100644 --- a/test/quantization/quant2_int8_lstm_model.py +++ b/test/quantization/quant2_int8_lstm_model.py @@ -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 diff --git a/test/quantization/quant2_int8_nlp_comparison.py b/test/quantization/quant2_int8_nlp_comparison.py index 215441823f4a1c..e0fa16d1ccb191 100644 --- a/test/quantization/quant2_int8_nlp_comparison.py +++ b/test/quantization/quant2_int8_nlp_comparison.py @@ -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) @@ -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 @@ -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}') diff --git a/test/quantization/quant_int8_image_classification_comparison.py b/test/quantization/quant_int8_image_classification_comparison.py index 4fc176c45c0d43..a79f0a8e838263 100644 --- a/test/quantization/quant_int8_image_classification_comparison.py +++ b/test/quantization/quant_int8_image_classification_comparison.py @@ -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 diff --git a/test/rnn/rnn_numpy.py b/test/rnn/rnn_numpy.py index c5e651230a4b4e..9d60d80ebaf3dd 100644 --- a/test/rnn/rnn_numpy.py +++ b/test/rnn/rnn_numpy.py @@ -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] diff --git a/test/sequence/test_sequence_conv.py b/test/sequence/test_sequence_conv.py index 60934f78cc2d65..35a28a51a8f7b0 100644 --- a/test/sequence/test_sequence_conv.py +++ b/test/sequence/test_sequence_conv.py @@ -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, :, diff --git a/test/sot/test_analysis_inputs.py b/test/sot/test_analysis_inputs.py index 8b37813028262a..eca16161d3e299 100644 --- a/test/sot/test_analysis_inputs.py +++ b/test/sot/test_analysis_inputs.py @@ -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): diff --git a/test/sot/test_sot_exception.py b/test/sot/test_sot_exception.py index d9407df2c0a621..64cf16719844c1 100644 --- a/test/sot/test_sot_exception.py +++ b/test/sot/test_sot_exception.py @@ -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) diff --git a/test/tokenizer/tokenizer_utils.py b/test/tokenizer/tokenizer_utils.py index 30e7e1e28ee0f3..7d4a2c60218c8e 100644 --- a/test/tokenizer/tokenizer_utils.py +++ b/test/tokenizer/tokenizer_utils.py @@ -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( diff --git a/test/xpu/collective_allgather_api.py b/test/xpu/collective_allgather_api.py index 7f3c397bffa256..ab600623c73b4c 100644 --- a/test/xpu/collective_allgather_api.py +++ b/test/xpu/collective_allgather_api.py @@ -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"] diff --git a/test/xpu/test_fused_linear_param_grad_add_xpu.py b/test/xpu/test_fused_linear_param_grad_add_xpu.py index 20a635cd92998f..88198501391881 100644 --- a/test/xpu/test_fused_linear_param_grad_add_xpu.py +++ b/test/xpu/test_fused_linear_param_grad_add_xpu.py @@ -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(), diff --git a/test/xpu/test_generate_proposals_v2_op_xpu.py b/test/xpu/test_generate_proposals_v2_op_xpu.py index dca37a4cd2e73f..f1a73f41a9e923 100644 --- a/test/xpu/test_generate_proposals_v2_op_xpu.py +++ b/test/xpu/test_generate_proposals_v2_op_xpu.py @@ -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( diff --git a/test/xpu/test_put_along_axis_op_int_xpu.py b/test/xpu/test_put_along_axis_op_int_xpu.py index 2ed0bb1ddbee6d..93cf1d923f6fcf 100644 --- a/test/xpu/test_put_along_axis_op_int_xpu.py +++ b/test/xpu/test_put_along_axis_op_int_xpu.py @@ -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 diff --git a/test/xpu/test_put_along_axis_op_xpu.py b/test/xpu/test_put_along_axis_op_xpu.py index 3fe23ca06298c5..ed1a58b7a5ddc0 100644 --- a/test/xpu/test_put_along_axis_op_xpu.py +++ b/test/xpu/test_put_along_axis_op_xpu.py @@ -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 diff --git a/test/xpu/test_randperm_op_xpu.py b/test/xpu/test_randperm_op_xpu.py index 8468ebcf98990a..fea11cc23f3ee3 100644 --- a/test/xpu/test_randperm_op_xpu.py +++ b/test/xpu/test_randperm_op_xpu.py @@ -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) diff --git a/test/xpu/test_sequence_conv_op_xpu.py b/test/xpu/test_sequence_conv_op_xpu.py index 9077511ece8a99..e84796edeb8d82 100644 --- a/test/xpu/test_sequence_conv_op_xpu.py +++ b/test/xpu/test_sequence_conv_op_xpu.py @@ -71,10 +71,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, :, diff --git a/test/xpu/test_set_value_op_xpu.py b/test/xpu/test_set_value_op_xpu.py index fe3da75404bffe..688c89263bf0e7 100644 --- a/test/xpu/test_set_value_op_xpu.py +++ b/test/xpu/test_set_value_op_xpu.py @@ -1028,9 +1028,7 @@ class XPUTestSetValueValueShape4(XPUTestSetValueValueShape1): def set_value(self): self.value = np.array( [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]] - ).astype( - self.dtype - ) # shape is (3,4) + ).astype(self.dtype) # shape is (3,4) def _call_setitem(self, x): x[0] = paddle.assign(self.value) # x is Paddle.Tensor diff --git a/test/xpu/test_top_k_v2_op_xpu.py b/test/xpu/test_top_k_v2_op_xpu.py index 3a233f2b716c67..f1b8123e0d3b51 100644 --- a/test/xpu/test_top_k_v2_op_xpu.py +++ b/test/xpu/test_top_k_v2_op_xpu.py @@ -32,9 +32,9 @@ def random_unique_float(shape, dtype): numel = np.prod(shape) arr = np.random.uniform(-10.0, 10.0, numel * 10).astype(dtype) arr = np.unique(arr) - assert ( - arr.shape[0] >= numel - ), f"failed to create enough unique values: {arr.shape[0]} vs {numel}" + assert arr.shape[0] >= numel, ( + f"failed to create enough unique values: {arr.shape[0]} vs {numel}" + ) arr = arr[:numel] np.random.shuffle(arr) arr = arr.reshape(shape)