diff --git a/test/allowlist_for_publicAPI.json b/test/allowlist_for_publicAPI.json index 1b2e46584d999e0abd20aec48cb4dde05750dd0a..8c7fee4b1bc04ae347242761f05888f6e318af7c 100644 --- a/test/allowlist_for_publicAPI.json +++ b/test/allowlist_for_publicAPI.json @@ -2810,83 +2810,12 @@ "TrieNode" ], "torch_npu": [ - "_npu_dropout", - "copy_memory_", - "empty_with_format", - "empty_with_swapped_memory", - "npu_alloc_float_status", - "npu_apply_adam", - "npu_advance_step_flashattn", - "npu_batch_gather_matmul", - "npu_batch_gather_matmul_", - "npu_bert_apply_adam", - "npu_clear_float_status", - "npu_cross_entropy_loss", - "npu_format_cast_", - "npu_fusion_attention", - "npu_fusion_attention_v2", - "npu_get_float_status", - "npu_nms_rotated", - "npu_random_choice_with_mask", - "npu_rms_norm", - "npu_add_rms_norm_cast", - "npu_fused_infer_attention_score", - "npu_fused_infer_attention_v2", - "npu_mla_prolog", - "npu_mla_prolog_v2", - "npu_convert_weight_to_int4pack", - "npu_ffn", - "npu_fused_matmul", - "npu_geglu", - "npu_grouped_matmul", - "npu_quant_matmul", - "npu_quant_scatter", - "npu_scatter_nd_update_", - "npu_swiglu", - "npu_dequant_bias", - "npu_group_quant", - "npu_dynamic_quant", - "npu_dynamic_quant_asymmetric", - "npu_yolo_boxes_encode", - "npu_yolo_boxes_encode", - "npu_gemma_rms_norm", - "npu_weight_quant_batchmatmul", - "npu_transpose", - "npu_trans_quant_param", "npu_stride_add", - "npu_sort_v2", - "npu_dtype_cast", + "npu_group_quant", "npu_gelu", - "npu_gelu_backward", - "npu_all_gather_base_mm", - "npu_mm_reduce_scatter_base", - "npu_prefetch", - "npu_quant_scatter_", - "scatter_update", - "scatter_update_", - "npu_kronecker_quant", - "npu_moe_compute_expert_tokens", + "npu_geglu", "npu_moe_gating_top_k_softmax", - "npu_moe_init_routing", - "npu_group_norm_swish", - "npu_mrope", - "npu_grouped_matmul_finalize_routing", - "npu_alltoallv_gmm", - "npu_gmm_alltoallv", - "npu_nsa_compress", - "npu_nsa_compress_infer", - "npu_nsa_compress_attention", - "npu_nsa_compress_attention_infer", - "npu_nsa_select_attention", - "npu_nsa_select_attention_infer", - "npu_transpose_batchmatmul", - "npu_gather_sparse_index", - "npu_moe_distribute_combine_add_rms_norm", - "npu_moe_eplb_update_expert", - "npu_moe_distribute_dispatch_setup", - "npu_moe_distribute_dispatch_teardown", - "npu_moe_distribute_combine_setup", - "npu_moe_distribute_combine_teardown" + "npu_moe_init_routing" ], "torch_npu.contrib": [ "npu_fused_attention_with_layernorm", diff --git a/test/npu/test_compatibility.py b/test/npu/test_compatibility.py index 9c8dead41e1b95a63fb277ad7f4d13fff508d819..dc9b905fa50aeec9b07253e589fb334d47e8c818 100644 --- a/test/npu/test_compatibility.py +++ b/test/npu/test_compatibility.py @@ -135,7 +135,7 @@ def api_signature(obj, api_str, content, base_schema, failure_list): def func_in_class(obj, content, modname, elem, base_schema, failure_list): class_variables = [attribute for attribute in obj.__dict__.keys() if not attribute.startswith('__') - and callable(getattr(obj, attribute))] + and callable(getattr(obj, attribute))] for variable in class_variables: if variable in ["_backward_cls"]: continue @@ -282,6 +282,10 @@ class TestPublicApiCompatibility(TestCase): return elem_module = getattr(obj, '__module__', None) + # the compatibility of apis from torch._ops.npu is checked in op-plugin. + if elem_module == "torch._ops.npu": + return + modname = allow_dict["being_migrated"].get(modname, modname) elem_modname_starts_with_mod = elem_module is not None and \ elem_module.startswith(modname) and \ @@ -328,6 +332,13 @@ class TestPublicApiCompatibility(TestCase): failure_list.append(f"# {func}:") failure_list.append(f" - {func} has been deleted.") + newly_apis = set(now_funcs) - set(base_funcs) + for func in newly_apis: + failure_list.append(f"# {func}:") + failure_list.append(f" - {func} is new. Please add it to the torch_npu_schema.json") + signature = content[func]["signature"] + failure_list.append(f" - it's signature is {signature}.") + msg = "All the APIs below do not meet the compatibility guidelines. " msg += "If the change timeline has been reached, you can modify the torch_npu_schema.json to make it OK." msg += "\n\nFull list:\n" diff --git a/test/npu/test_public_bindings.py b/test/npu/test_public_bindings.py index 5cd8208ba77ff9abeddd0e702b7fc1dd9b046fbd..4a6910d09de0de82da5427fe4fa828f58fb95ebd 100644 --- a/test/npu/test_public_bindings.py +++ b/test/npu/test_public_bindings.py @@ -663,6 +663,16 @@ class TestPublicBindings(TestCase): except Exception: update_allow_dict_torchair = {} warnings.warn("if you are debugging UT file in clone repo, please recursively update the torchair submodule") + + try: + file_abspath = os.path.abspath(__file__) + op_plugin_path = 'third_party/op-plugin/test/allowlist_for_publicAPI.json' + with open( + os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(file_abspath))), op_plugin_path)) as json_file_op_plugin: + allow_dict_op_plugin = json.load(json_file_op_plugin) + except Exception as e: + allow_dict_op_plugin = {} + warnings.warn(f"{e}") with open(get_file_path_2(os.path.dirname(os.path.dirname(__file__)), 'allowlist_for_publicAPI.json')) as json_file: @@ -681,7 +691,13 @@ class TestPublicBindings(TestCase): if update_allow_dict_torchair: allow_dict.update(update_allow_dict_torchair) - + + if allow_dict_op_plugin and "torch_npu" in allow_dict_op_plugin: + if "torch_npu" in allow_dict: + allow_dict["torch_npu"].extend(allow_dict_op_plugin["torch_npu"]) + else: + allow_dict.update(allow_dict_op_plugin["torch_npu"]) + def test_module(modname): try: if "__main__" in modname or \ diff --git a/test/torch_npu_schema.json b/test/torch_npu_schema.json index a672730f6f165c1ec1d6c6b7a1ded9eccef3eb1b..20e201dd032a093098e314c70b781060dbd06dfb 100644 --- a/test/torch_npu_schema.json +++ b/test/torch_npu_schema.json @@ -701,6 +701,48 @@ "torch_npu.dynamo.torchair.npu_fx_compiler.get_npu_backend": { "signature": "(*, compiler_config: torchair.configs.compiler_config.CompilerConfig = None, custom_decompositions: Dict = {})" }, + "torch_npu.profiler.profile._set_step_num_offset_for_dynamic_prof": { + "signature": "(self, step: int)" + }, + "torch_npu.profiler.experimental_config.HostSystem": { + "signature": "()" + }, + "torch_npu.utils.save_async": { + "signature": "(obj: object, f, pickle_module: Any = , pickle_protocol: int = 2, _use_new_zipfile_serialization: bool = True, _disable_byteorder_record: bool = False, model: torch.nn.modules.module.Module = None) -> None" + }, + "torch_npu.profiler.profiler.profile._set_step_num_offset_for_dynamic_prof": { + "signature": "(self, step: int)" + }, + "torch_npu.dynamo.torchair.ops.npu_fused_infer_attention_score": { + "signature": "(*args, **kwargs)" + }, + "torch_npu.dynamo.torchair.ops.npu_fused_infer_attention_v2": { + "signature": "(*args, **kwargs)" + }, + "torch_npu.profiler._ExperimentalConfig._check_host_sys_params": { + "signature": "(self)" + }, + "torch_npu.profiler.HostSystem": { + "signature": "()" + }, + "torch_npu.profiler.experimental_config._ExperimentalConfig._check_host_sys_params": { + "signature": "(self)" + }, + "torch_npu.dynamo.torchair.ops.npu_tagged_event_wait": { + "signature": "(event)" + }, + "torch_npu.utils.serialization.save_async": { + "signature": "(obj: object, f, pickle_module: Any = , pickle_protocol: int = 2, _use_new_zipfile_serialization: bool = True, _disable_byteorder_record: bool = False, model: torch.nn.modules.module.Module = None) -> None" + }, + "torch_npu.npu.NPUGraph.update": { + "signature": "(self, cpu_update_input)" + }, + "torch_npu.npu.graphs.NPUGraph.update": { + "signature": "(self, cpu_update_input)" + }, + "torch_npu.dynamo.torchair.ops.npu_tagged_event_record": { + "signature": "(event)" + }, "torch_npu.jit.optimize": { "signature": "(jit_mod)" }, @@ -785,9 +827,6 @@ "torch_npu.npu.NPUGraph.capture_end": { "signature": "(self)" }, - "torch_npu.npu_mla_prolog": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu.MemPoolContext": { "signature": "(pool: torch_npu.npu.memory.MemPool)" }, @@ -806,9 +845,6 @@ "torch_npu.npu.graphs.NPUGraph.reset": { "signature": "(self)" }, - "torch_npu.npu_cross_entropy_loss": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu.memory.use_mem_pool": { "signature": "(pool: torch_npu.npu.memory.MemPool, device=None)" }, @@ -818,15 +854,9 @@ "torch_npu.npu.graphs.graph_task_update_begin": { "signature": "(stream, handle)" }, - "torch_npu.npu_grouped_matmul_finalize_routing": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu.streams.ExternalEvent.record": { "signature": "(self, stream=None)" }, - "torch_npu.npu_advance_step_flashattn": { - "signature": "(*args, **kwargs)" - }, "torch_npu.contrib.module.activations.Swish.forward": { "signature": "(self, x)" }, @@ -857,15 +887,6 @@ "torch_npu.contrib.module.activations.SiLU.forward": { "signature": "(self, x)" }, - "torch_npu.empty_with_swapped_memory": { - "signature": "(*args, **kwargs)" - }, - "torch_npu.npu_gmm_alltoallv": { - "signature": "(*args, **kwargs)" - }, - "torch_npu.npu_mrope": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu.streams.Event.recorded_time": { "signature": "(self)" }, @@ -881,9 +902,6 @@ "torch_npu.npu.Event.recorded_time": { "signature": "(self)" }, - "torch_npu.npu_alltoallv_gmm": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu.graphs.NPUGraph.replay": { "signature": "(self)" }, @@ -893,9 +911,6 @@ "torch_npu.npu.NPUGraph.replay": { "signature": "(self)" }, - "torch_npu.npu_group_norm_swish": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu.graphs.NPUGraph.capture_end": { "signature": "(self)" }, @@ -2459,15 +2474,9 @@ "torch_npu.utils.syncbatchnorm.SyncBatchNorm.backward": { "signature": "(self, grad_output)" }, - "torch_npu._npu_dropout": { - "signature": "(*args, **kwargs)" - }, "torch_npu.fast_gelu": { "signature": "(self)" }, - "torch_npu.npu_alloc_float_status": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_anchor_response_flags": { "signature": "(self, featmap_size, stride, num_base_anchors)" }, @@ -2477,9 +2486,6 @@ "torch_npu.npu_batch_nms": { "signature": "(self, scores, score_threshold, iou_threshold, max_size_per_class, max_total_size, change_coordinate_frame=False, transpose_box=False)" }, - "torch_npu.npu_bert_apply_adam": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_bmmV2": { "signature": "(self, mat2, output_sizes)" }, @@ -2489,18 +2495,12 @@ "torch_npu.npu_bounding_box_encode": { "signature": "(anchor_box, ground_truth_box, means0, means1, means2, means3, stds0, stds1, stds2, stds3)" }, - "torch_npu.npu_clear_float_status": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_confusion_transpose": { "signature": "(self, perm, shape, transpose_first)" }, "torch_npu.npu_conv3d": { "signature": "(input_, weight, bias, stride, padding, dilation, groups)" }, - "torch_npu.npu_convert_weight_to_int4pack": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_deformable_conv2d": { "signature": "(inputs, weight, offset, bias, kernel_size, stride, padding, dilation=[1, 1, 1, 1], groups=1, deformable_groups=1, modulated=True)" }, @@ -2522,33 +2522,18 @@ "torch_npu.npu_stride_add": { "signature": "(self, other, offset1, offset2, c1_len)" }, - "torch_npu.npu_ffn": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_format_cast": { "signature": "(self, acl_format, customize_dtype=None)" }, - "torch_npu.npu_format_cast_": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_fused_attention_score": { "signature": "(query_layer, key_layer, value_layer, attention_mask, scale, keep_prob, query_transpose=False, key_transpose=False, bmm_score_transpose_a=False, bmm_score_transpose_b=False, value_transpose=False, dx_transpose=False)" }, - "torch_npu.npu_fusion_attention": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_geglu": { "signature": "(self, dim=-1, approximate=1, activate_left=False)" }, - "torch_npu.npu_get_float_status": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_grid_assign_positive": { "signature": "(self, overlaps, box_responsible_flags, max_overlaps, argmax_overlaps, gt_max_overlaps, gt_argmax_overlaps, num_gts, pos_iou_thr, min_pos_iou, gt_max_assign_all)" }, - "torch_npu.npu_grouped_matmul": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_incre_flash_attention": { "signature": "(self, query, key, value, padding_mask, atten_mask, pse_shift, actual_seq_lengths, num_heads, scale_value, input_layout, num_key_value_heads)" }, @@ -2585,15 +2570,6 @@ "torch_npu.npu_ps_roi_pooling": { "signature": "(self, rois, spatial_scale, group_size, output_dim)" }, - "torch_npu.npu_quant_matmul": { - "signature": "(*args, **kwargs)" - }, - "torch_npu.npu_quant_scatter": { - "signature": "(*args, **kwargs)" - }, - "torch_npu.npu_random_choice_with_mask": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_rms_norm": { "signature": "(self, gamma, epsilon=1e-06)" }, @@ -2615,9 +2591,6 @@ "torch_npu.npu_scatter_nd_update": { "signature": "(self, indices, updates)" }, - "torch_npu.npu_scatter_nd_update_": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_sign_bits_pack": { "signature": "(self, size)" }, @@ -2630,18 +2603,9 @@ "torch_npu.npu_softmax_cross_entropy_with_logits": { "signature": "(self, labels)" }, - "torch_npu.npu_swiglu": { - "signature": "(*args, **kwargs)" - }, - "torch_npu.npu_trans_quant_param": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_transpose": { "signature": "(self, perm, require_contiguous=True, out=None)" }, - "torch_npu.npu_transpose_batchmatmul": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_weight_quant_batchmatmul": { "signature": "(x, weight, antiquant_scale, antiquant_offset=None, quant_scale=None, quant_offset=None, bias=None, antiquant_group_size=0, inner_precise=0)" }, @@ -2672,36 +2636,15 @@ "torch_npu.utils.FlopsCounter.get_flops": { "signature": "(self)" }, - "torch_npu.scatter_update": { - "signature": "(*args, **kwargs)" - }, - "torch_npu.scatter_update_": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_quantize": { "signature": "(inputs, scales, zero_points, dtype, axis, div_mode=True)" }, - "torch_npu.npu_quant_scatter_": { - "signature": "(*args, **kwargs)" - }, - "torch_npu.npu_prefetch": { - "signature": "(*args, **kwargs)" - }, - "torch_npu.npu_moe_init_routing": { - "signature": "(*args, **kwargs)" - }, - "torch_npu.npu_moe_gating_top_k_softmax": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_moe_finalize_routing": { "signature": "(expanded_permuted_rows, skip1, skip2, bias, scales, expanded_src_to_dst_row, export_for_source_row, drop_pad_mode=0)" }, "torch_npu.npu_moe_compute_expert_tokens": { "signature": "(sorted_experts, num_experts=1)" }, - "torch_npu.npu_mm_reduce_scatter_base": { - "signature": "(*args, **kwargs)" - }, "torch_npu.npu_group_norm_silu": { "signature": "(x, gamma, beta, group, eps=1e-05)" }, @@ -2711,18 +2654,33 @@ "torch_npu.npu_fast_gelu": { "signature": "(self)" }, - "torch_npu.npu_all_gather_base_mm": { - "signature": "(*args, **kwargs)" - }, "torch_npu.utils.set_thread_affinity": { "signature": "(core_range: List[int] = None)" }, "torch_npu.utils.reset_thread_affinity": { "signature": "()" }, + "torch_npu.npu.npu_config.set_device_limit": { + "signature": "(*args, **kwargs)" + }, + "torch_npu.npu.set_device_limit": { + "signature": "(*args, **kwargs)" + }, + "torch_npu.npu.get_device_limit": { + "signature": "(device)" + }, + "torch_npu.npu.npu_config.get_device_limit": { + "signature": "(device)" + }, "torch_npu.dynamo.torchair.scope.npu_stream_switch": { "signature": "(stream_tag: str, stream_priority: int = 0)" }, + "torch_npu.dynamo.torchair.ops.npu_record_tagged_stream":{ + "signature": "(self: torch.Tensor, tagged_stream: str)" + }, + "torch_npu.dynamo.torchair.ops.npu_create_tagged_event": { + "signature": "(tag: str)" + }, "torch_npu.dynamo.torchair.scope.npu_wait_tensor": { "signature": "(self: torch.Tensor, dependency: torch.Tensor)" },