已合并
[feature] add torchnpugen packages #30023
梁松伟创建于 1月26日
[feature] add torchnpugen packages #30023
已合并
共 31 个文件变更+844-844
| @@ -16,7 +16,7 @@ from distutils import file_util | |||
| 16 | # Disable autoloading before running 'import torch' to avoid circular dependencies | 16 | # Disable autoloading before running 'import torch' to avoid circular dependencies |
| 17 | os.environ["TORCH_DEVICE_BACKEND_AUTOLOAD"] = "0" | 17 | os.environ["TORCH_DEVICE_BACKEND_AUTOLOAD"] = "0" |
| 18 | 18 | ||
| 19 | -from codegen.utils import PathManager | 19 | +from torchnpugen.utils import PathManager |
| 20 | 20 | ||
| 21 | BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 21 | BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 22 | PathManager.check_directory_path_readable(os.path.join(BASE_DIR, "version.txt")) | 22 | PathManager.check_directory_path_readable(os.path.join(BASE_DIR, "version.txt")) |
| @@ -29,7 +29,7 @@ from wheel.bdist_wheel import bdist_wheel | |||
| 29 | # Disable autoloading before running 'import torch' to avoid circular dependencies | 29 | # Disable autoloading before running 'import torch' to avoid circular dependencies |
| 30 | os.environ["TORCH_DEVICE_BACKEND_AUTOLOAD"] = "0" | 30 | os.environ["TORCH_DEVICE_BACKEND_AUTOLOAD"] = "0" |
| 31 | 31 | ||
| 32 | -from codegen.utils import PathManager | 32 | +from torchnpugen.utils import PathManager |
| 33 | 33 | ||
| 34 | BASE_DIR = os.path.dirname(os.path.realpath(__file__)) | 34 | BASE_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 35 | THIRD_PARTY_PATH = os.path.join(BASE_DIR, "third_party") | 35 | THIRD_PARTY_PATH = os.path.join(BASE_DIR, "third_party") |
| @@ -20,8 +20,8 @@ from torchgen.model import ( | |||
| 20 | TensorOptionsArguments | 20 | TensorOptionsArguments |
| 21 | ) | 21 | ) |
| 22 | from torchgen.api.types import Binding | 22 | from torchgen.api.types import Binding |
| 23 | -from codegen.gen_backend_stubs import parse_native_and_custom_yaml | 23 | +from torchnpugen.gen_backend_stubs import parse_native_and_custom_yaml |
| 24 | -from codegen.utils import CUSTOM_YAML_NAME | 24 | +from torchnpugen.utils import CUSTOM_YAML_NAME |
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | def parse_native_and_custom_yaml_(*args, **kwargs): | 27 | def parse_native_and_custom_yaml_(*args, **kwargs): |
| @@ -2,10 +2,10 @@ | |||
| 2 | To run this file by hand from the root of the PyTorch | 2 | To run this file by hand from the root of the PyTorch |
| 3 | repository, run: | 3 | repository, run: |
| 4 | 4 | ||
| 5 | -python -m codegen.autograd.gen_autograd \ | 5 | +python -m torchnpugen.autograd.gen_autograd \ |
| 6 | --npu_native_function_dir="./torch_npu/csrc/aten/npu_native_functions.yaml" \ | 6 | --npu_native_function_dir="./torch_npu/csrc/aten/npu_native_functions.yaml" \ |
| 7 | --out_dir=$OUTPUT_DIR \ | 7 | --out_dir=$OUTPUT_DIR \ |
| 8 | - --autograd_dir="./codegen/autograd/" | 8 | + --autograd_dir="./torchnpugen/autograd/" |
| 9 | 9 | ||
| 10 | Where $OUTPUT_DIR is where you would like the files to be | 10 | Where $OUTPUT_DIR is where you would like the files to be |
| 11 | generated. In the full build system, OUTPUT_DIR is | 11 | generated. In the full build system, OUTPUT_DIR is |
| @@ -24,7 +24,7 @@ import os | |||
| 24 | from torchgen.packaged.autograd.gen_inplace_or_view_type import gen_inplace_or_view_type | 24 | from torchgen.packaged.autograd.gen_inplace_or_view_type import gen_inplace_or_view_type |
| 25 | from torchgen.packaged.autograd.gen_autograd_functions import gen_autograd_functions_lib | 25 | from torchgen.packaged.autograd.gen_autograd_functions import gen_autograd_functions_lib |
| 26 | 26 | ||
| 27 | -from codegen.utils import get_torchgen_dir, gen_custom_yaml_path | 27 | +from torchnpugen.utils import get_torchgen_dir, gen_custom_yaml_path |
| 28 | from .gen_variable_type import ( | 28 | from .gen_variable_type import ( |
| 29 | gen_variable_type, gen_variable_type_head | 29 | gen_variable_type, gen_variable_type_head |
| 30 | ) | 30 | ) |
Rcodegen/autograd/templates/ADInplaceOrViewType.cpp→torchnpugen/autograd/templates/ADInplaceOrViewType.cpp+0-0
文件重命名但无更改。
Rcodegen/autograd/templates/python_functions.cpp→torchnpugen/autograd/templates/python_functions.cpp+0-0
文件重命名但无更改。
Rcodegen/autograd/templates/python_functions.h→torchnpugen/autograd/templates/python_functions.h+0-0
文件重命名但无更改。
| @@ -9,8 +9,8 @@ from torchgen.api.autograd import ( | |||
| 9 | ) | 9 | ) |
| 10 | from torchgen.packaged.autograd.load_derivatives import load_derivatives | 10 | from torchgen.packaged.autograd.load_derivatives import load_derivatives |
| 11 | 11 | ||
| 12 | -from codegen.utils import get_torchgen_dir, CUSTOM_YAML_NAME, PathManager | 12 | +from torchnpugen.utils import get_torchgen_dir, CUSTOM_YAML_NAME, PathManager |
| 13 | -from codegen.gen_backend_stubs import parse_native_and_custom_yaml | 13 | +from torchnpugen.gen_backend_stubs import parse_native_and_custom_yaml |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | AUTOGRAD_BLACK_LIST = {'npu_format_cast.Tensor', 'npu_format_cast_', 'npu_format_cast_.acl_format'} | 16 | AUTOGRAD_BLACK_LIST = {'npu_format_cast.Tensor', 'npu_format_cast_', 'npu_format_cast_.acl_format'} |
| @@ -9,8 +9,8 @@ import yaml | |||
| 9 | from torchgen.code_template import CodeTemplate | 9 | from torchgen.code_template import CodeTemplate |
| 10 | from torchgen.gen import FileManager | 10 | from torchgen.gen import FileManager |
| 11 | 11 | ||
| 12 | -from codegen.autograd.utils import VERSION_PART | 12 | +from torchnpugen.autograd.utils import VERSION_PART |
| 13 | -from codegen.utils import PathManager | 13 | +from torchnpugen.utils import PathManager |
| 14 | 14 | ||
| 15 | project_path = Path(os.path.dirname(__file__)).parent | 15 | project_path = Path(os.path.dirname(__file__)).parent |
| 16 | op_plugin_info_path = os.path.realpath(os.path.join( | 16 | op_plugin_info_path = os.path.realpath(os.path.join( |
| @@ -96,7 +96,7 @@ def gen_ops_info(summary_dict): | |||
| 96 | skip_template = CodeTemplate( | 96 | skip_template = CodeTemplate( |
| 97 | """\n'${op_name}': [${decorators}]""" | 97 | """\n'${op_name}': [${decorators}]""" |
| 98 | ) | 98 | ) |
| 99 | - fm = FileManager(os.path.join("torch_npu", "testing"), os.path.join("codegen", "templates"), False) | 99 | + fm = FileManager(os.path.join("torch_npu", "testing"), os.path.join("torchnpugen", "templates"), False) |
| 100 | 100 | ||
| 101 | fm.write_with_template(f"_npu_testing_utils.py", "npu_testing_utils.py", lambda:{ | 101 | fm.write_with_template(f"_npu_testing_utils.py", "npu_testing_utils.py", lambda:{ |
| 102 | "skip_detail": [skip_template.substitute(op_name=op, decorators=doc) for op, doc in skip_list.items()] | 102 | "skip_detail": [skip_template.substitute(op_name=op, decorators=doc) for op, doc in skip_list.items()] |
| @@ -13,7 +13,7 @@ from torchgen.context import with_native_function, native_function_manager, meth | |||
| 13 | from torchgen.api.types import DispatcherSignature | 13 | from torchgen.api.types import DispatcherSignature |
| 14 | from torchgen.api import cpp | 14 | from torchgen.api import cpp |
| 15 | from torchgen.dest.register_dispatch_key import RegisterDispatchKey | 15 | from torchgen.dest.register_dispatch_key import RegisterDispatchKey |
| 16 | -from codegen.utils import (enable_opplugin, is_op_valid, field_tag, get_opplugin_wrap_name, parse_npu_yaml, | 16 | +from torchnpugen.utils import (enable_opplugin, is_op_valid, field_tag, get_opplugin_wrap_name, parse_npu_yaml, |
| 17 | gen_op_hook_post_code) | 17 | gen_op_hook_post_code) |
| 18 | 18 | ||
| 19 | 19 | ||
Rcodegen/templates/RegisterFunctionalization.cpp→torchnpugen/templates/RegisterFunctionalization.cpp+0-0
文件重命名但无更改。
| @@ -198,7 +198,7 @@ def filt_compositeimplicitautograd_api(native_yaml_path, npu_supported): | |||
| 198 | with open(native_yaml_path, 'r') as f: | 198 | with open(native_yaml_path, 'r') as f: |
| 199 | es = yaml.safe_load(f) | 199 | es = yaml.safe_load(f) |
| 200 | 200 | ||
| 201 | - from codegen.autograd.utils import TORCH_AUTOGRAD_FUNCTION | 201 | + from torchnpugen.autograd.utils import TORCH_AUTOGRAD_FUNCTION |
| 202 | supported_autograd = [] | 202 | supported_autograd = [] |
| 203 | for e in es: | 203 | for e in es: |
| 204 | api_name = e['func'].split('(')[0] | 204 | api_name = e['func'].split('(')[0] |


代码维护性: 代码中使用了硬编码的模块路径
torchnpugen.gen_backend_stubs。虽然从上下文看,这可能是从codegen.gen_backend_stubs重命名而来,但硬编码的模块名降低了脚本的灵活性。如果未来模块结构或命名再次发生变化,需要修改此脚本。结合第32行和第38行的类似改动,这属于批量重命名操作,但未考虑使用变量或参数来配置模块路径,使得脚本与特定的代码组织结构耦合。问题类型: 代码维护性 文件路径:
generate_code.sh行号: 26 问题代码:${python_execute} -m torchnpugen.gen_backend_stubs \修改建议:
此评论由代码审查工具自动生成