Files
TorchNPU/.lintrunner.toml
c_34 0296ffac1f feat: integrate fxrt as in-tree subpackage of torch_npu build and wheel
Co-authored-by: chenhaozhe<chenhaozhe1@huawei.com>



# message auto-generated for no-merge-commit merge:
!45813 merge fxrt-src into master

feat: integrate fxrt as in-tree subpackage of torch_npu build and wheel

Created-by: c_34
Commit-by: chenhaozhe
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>

- [ ] 需求
- [ ] 问题单
- [x] issue/工单  https://gitcode.com/Ascend/pytorch/issues/4733
- [ ] 重构优化
- [ ] 资料更新

## 目的

将 fxrt(FX 图运行时)以源码方式合入 torch_npu,随 torch_npu 一起编译打包,用户安装 torch_npu 后即可直接使用,无需单独安装 fxrt。

###  概述

将 FX 图运行时 fxrt 放入 `fxrt/` 目录,随 torch_npu 一起构建,以 `torch_npu.fxrt` 子包的形式发布,不再单独发包。

diff 主体是 `fxrt/` 下的源码。对 torch_npu 已有代码的改动为 19 个文件、约 270 行,其中约 200 行是新增测试。

### 对 torch_npu 的影响

- `import torch_npu` 不加载 fxrt,行为不变;fxrt 在 `import torch_npu.fxrt` 时才加载。
- 导入 fxrt 不改动 inductor,需显式调用 `torch_npu.fxrt.register_fx_wrapper()` 才会接管。
- C++ 接口唯一改动:导出 `npu_logging::Logger`。
- `--disable_fxrt` 可构建不含 fxrt 的 wheel。


# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)

**构建接入**(沿用 torchair 方式)
- `setup.py`:检测到 `fxrt/fxrt` 时传入 `BUILD_FXRT`、`FXRT_INSTALL_DST`、`FXRT_TARGET_PYTHON`;package_data` 增加 fxrt 的 `.so`。fxrt 暂不提供 C++ 接口,wheel 中不含 fxrt 头文件。
- `CMakeLists.txt`:在 `torch_npu` target 之后 `add_subdirectory(fxrt/fxrt)`。
- `ci/build.sh`:新增 `--disable_fxrt`。

fxrt 的依赖(ACL/HCCL stub、nlohmann、DVM)均复用仓库内已有内容,构建时不下载,也不依赖 CANN 安装。fxrt 库的 RPATH 包含 `torch_npu/lib`,auditwheel 可在 wheel 内解析 `libtorch_npu.so` 及其依赖。

**日志**
- `torch_npu/_logging/_internal.py`:注册 `fxrt` 日志别名,`TORCH_NPU_LOGS=+fxrt` 控制 fxrt 的 C++ 和 Python 日志。
- `torch_npu/csrc/logging/Logger.h`:`Logger` 加 `TORCH_NPU_API`。torch_npu 以 `-fvisibility=hidden` 编译,fxrt 调用 `Logger` 成员函数需要导出符号,实现不变。
- `TORCH_NPU_LOGS.md`:模块表增加 `fxrt`。

**构建依赖**
- nanobind 仅构建时需要(静态链接,运行时不依赖),加入 `requirements*-build.txt`、`.ci/docker/requirements-builder.txt`(`==2.13.0`)、`ci/docker` 的 Dockerfile 和源码构建指南。

**测试与门禁**
- 新增 `test/fxrt`(7 个用例,fxrt 未构建时跳过):fxrt 后端编译运行;`import torch_npu` / `import torch_npu.fxrt` 无副作用;`register_fx_wrapper()` 注册行为。
- `test/npu/test_public_bindings.py`:模块名检查跳过 `torch_npu.fxrt`。fxrt 以顶层包名 `fxrt` 执行,对象的 `__module__` 为 `fxrt.*`;导入检查不跳过。
- `.lintrunner.toml`:fxrt C++ 源码纳入 clang-format 检查。
- `tools/linter/dictionary.txt`:增加 `hax`(fxrt 哈希实现中的变量名)。

详见RFC issue

# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”

当前版本不涉及

# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”

新增demo特性,不涉及历史接口版本变更,demo特性已进行隔离,默认不开启。

# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图

当前作为demo能力,默认不主动使能的情况下,要求不修改任何pytorch_npu已有逻辑和行为。

主要验证:
1. 构建打包安装行为不影响torch-npu的包。
2. 不主动使能情况下,原有torch-npu行为不受fxrt任何影响。

关于新增依赖的缺陷扫描,主要新增一个nanobind作为构建过程中的python依赖,扫描结果如下,引入依赖版本无安全缺陷报告:

![image.png](https://raw.gitcode.com/user-images/assets/7404318/d89bf7a3-a681-4c13-bab4-fb0c4e22168e/image.png 'image.png')


# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!45813
2026-09-23 11:17:05 +08:00

1816 lines
55 KiB
TOML

[[linter]]
code = 'FLAKE8'
include_patterns = ['**/*.py']
exclude_patterns = [
'.git/**',
'build_test_custom_build/**',
'build/**',
'caffe2/**',
'docs/caffe2/**',
'docs/cpp/src/**',
'docs/src/**',
'fb/**',
'**/fb/**',
'functorch/docs/**',
'functorch/examples/**',
'functorch/docs/source/tutorials/**',
'torch_npu/_inductor/fx_passes/serialized_patterns/**',
'torch_npu/_inductor/autoheuristic/artifacts/**',
'torch_npu/_inductor/kernel/vendored_templates/cutedsl/kernels/**',
'torch_npu/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py',
'scripts/**',
'test/generated_type_hints_smoketest.py',
'test/test_torchfuzz_repros.py',
# CPython tests
'test/dynamo/cpython/**',
# Tests from the NumPy test suite
'test/torch_np/numpy_test/**/*.py',
'third_party/**',
'torch_npu/include/**',
'torch_npu/lib/**',
'torch/include/**',
'torch/lib/**',
'venv/**',
'**/*.pyi',
"tools/experimental/torchfuzz/**",
'tools/test/test_selective_build.py',
]
command = [
'uv',
'run',
'--script',
'tools/linter/adapters/flake8_linter.py',
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'CLANGFORMAT'
include_patterns = [
'torch_npu/csrc/**/*.h',
'torch_npu/csrc/**/*.hpp',
'torch_npu/csrc/**/*.cpp',
'torch_npu/nativert/**/*.h',
'test/cpp/**/*.h',
'test/cpp/**/*.cpp',
'fxrt/**/*.h',
'fxrt/**/*.cpp',
]
exclude_patterns = [
'**/fb/**',
'torch_npu/csrc/inductor/aoti_torch/generated/**',
'torch_npu/csrc/jit/serialization/mobile_bytecode_generated.h',
'torch_npu/csrc/utils/pythoncapi_compat.h',
]
init_command = [
'python3',
'tools/linter/adapters/s3_init.py',
'--config-json=tools/linter/adapters/s3_init_config.json',
'--linter=clang-format',
'--dry-run={{DRYRUN}}',
'--output-dir=.lintbin',
'--output-name=clang-format',
]
command = [
'python3',
'tools/linter/adapters/clangformat_linter.py',
'--binary=.lintbin/clang-format',
'--',
'@{{PATHSFILE}}'
]
is_formatter = true
# [[linter]]
# code = 'PYREFLY'
# include_patterns = [
# 'torch_npu/**/*.py',
# 'torch_npu/**/*.pyi',
# 'torchgen/**/*.py',
# 'torchgen/**/*.pyi',
# 'functorch/**/*.py',
# 'functorch/**/*.pyi',
# 'tools/**/*.py',
# 'tools/**/*.pyi',
# ]
# exclude_patterns = [
# 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/kernels/**',
# 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py',
# 'tools/linter/**',
# 'tools/setup_helpers/**',
# ]
# command = [
# 'uv',
# 'run',
# '--script',
# 'tools/linter/adapters/pyrefly_linter.py',
# '--config=pyrefly.toml',
# ]
# [[linter]]
# code = 'CLANGTIDY'
# include_patterns = [
# # Enable coverage of headers in aten/src/ATen
# # and excluding most sub-directories for now.
# 'aten/src/ATen/*.h',
# 'aten/src/ATen/*.cpp',
# 'aten/src/ATen/cuda/*.cpp',
# 'aten/src/ATen/cpu/*.h',
# 'aten/src/ATen/cpu/*.cpp',
# 'aten/src/ATen/accelerator/**/*.h',
# 'aten/src/ATen/accelerator/**/*.cpp',
# 'aten/src/ATen/core/*.h',
# 'aten/src/ATen/core/*.cpp',
# 'aten/src/ATen/cudnn/*.h',
# 'aten/src/ATen/cudnn/*.cpp',
# 'aten/src/ATen/native/mkldnn/xpu/**/*.h',
# 'aten/src/ATen/native/mkldnn/xpu/**/*.cpp',
# 'aten/src/ATen/detail/*',
# 'aten/src/ATen/functorch/*.h',
# 'aten/src/ATen/functorch/*.cpp',
# 'aten/src/ATen/native/nested/cuda/*.cpp',
# 'aten/src/ATen/native/nested/cuda/*.h',
# 'aten/src/ATen/native/nested/*.cpp',
# 'aten/src/ATen/native/nested/*.h',
# 'aten/src/ATen/xpu/**/*.h',
# 'aten/src/ATen/xpu/**/*.cpp',
# 'c10/**/*.cpp',
# 'c10/**/*.h',
# 'torch_npu/*.h',
# 'torch_npu/_inductor/codegen/aoti_runtime/*.h',
# 'torch_npu/_inductor/codegen/aoti_runtime/*.cpp',
# 'torch_npu/csrc/*.h',
# 'torch_npu/csrc/*.cpp',
# 'torch_npu/csrc/**/*.h',
# 'torch_npu/csrc/**/*.cpp',
# 'torch_npu/csrc/jit/serialization/*.h',
# 'torch_npu/csrc/jit/serialization/*.cpp',
# 'torch_npu/nativert/*.h',
# 'torch_npu/nativert/*.cpp',
# 'torch_npu/nativert/**/*.h',
# 'torch_npu/nativert/**/*.cpp',
# 'torch_npu/headeronly/**/*.h',
# ]
# exclude_patterns = [
# # The negative filters below are to exclude files that include onnx_pb.h or
# # caffe2_pb.h, otherwise we'd have to build protos as part of this CI job.
# # CUDA files are also excluded.
# '**/fb/**',
# '**/generated/**',
# '**/*pb.h',
# '**/*inl.h',
# 'aten/src/ATen/cpu/FlushDenormal.cpp',
# 'aten/src/ATen/cpu/vml.h',
# 'aten/src/ATen/CPUFixedAllocator.h',
# 'aten/src/ATen/Parallel*.h',
# 'c10/xpu/**/*.h',
# 'c10/xpu/**/*.cpp',
# 'c10/benchmark/intrusive_ptr_benchmark.cpp',
# 'c10/cuda/CUDAAlgorithm.h',
# 'c10/util/complex_math.h',
# 'c10/util/complex_utils.h',
# 'c10/util/flat_hash_map.h',
# 'c10/util/logging*.h',
# 'c10/metal/*.h',
# 'c10/util/hash.h',
# 'c10/util/strong_type.h',
# 'c10/util/SmallVector.h',
# 'c10/util/win32-headers.h',
# 'c10/test/**/*.h',
# 'c10/test/**/*.cpp',
# 'third_party/**/*',
# 'torch_npu/csrc/autograd/generated/**',
# 'torch_npu/csrc/distributed/**/*.cu',
# 'torch_npu/csrc/distributed/c10d/WinSockUtils.hpp',
# 'torch_npu/csrc/distributed/c10d/quantization/quantization_gpu.h',
# 'torch_npu/csrc/dynamo/eval_frame.h',
# 'torch_npu/csrc/inductor/aoti_torch/c/shim.h',
# 'torch_npu/csrc/jit/**/*',
# 'torch_npu/csrc/jit/serialization/mobile_bytecode_generated.h',
# 'torch_npu/csrc/utils/generated_serialization_types.h',
# 'torch_npu/csrc/utils/pythoncapi_compat.h',
# 'torch_npu/csrc/inductor/aoti_runtime/sycl_runtime_wrappers.h',
# ]
# init_command = [
# 'python3',
# 'tools/linter/adapters/s3_init.py',
# '--config-json=tools/linter/adapters/s3_init_config.json',
# '--linter=clang-tidy',
# '--dry-run={{DRYRUN}}',
# '--output-dir=.lintbin',
# '--output-name=clang-tidy',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/clangtidy_linter.py',
# '--binary=.lintbin/clang-tidy',
# '--build_dir=./build',
# '--',
# '@{{PATHSFILE}}'
# ]
# [[linter]]
# code = 'CLANGTIDY_EXECUTORCH_COMPATIBILITY'
# include_patterns = [
# # c10 headers that must be C++17 compatible
# 'c10/macros/Export.h',
# 'c10/macros/Macros.h',
# 'c10/macros/cmake_macros.h',
# 'c10/util/BFloat16.h',
# 'c10/util/BFloat16-inl.h',
# 'c10/util/BFloat16-math.h',
# 'c10/util/Half.h',
# 'c10/util/Half-inl.h',
# 'c10/util/TypeSafeSignMath.h',
# 'c10/util/bit_cast.h',
# 'c10/util/complex.h',
# 'c10/util/floating_point_utils.h',
# 'c10/util/irange.h',
# 'c10/util/llvmMathExtras.h',
# 'c10/util/overflows.h',
# 'c10/util/safe_numerics.h',
# # torch_npu/headeronly headers that must be C++17 compatible
# 'torch_npu/headeronly/macros/cmake_macros.h',
# 'torch_npu/headeronly/macros/Export.h',
# 'torch_npu/headeronly/macros/Macros.h',
# 'torch_npu/headeronly/util/BFloat16.h',
# 'torch_npu/headeronly/util/Half.h',
# 'torch_npu/headeronly/util/TypeSafeSignMath.h',
# 'torch_npu/headeronly/util/bit_cast.h',
# 'torch_npu/headeronly/util/complex.h',
# 'torch_npu/headeronly/util/floating_point_utils.h',
# ]
# exclude_patterns = [
# '**/fb/**',
# ]
# init_command = [
# 'python3',
# 'tools/linter/adapters/s3_init.py',
# '--config-json=tools/linter/adapters/s3_init_config.json',
# '--linter=clang-tidy',
# '--dry-run={{DRYRUN}}',
# '--output-dir=.lintbin',
# '--output-name=clang-tidy',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/clangtidy_linter.py',
# '--binary=.lintbin/clang-tidy',
# '--build_dir=./build',
# '--std=c++17',
# '--',
# '@{{PATHSFILE}}'
# ]
[[linter]]
code = 'TYPEIGNORE'
include_patterns = ['**/*.py', '**/*.pyi']
exclude_patterns = [
'fb/**',
'**/fb/**',
'test/test_jit.py',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=# type:\s*ignore([^\[]|$)',
'--linter-name=TYPEIGNORE',
'--error-name=unqualified type: ignore',
"""--error-description=\
This line has an unqualified `type: ignore`; \
please convert it to `type: ignore[xxxx]`\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'TYPENOSKIP'
include_patterns = ['mypy.ini']
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=follow_imports\s*=\s*skip',
'--linter-name=TYPENOSKIP',
'--error-name=use of follow_imports = skip',
"""--error-description=\
follow_imports = skip is forbidden from mypy.ini configuration as it \
is extremely easy to accidentally turn off type checking unintentionally. If \
you need to suppress type errors, use a top level # mypy: ignore-errors. \
Do not rely on automatic Any substitution; instead, manually # type: ignore \
at use sites or define a pyi type stub with more relaxed types. \
""",
'--',
'@{{PATHSFILE}}'
]
# [[linter]]
# code = 'NOQA'
# include_patterns = ['**/*.py', '**/*.pyi']
# exclude_patterns = [
# 'caffe2/**',
# 'fb/**',
# '**/fb/**'
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/grep_linter.py',
# '--pattern=# noqa([^:]|$)',
# '--linter-name=NOQA',
# '--error-name=unqualified noqa',
# """--error-description=\
# This line has an unqualified `noqa`; \
# please convert it to `noqa: XXXX`\
# """,
# '--',
# '@{{PATHSFILE}}'
# ]
[[linter]]
code = 'NATIVEFUNCTIONS'
include_patterns=['aten/src/ATen/native/native_functions.yaml']
command = [
'uv',
'run',
'--script',
'tools/linter/adapters/nativefunctions_linter.py',
'--native-functions-yml=aten/src/ATen/native/native_functions.yaml',
]
is_formatter = true
# [[linter]]
# code = 'GHA'
# include_patterns=['.github/workflows/**/*.yml']
# command = [
# 'uv',
# 'run',
# '--script',
# 'tools/linter/adapters/gha_linter.py',
# '--',
# '@{{PATHSFILE}}'
# ]
[[linter]]
code = 'NEWLINE'
include_patterns=['**']
exclude_patterns=[
'**/contrib/**',
'third_party/**',
'**/*.bat',
'**/*.expect',
'**/*.ipynb',
'**/*.ps1',
'**/*.ptl',
'fb/**',
'**/fb/**',
'tools/clang_format_hash/**',
'test/cpp/jit/upgrader_models/*.ptl',
'test/cpp/jit/upgrader_models/*.ptl.ff',
'test/dynamo/cpython/**',
'**/*.png',
'**/*.gz',
'**/*.patch',
'**/*.md',
]
command = [
'python3',
'tools/linter/adapters/newlines_linter.py',
'--',
'@{{PATHSFILE}}',
]
is_formatter = true
[[linter]]
code = 'SPACES'
include_patterns = ['**']
exclude_patterns = [
'**/contrib/**',
'**/*.diff',
'**/*.patch',
'third_party/**',
'aten/src/ATen/native/vulkan/api/vk_mem_alloc.h',
'fb/**',
'**/fb/**',
'test/cpp/jit/upgrader_models/*.ptl',
'test/cpp/jit/upgrader_models/*.ptl.ff',
'**/*.md',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=[[:blank:]]$',
'--linter-name=SPACES',
'--error-name=trailing spaces',
'--replace-pattern=s/[[:blank:]]+$//',
"""--error-description=\
This line has trailing spaces; please remove them.\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'TABS'
include_patterns = ['**']
exclude_patterns = [
'**/*.svg',
'**/*Makefile',
'**/contrib/**',
'third_party/**',
'**/.gitattributes',
'**/.gitmodules',
'fb/**',
'**/fb/**',
'aten/src/ATen/native/vulkan/api/vk_mem_alloc.h',
'test/cpp/jit/upgrader_models/*.ptl',
'test/cpp/jit/upgrader_models/*.ptl.ff',
'.ci/docker/common/install_rocm_drm.sh',
'.lintrunner.toml',
'**/*.patch',
'**/*.md',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
# @lint-ignore TXT2
'--pattern= ',
'--linter-name=TABS',
'--error-name=saw some tabs',
'--replace-pattern=s/\t/ /',
"""--error-description=\
This line has tabs; please replace them with spaces.\
""",
'--',
'@{{PATHSFILE}}'
]
# [[linter]]
# code = 'C10_UNUSED'
# include_patterns = [
# '**/*.cpp',
# '**/*.h',
# ]
# exclude_patterns = [
# 'torch_npu/headeronly/macros/Macros.h',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/grep_linter.py',
# '--pattern=C10_UNUSED',
# '--linter-name=C10_UNUSED',
# '--error-name=deprecated C10_UNUSED macro',
# '--replace-pattern=s/C10_UNUSED/[[maybe_unused]]/',
# """--error-description=\
# Deprecated macro, use [[maybe_unused]] directly\
# """,
# '--',
# '@{{PATHSFILE}}'
# ]
# [[linter]]
# code = 'C10_NODISCARD'
# include_patterns = [
# '**/*.cpp',
# '**/*.h',
# ]
# exclude_patterns = [
# 'torch_npu/headeronly/macros/Macros.h',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/grep_linter.py',
# '--pattern=C10_NODISCARD',
# '--linter-name=C10_NODISCARD',
# '--error-name=deprecated C10_NODISCARD macro',
# '--replace-pattern=s/C10_NODISCARD/[[nodiscard]]/',
# """--error-description=\
# Deprecated macro, use [[nodiscard]] directly\
# """,
# '--',
# '@{{PATHSFILE}}'
# ]
# [[linter]]
# code = 'RAWTHROW'
# include_patterns = [
# '**/*.cpp',
# '**/*.h',
# ]
# exclude_patterns = [
# # Vendored code (do not modify)
# 'c10/util/flat_hash_map.h',
# 'c10/util/order_preserving_flat_hash_map.h',
# 'aten/src/ATen/native/quantized/cpu/qnnpack/**',
# 'aten/src/ATen/native/transformers/cuda/mem_eff_attention/**',
# # Standalone code that cannot depend on c10
# 'torch_npu/csrc/inductor/aoti_runtime/**',
# # Test files use EXPECT_THROW which is a gtest macro
# 'test/cpp/**/*.cpp',
# # Python C API bindings use python_error/py::error_already_set for exception propagation
# 'torch_npu/csrc/npu/Module.cpp',
# # NPUGraph logs files
# 'torch_npu/csrc/core/npu/NPUGraph.cpp',
# 'torch_npu/csrc/core/npu/NPUGraph.h',
# 'torch_npu/csrc/npu/Graph.cpp',
# 'torch_npu/csrc/core/npu/NPUCachingAllocator.cpp',
# 'torch_npu/csrc/core/npu/NPUWorkspaceAllocator.cpp',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/rawthrow_linter.py',
# '--linter-name=RAWTHROW',
# '--error-name=raw throw statement',
# """--error-description=\
# Do not use raw `throw` in C++ code. Use TORCH_CHECK, \
# TORCH_CHECK_WITH, C10_THROW_ERROR, or other error-reporting macros \
# instead. See c10/util/Exception.h for available macros. If this is a \
# re-throw (throw;), restructure the code to avoid try/catch/throw or \
# add the file to the RAWTHROW exclude list in .lintrunner.toml with \
# justification.\
# """,
# '--',
# '@{{PATHSFILE}}'
# ]
# [[linter]]
# code = 'INCLUDE'
# include_patterns = [
# 'c10/**',
# 'aten/**',
# 'torch_npu/csrc/**',
# 'torch_npu/nativert/**',
# ]
# exclude_patterns = [
# 'aten/src/ATen/native/quantized/cpu/qnnpack/**',
# 'aten/src/ATen/native/vulkan/api/vk_mem_alloc.h',
# 'aten/src/ATen/native/vulkan/glsl/**',
# '**/fb/**',
# 'torch_npu/csrc/jit/serialization/mobile_bytecode_generated.h',
# 'torch_npu/csrc/utils/pythoncapi_compat.h',
# 'torch_npu/csrc/core/npu/NPUCachingAllocator.cpp',
# 'torch_npu/csrc/core/npu/NPUWorkspaceAllocator.cpp',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/grep_linter.py',
# '--pattern=#include "',
# '--linter-name=INCLUDE',
# '--error-name=quoted include',
# '--replace-pattern=s/#include "(.*)"$/#include <\1>/',
# """--error-description=\
# This #include uses quotes; please convert it to #include <xxxx>\
# """,
# '--',
# '@{{PATHSFILE}}'
# ]
# [[linter]]
# code = 'PYBIND11_INCLUDE'
# include_patterns = [
# '**/*.cpp',
# '**/*.h',
# ]
# exclude_patterns = [
# 'torch_npu/csrc/utils/pybind.h',
# 'torch_npu/utils/benchmark/utils/valgrind_wrapper/compat_bindings.cpp',
# 'caffe2/**/*',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/grep_linter.py',
# '--pattern=#include <pybind11\/(^|[^(gil_simple\.h)])',
# '--allowlist-pattern=#include <torch\/csrc\/utils\/pybind.h>',
# '--linter-name=PYBIND11_INCLUDE',
# '--match-first-only',
# '--error-name=direct include of pybind11',
# # https://stackoverflow.com/a/33416489/23845
# # NB: this won't work if the pybind11 include is on the first line;
# # but that's fine because it will just mean the lint will still fail
# # after applying the change and you will have to fix it manually
# '--replace-pattern=1,/(#include <pybind11\/)/ s/(#include <pybind11\/)/#include <torch\/csrc\/utils\/pybind.h>\n\1/',
# """--error-description=\
# This #include directly includes pybind11 without also including \
# #include <torch_npu/csrc/utils/pybind.h>; this means some important \
# specializations may not be included.\
# """,
# '--',
# '@{{PATHSFILE}}'
# ]
[[linter]]
code = 'ERROR_PRONE_ISINSTANCE'
include_patterns = [
'torch_npu/_refs/**/*.py',
'torch_npu/_prims/**/*.py',
'torch_npu/_prims_common/**/*.py',
'torch_npu/_decomp/**/*.py',
'torch_npu/_meta_registrations.py',
]
exclude_patterns = [
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=isinstance\([^)]+(int|float)\)',
'--linter-name=ERROR_PRONE_ISINSTANCE',
'--error-name=error prone isinstance',
"""--error-description=\
This line has an isinstance call that directly refers to \
int or float. This is error-prone because you may also \
have wanted to allow SymInt or SymFloat in your test. \
To suppress this lint, use an appropriate type alias defined \
in torch._prims_common; use IntLike/FloatLike when you would accept \
both regular and symbolic numbers, Dim for ints representing \
dimensions, or IntWithoutSymInt/FloatWithoutSymFloat if you really \
meant to exclude symbolic numbers.
""",
'--',
'@{{PATHSFILE}}'
]
# [[linter]]
# code = 'PYBIND11_SPECIALIZATION'
# include_patterns = [
# '**/*.cpp',
# '**/*.h',
# ]
# exclude_patterns = [
# # The place for all orphan specializations
# 'torch_npu/csrc/utils/pybind.h',
# # These specializations are non-orphan
# 'torch_npu/csrc/distributed/c10d/init.cpp',
# 'torch_npu/csrc/jit/python/pybind.h',
# 'fb/**',
# '**/fb/**',
# # These are safe to exclude as they do not have Python
# 'c10/**/*',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/grep_linter.py',
# '--pattern=PYBIND11_DECLARE_HOLDER_TYPE',
# '--linter-name=PYBIND11_SPECIALIZATION',
# '--error-name=pybind11 specialization in non-standard location',
# """--error-description=\
# This pybind11 specialization (PYBIND11_DECLARE_HOLDER_TYPE) should \
# be placed in torch_npu/csrc/utils/pybind.h so that it is guaranteed to be \
# included at any site that may potentially make use of it via py::cast. \
# If your specialization is in the same header file as the definition \
# of the holder type, you can ignore this lint by adding your header to \
# the exclude_patterns for this lint in .lintrunner.toml. For more \
# information see https://github.com/pybind/pybind11/issues/4099 \
# """,
# '--',
# '@{{PATHSFILE}}'
# ]
[[linter]]
code = 'PYPIDEP'
include_patterns = ['.github/**']
exclude_patterns = [
'**/*.rst',
'**/*.py',
'**/*.md',
'**/*.diff',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
"""--pattern=\
(pip|pip3|python -m pip|python3 -m pip|python3 -mpip|python -mpip) \
install ([a-zA-Z0-9][A-Za-z0-9\\._\\-]+)([^/=<>~!]+)[A-Za-z0-9\\._\\-\\*\\+\\!]*$\
""",
'--linter-name=PYPIDEP',
'--error-name=unpinned PyPI install',
"""--error-description=\
This line has unpinned PyPi installs; \
please pin them to a specific version: e.g. 'thepackage==1.2'\
""",
'--',
'@{{PATHSFILE}}'
]
# [[linter]]
# code = 'EXEC'
# include_patterns = ['**']
# exclude_patterns = [
# 'third_party/**',
# 'torch_npu/bin/**',
# '**/*.so',
# '**/*.py',
# '**/*.sh',
# '**/*.bash',
# '**/git-pre-commit',
# '**/git-clang-format',
# '**/gradlew',
# 'fb/**',
# '**/fb/**',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/exec_linter.py',
# '--',
# '@{{PATHSFILE}}',
# ]
[[linter]]
code = 'CUBINCLUDE'
include_patterns = ['aten/**']
exclude_patterns = [
'aten/src/ATen/cuda/cub*.cuh',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=#include <cub/',
'--linter-name=CUBINCLUDE',
'--error-name=direct cub include',
"""--error-description=\
This line has a direct cub include; please include \
ATen/cuda/cub.cuh instead and wrap your cub calls in \
at::native namespace if necessary.
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'RAWCUDA'
include_patterns = [
'aten/**',
'c10/**',
]
exclude_patterns = [
'aten/src/ATen/test/**',
'c10/cuda/CUDAFunctions.h',
'c10/cuda/CUDACachingAllocator.cpp',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=cudaStreamSynchronize',
'--linter-name=RAWCUDA',
'--error-name=raw CUDA API usage',
"""--error-description=\
This line calls raw CUDA APIs directly; please use at::cuda wrappers instead.
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'RAWCUDADEVICE'
include_patterns = [
'aten/**',
'c10/**',
'torch_npu/csrc/**',
'torch_npu/nativert/**',
]
exclude_patterns = [
'aten/src/ATen/cuda/CUDAContext.cpp',
'aten/src/ATen/cuda/CUDAGeneratorImpl.cpp',
'aten/src/ATen/test/**',
'c10/core/impl/InlineDeviceGuard.h',
'c10/cuda/CUDAFunctions.cpp',
'c10/cuda/CUDAGuard.h',
'c10/cuda/impl/CUDATest.cpp',
'torch_npu/csrc/cuda/nccl.cpp',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=(cudaSetDevice|cudaGetDevice)\\(',
'--linter-name=RAWCUDADEVICE',
'--error-name=raw CUDA API usage',
"""--error-description=\
This line calls raw CUDA APIs directly; please use c10::cuda wrappers instead.
""",
'--',
'@{{PATHSFILE}}'
]
# [[linter]]
# code = 'ROOT_LOGGING'
# include_patterns = [
# '**/*.py',
# ]
# # These are not library code, but scripts in their own right, and so
# # therefore are permitted to use logging
# exclude_patterns = [
# 'tools/**',
# 'test/**',
# 'benchmarks/**',
# 'torch_npu/distributed/run.py',
# 'functorch/benchmarks/**',
# # Grandfathered in
# 'caffe2/**',
# 'fb/**',
# '**/fb/**',
# # NPUGraph logs files
# 'torch_npu/_logging/_internal.py',
# 'torch_npu/npu/_graph_tree.py',
# 'torch_npu/npu/graphs.py',
# 'torch_npu/utils/_graph_tree.py',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/grep_linter.py',
# '--pattern=logging\.(debug|info|warn|warning|error|critical|log|exception)\(',
# '--replace-pattern=s/logging\.(debug|info|warn|warning|error|critical|log|exception)\(/log.\1(/',
# '--linter-name=ROOT_LOGGING',
# '--error-name=use of root logger',
# """--error-description=\
# Do not use root logger (logging.info, etc) directly; instead \
# define 'log = logging.getLogger(__name__)' and call, e.g., log.info().
# """,
# '--',
# '@{{PATHSFILE}}'
# ]
[[linter]]
code = 'DEPLOY_DETECTION'
include_patterns = [
'**/*.py',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=sys\.executable == .torch_deploy.',
'--replace-pattern=s/sys\.executable == .torch_deploy./torch._running_with_deploy\(\)/',
'--linter-name=DEPLOY_DETECTION',
'--error-name=properly detect deploy runner',
"""--error-description=\
Do not use sys.executable to detect if running within deploy/multipy, use torch._running_with_deploy().
""",
'--',
'@{{PATHSFILE}}'
]
# [[linter]]
# code = 'CMAKE'
# include_patterns = [
# "**/*.cmake",
# "**/*.cmake.in",
# "**/CMakeLists.txt",
# ]
# exclude_patterns = [
# 'cmake/Modules/**',
# 'cmake/Modules_CUDA_fix/**',
# 'cmake/Caffe2Config.cmake.in',
# 'aten/src/ATen/ATenConfig.cmake.in',
# 'cmake/TorchConfig.cmake.in',
# 'cmake/TorchConfigVersion.cmake.in',
# 'cmake/cmake_uninstall.cmake.i',
# 'fb/**',
# '**/fb/**',
# ]
# command = [
# 'uv',
# 'run',
# '--script',
# 'tools/linter/adapters/cmake_linter.py',
# '--config=.cmakelintrc',
# '--',
# '@{{PATHSFILE}}',
# ]
[[linter]]
code = 'SHELLCHECK'
include_patterns = [
'.ci/pytorch_npu/**/*.sh'
]
exclude_patterns = [
'**/fb/**',
]
command = [
'uv',
'run',
'--script',
'tools/linter/adapters/shellcheck_linter.py',
'--',
'@{{PATHSFILE}}',
]
# [[linter]]
# code = 'ACTIONLINT'
# include_patterns = [
# '.github/workflows/*.yml',
# '.github/workflows/*.yaml',
# # actionlint does not support composite actions yet
# # '.github/actions/**/*.yml',
# # '.github/actions/**/*.yaml',
# ]
# exclude_patterns = [
# '**/fb/**',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/actionlint_linter.py',
# '--binary=.lintbin/actionlint',
# '--',
# '@{{PATHSFILE}}',
# ]
# init_command = [
# 'python3',
# 'tools/linter/adapters/s3_init.py',
# '--config-json=tools/linter/adapters/s3_init_config.json',
# '--linter=actionlint',
# '--dry-run={{DRYRUN}}',
# '--output-dir=.lintbin',
# '--output-name=actionlint',
# ]
# # [[linter]]
# # code = 'TESTOWNERS'
# # include_patterns = [
# # 'test/**/test_*.py',
# # 'test/**/*_test.py',
# # ]
# # exclude_patterns = [
# # 'test/run_test.py',
# # '**/fb/**',
# # ]
# # command = [
# # 'python3',
# # 'tools/linter/adapters/testowners_linter.py',
# # '--',
# # '@{{PATHSFILE}}',
# # ]
# [[linter]]
# code = 'TEST_HAS_MAIN'
# include_patterns = [
# 'test/**/test_*.py',
# ]
# exclude_patterns = [
# 'test/run_test.py',
# '**/fb/**',
# 'test/dynamo/cpython/3.13/**',
# 'test/quantization/**', # should be run through test/test_quantization.py
# 'test/jit/**', # should be run through test/test_jit.py
# 'test/ao/sparsity/**', # should be run through test/test_ao_sparsity.py
# 'test/fx/**', # should be run through test/test_fx.py
# 'test/package/**', # excluded by test/run_test.py
# 'test/distributed/argparse_util_test.py',
# 'test/distributed/bin/test_script.py',
# 'test/distributed/elastic/agent/server/test/local_elastic_agent_test.py',
# 'test/distributed/elastic/multiprocessing/bin/test_script.py',
# 'test/distributed/elastic/multiprocessing/bin/zombie_test.py',
# 'test/distributed/elastic/multiprocessing/errors/api_test.py',
# 'test/distributed/elastic/multiprocessing/errors/error_handler_test.py',
# 'test/distributed/elastic/multiprocessing/redirects_test.py',
# 'test/distributed/elastic/multiprocessing/tail_log_test.py',
# 'test/distributed/elastic/rendezvous/api_test.py',
# 'test/distributed/elastic/rendezvous/c10d_rendezvous_backend_test.py',
# 'test/distributed/elastic/rendezvous/dynamic_rendezvous_test.py',
# 'test/distributed/elastic/rendezvous/etcd_rendezvous_backend_test.py',
# 'test/distributed/elastic/rendezvous/etcd_rendezvous_test.py',
# 'test/distributed/elastic/rendezvous/etcd_server_test.py',
# 'test/distributed/elastic/rendezvous/rendezvous_backend_test.py',
# 'test/distributed/elastic/rendezvous/static_rendezvous_test.py',
# 'test/distributed/elastic/rendezvous/utils_test.py',
# 'test/distributed/elastic/timer/api_test.py',
# 'test/distributed/elastic/utils/data/cycling_iterator_test.py',
# 'test/distributed/launcher/api_test.py',
# 'test/distributed/launcher/bin/test_script.py',
# 'test/distributed/launcher/bin/test_script_init_method.py',
# 'test/distributed/launcher/bin/test_script_is_torchelastic_launched.py',
# 'test/distributed/launcher/bin/test_script_local_rank.py',
# 'test/distributed/launcher/launch_test.py',
# 'test/distributed/launcher/run_test.py',
# 'test/distributed/optim/test_apply_optimizer_in_backward.py',
# 'test/distributed/optim/test_named_optimizer.py',
# 'test/distributed/test_c10d_spawn.py',
# 'test/distributed/test_collective_utils.py',
# 'test/distributions/test_distributions.py',
# 'test/inductor/test_aot_inductor_utils.py',
# 'test/lazy/test_bindings.py',
# 'test/lazy/test_extract_compiled_graph.py',
# 'test/lazy/test_meta_kernel.py',
# 'test/nn/test_init.py',
# 'test/onnx/model_defs/op_test.py',
# 'test/onnx/test_models_quantized_onnxruntime.py',
# 'test/onnx/test_onnxscript_no_runtime.py',
# 'test/onnx_caffe2/test_caffe2_common.py',
# 'test/optim/test_lrscheduler.py',
# 'test/optim/test_optim.py',
# 'test/optim/test_swa_utils.py',
# 'test/run_test.py',
# 'test/test_bundled_images.py',
# 'test/test_cuda_expandable_segments.py',
# 'test/test_hub.py',
# ]
# command = [
# 'uv',
# 'run',
# '--script',
# 'tools/linter/adapters/test_has_main_linter.py',
# '--',
# '@{{PATHSFILE}}',
# ]
# [[linter]]
# code = 'CALL_ONCE'
# include_patterns = [
# 'c10/**',
# 'aten/**',
# 'torch_npu/csrc/**',
# 'torch_npu/nativert/**',
# ]
# exclude_patterns = [
# 'c10/util/CallOnce.h',
# '**/fb/**',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/grep_linter.py',
# '--pattern=std::call_once',
# '--linter-name=CALL_ONCE',
# '--error-name=invalid call_once',
# '--replace-pattern=s/std::call_once/c10::call_once/',
# """--error-description=\
# Use of std::call_once is forbidden and should be replaced with c10::call_once\
# """,
# '--',
# '@{{PATHSFILE}}'
# ]
# [[linter]]
# code = 'CONTEXT_DECORATOR'
# include_patterns = [
# 'torch_npu/**',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/grep_linter.py',
# '--pattern=@.*(dynamo_timed|preserve_rng_state|clear_frame|with_fresh_cache_if_config|use_lazy_graph_module|_disable_current_modes)',
# '--allowlist-pattern=clear_frames',
# '--linter-name=CONTEXT_DECORATOR',
# '--error-name=avoid context decorator',
# """--error-description=\
# Do not use context manager as decorator as it breaks cProfile traces. Use it as \
# a context manager instead\
# """,
# '--',
# '@{{PATHSFILE}}'
# ]
# [[linter]]
# code = 'ONCE_FLAG'
# include_patterns = [
# 'c10/**',
# 'aten/**',
# 'torch_npu/csrc/**',
# 'torch_npu/nativert/**',
# ]
# exclude_patterns = [
# '**/fb/**',
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/grep_linter.py',
# '--pattern=std::once_flag',
# '--linter-name=ONCE_FLAG',
# '--error-name=invalid once_flag',
# '--replace-pattern=s/std::once_flag/c10::once_flag/',
# """--error-description=\
# Use of std::once_flag is forbidden and should be replaced with c10::once_flag\
# """,
# '--',
# '@{{PATHSFILE}}'
# ]
# [[linter]]
# code = 'WORKFLOWSYNC'
# include_patterns = [
# '.github/workflows/*.yml',
# '.github/workflows/*.yaml',
# ]
# command = [
# 'uv',
# 'run',
# '--script',
# 'tools/linter/adapters/workflow_consistency_linter.py',
# '--',
# '@{{PATHSFILE}}'
# ]
# [[linter]]
# code = 'NO_WORKFLOWS_ON_FORK'
# include_patterns = [
# '.github/**/*.yml',
# '.github/**/*.yaml',
# ]
# exclude_patterns = [
# '**/fb/**',
# ]
# command = [
# 'uv',
# 'run',
# '--script',
# 'tools/linter/adapters/no_workflows_on_fork.py',
# '--',
# '@{{PATHSFILE}}',
# ]
[[linter]]
code = 'CODESPELL'
command = [
'uv',
'run',
'--script',
'tools/linter/adapters/codespell_linter.py',
'--',
'@{{PATHSFILE}}'
]
include_patterns = [
'**',
]
exclude_patterns = [
# We don't care too much about files in this directory, don't enforce
# spelling on them
'caffe2/**',
'fb/**',
'**/fb/**',
'third_party/**',
'test/dynamo/cpython/**',
'torch_npu/_vendor/**',
'torch_npu/_inductor/fx_passes/serialized_patterns/**',
'torch_npu/_inductor/autoheuristic/artifacts/**',
'torch_npu/_inductor/kernel/vendored_templates/cutedsl/kernels/**',
'torch_npu/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py',
'torch_npu/utils/model_dump/preact.mjs',
'torch_npu/_inductor/docs/**/*.svg',
]
is_formatter = true
# # usort + ruff-format
# [[linter]]
# code = 'PYFMT'
# include_patterns = [
# '**/*.py',
# '**/*.pyi',
# ]
# command = [
# 'uv',
# 'run',
# '--script',
# 'tools/linter/adapters/pyfmt_linter.py',
# '--',
# '@{{PATHSFILE}}'
# ]
# exclude_patterns = [
# 'tools/gen_vulkan_spv.py',
# # We don't care too much about files in this directory, don't enforce
# # formatting on them
# 'caffe2/**/*.py',
# 'caffe2/**/*.pyi',
# 'fb/**',
# '**/fb/**',
# 'test/dynamo/cpython/**',
# 'third_party/**/*.py',
# 'third_party/**/*.pyi',
# 'torch_npu/_vendor/**',
# 'torch_npu/_inductor/fx_passes/serialized_patterns/**',
# 'torch_npu/_inductor/autoheuristic/artifacts/**',
# # Needs Python 3.12+
# 'torch_npu/testing/_internal/py312_intrinsics.py',
# # These files are all grandfathered in, feel free to remove from this list
# # as necessary
# 'test/quantization/__init__.py',
# 'test/quantization/core/__init__.py',
# 'test/quantization/core/experimental/apot_fx_graph_mode_ptq.py',
# 'test/quantization/core/experimental/apot_fx_graph_mode_qat.py',
# 'test/quantization/core/experimental/quantization_util.py',
# 'test/quantization/core/experimental/test_bits.py',
# 'test/quantization/core/experimental/test_fake_quantize.py',
# 'test/quantization/core/experimental/test_linear.py',
# 'test/quantization/core/experimental/test_nonuniform_observer.py',
# 'test/quantization/core/experimental/test_quantized_tensor.py',
# 'test/quantization/core/experimental/test_quantizer.py',
# 'test/quantization/core/test_backend_config.py',
# 'test/quantization/core/test_docs.py',
# 'test/quantization/core/test_quantized_functional.py',
# 'test/quantization/core/test_quantized_module.py',
# 'test/quantization/core/test_quantized_op.py',
# 'test/quantization/core/test_quantized_tensor.py',
# 'test/quantization/core/test_top_level_apis.py',
# 'test/quantization/core/test_utils.py',
# 'test/quantization/core/test_workflow_module.py',
# 'test/quantization/core/test_workflow_ops.py',
# 'test/quantization/fx/__init__.py',
# 'test/quantization/fx/test_equalize_fx.py',
# 'test/quantization/fx/test_model_report_fx.py',
# 'test/quantization/fx/test_numeric_suite_fx.py',
# 'test/quantization/fx/test_quantize_fx.py',
# 'test/quantization/fx/test_subgraph_rewriter.py',
# 'test/test_function_schema.py',
# 'test/test_functional_autograd_benchmark.py',
# 'test/test_functional_optim.py',
# 'test/test_functionalization_of_rng_ops.py',
# 'test/test_datapipe.py',
# 'test/test_futures.py',
# 'test/test_fx.py',
# 'test/test_fx_experimental.py',
# 'test/test_fx_passes.py',
# 'test/test_fx_reinplace_pass.py',
# 'test/test_import_stats.py',
# 'test/test_itt.py',
# 'test/test_jit.py',
# 'test/test_jit_autocast.py',
# 'test/test_jit_cuda_fuser.py',
# 'test/test_jit_disabled.py',
# 'test/test_jit_fuser.py',
# 'test/test_jit_fuser_legacy.py',
# 'test/test_jit_legacy.py',
# 'test/test_jit_llga_fuser.py',
# 'test/test_jit_profiling.py',
# 'test/test_jit_simple.py',
# 'test/test_jit_string.py',
# 'test/test_jiterator.py',
# 'test/test_kernel_launch_checks.py',
# 'test/test_linalg.py',
# 'test/test_masked.py',
# 'test/test_maskedtensor.py',
# 'test/test_matmul_cuda.py',
# 'test/test_scaled_matmul_cuda.py',
# 'test/test_meta.py',
# 'test/test_metal.py',
# 'test/test_mkl_verbose.py',
# 'test/test_mkldnn.py',
# 'test/test_mkldnn_fusion.py',
# 'test/test_mkldnn_verbose.py',
# 'test/test_mobile_optimizer.py',
# 'test/test_model_dump.py',
# 'test/test_modules.py',
# 'test/test_monitor.py',
# 'test/test_mps.py',
# 'test/test_multiprocessing_spawn.py',
# 'test/test_namedtensor.py',
# 'test/test_namedtuple_return_api.py',
# 'test/test_native_functions.py',
# 'test/test_native_mha.py',
# 'test/test_nn.py',
# 'test/test_out_dtype_op.py',
# 'test/test_overrides.py',
# 'test/test_prims.py',
# 'test/test_proxy_tensor.py',
# 'test/test_pruning_op.py',
# 'test/test_quantization.py',
# 'test/test_reductions.py',
# 'test/test_scatter_gather_ops.py',
# 'test/test_schema_check.py',
# 'test/test_segment_reductions.py',
# 'test/test_serialization.py',
# 'test/test_set_default_mobile_cpu_allocator.py',
# 'test/test_sparse.py',
# 'test/test_sparse_csr.py',
# 'test/test_sparse_semi_structured.py',
# 'test/test_spectral_ops.py',
# 'test/test_stateless.py',
# 'test/test_static_runtime.py',
# 'test/test_subclass.py',
# 'test/test_sympy_utils.py',
# 'test/test_tensor_creation_ops.py',
# 'test/test_tensorboard.py',
# 'test/test_tensorexpr.py',
# 'test/test_tensorexpr_pybind.py',
# 'test/test_testing.py',
# 'test/test_torch.py',
# 'test/test_transformers.py',
# 'test/test_type_promotion.py',
# 'test/test_unary_ufuncs.py',
# 'test/test_vulkan.py',
# 'test/npu/test_fault_mode.py',
# 'torch_npu/utils/_dynamo.py',
# 'test/npu/test_resnet.py',
# 'test/npu/test_public_bindings.py',
# 'test/npu/test_compatibility.py',
# 'torch_npu/_awaits/__init__.py',
# 'torch_npu/_export/__init__.py',
# 'torch_npu/_export/constraints.py',
# 'torch_npu/_export/db/__init__.py',
# 'torch_npu/_export/db/case.py',
# 'torch_npu/_export/db/examples/__init__.py',
# 'torch_npu/_export/db/examples/assume_constant_result.py',
# 'torch_npu/_export/db/examples/autograd_function.py',
# 'torch_npu/_export/db/examples/class_method.py',
# 'torch_npu/_export/db/examples/cond_branch_class_method.py',
# 'torch_npu/_export/db/examples/cond_branch_nested_function.py',
# 'torch_npu/_export/db/examples/cond_branch_nonlocal_variables.py',
# 'torch_npu/_export/db/examples/cond_closed_over_variable.py',
# 'torch_npu/_export/db/examples/cond_operands.py',
# 'torch_npu/_export/db/examples/cond_predicate.py',
# 'torch_npu/_export/db/examples/decorator.py',
# 'torch_npu/_export/db/examples/dictionary.py',
# 'torch_npu/_export/db/examples/dynamic_shape_assert.py',
# 'torch_npu/_export/db/examples/dynamic_shape_constructor.py',
# 'torch_npu/_export/db/examples/dynamic_shape_if_guard.py',
# 'torch_npu/_export/db/examples/dynamic_shape_map.py',
# 'torch_npu/_export/db/examples/dynamic_shape_round.py',
# 'torch_npu/_export/db/examples/dynamic_shape_slicing.py',
# 'torch_npu/_export/db/examples/dynamic_shape_view.py',
# 'torch_npu/_export/db/examples/fn_with_kwargs.py',
# 'torch_npu/_export/db/examples/list_contains.py',
# 'torch_npu/_export/db/examples/list_unpack.py',
# 'torch_npu/_export/db/examples/nested_function.py',
# 'torch_npu/_export/db/examples/null_context_manager.py',
# 'torch_npu/_export/db/examples/pytree_flatten.py',
# 'torch_npu/_export/db/examples/scalar_output.py',
# 'torch_npu/_export/db/examples/specialized_attribute.py',
# 'torch_npu/_export/db/examples/static_for_loop.py',
# 'torch_npu/_export/db/examples/static_if.py',
# 'torch_npu/_export/db/examples/tensor_setattr.py',
# 'torch_npu/_export/db/examples/type_reflection_method.py',
# 'torch_npu/_export/db/gen_example.py',
# 'torch_npu/_export/db/logging.py',
# 'torch_npu/testing/_internal/__init__.py',
# 'torch_npu/testing/_internal/autocast_test_lists.py',
# 'torch_npu/testing/_internal/autograd_function_db.py',
# 'torch_npu/testing/_internal/check_kernel_launches.py',
# 'torch_npu/testing/_internal/codegen/__init__.py',
# 'torch_npu/testing/_internal/codegen/random_topo_test.py',
# 'torch_npu/testing/_internal/common_cuda.py',
# 'torch_npu/testing/_internal/common_jit.py',
# 'torch_npu/testing/_internal/common_methods_invocations.py',
# 'torch_npu/testing/_internal/common_modules.py',
# 'torch_npu/testing/_internal/common_nn.py',
# 'torch_npu/testing/_internal/common_pruning.py',
# 'torch_npu/testing/_internal/common_quantization.py',
# 'torch_npu/testing/_internal/common_quantized.py',
# 'torch_npu/testing/_internal/common_subclass.py',
# 'torch_npu/testing/_internal/common_utils.py',
# 'torch_npu/testing/_internal/composite_compliance.py',
# 'torch_npu/testing/_internal/hop_db.py',
# 'torch_npu/testing/_internal/custom_op_db.py',
# 'torch_npu/testing/_internal/data/__init__.py',
# 'torch_npu/testing/_internal/data/network1.py',
# 'torch_npu/testing/_internal/data/network2.py',
# 'torch_npu/testing/_internal/dist_utils.py',
# 'torch_npu/testing/_internal/generated/__init__.py',
# 'torch_npu/testing/_internal/hypothesis_utils.py',
# 'torch_npu/testing/_internal/inductor_utils.py',
# 'torch_npu/testing/_internal/jit_metaprogramming_utils.py',
# 'torch_npu/testing/_internal/jit_utils.py',
# 'torch_npu/testing/_internal/logging_tensor.py',
# 'torch_npu/testing/_internal/logging_utils.py',
# 'torch_npu/testing/_internal/optests/__init__.py',
# 'torch_npu/testing/_internal/optests/aot_autograd.py',
# 'torch_npu/testing/_internal/optests/compile_check.py',
# 'torch_npu/testing/_internal/optests/fake_tensor.py',
# 'torch_npu/testing/_internal/optests/make_fx.py',
# 'torch_npu/testing/_internal/quantization_torch_package_models.py',
# 'torch_npu/testing/_internal/test_module/__init__.py',
# 'torch_npu/testing/_internal/test_module/future_div.py',
# 'torch_npu/testing/_internal/test_module/no_future_div.py',
# 'torch_npu/utils/benchmark/__init__.py',
# 'torch_npu/utils/benchmark/examples/__init__.py',
# 'torch_npu/utils/benchmark/examples/compare.py',
# 'torch_npu/utils/benchmark/examples/fuzzer.py',
# 'torch_npu/utils/benchmark/examples/op_benchmark.py',
# 'torch_npu/utils/benchmark/examples/simple_timeit.py',
# 'torch_npu/utils/benchmark/examples/sparse/compare.py',
# 'torch_npu/utils/benchmark/examples/sparse/fuzzer.py',
# 'torch_npu/utils/benchmark/examples/sparse/op_benchmark.py',
# 'torch_npu/utils/benchmark/examples/spectral_ops_fuzz_test.py',
# 'torch_npu/utils/benchmark/op_fuzzers/__init__.py',
# 'torch_npu/utils/benchmark/op_fuzzers/binary.py',
# 'torch_npu/utils/benchmark/op_fuzzers/sparse_binary.py',
# 'torch_npu/utils/benchmark/op_fuzzers/sparse_unary.py',
# 'torch_npu/utils/benchmark/op_fuzzers/spectral.py',
# 'torch_npu/utils/benchmark/op_fuzzers/unary.py',
# 'torch_npu/utils/benchmark/utils/__init__.py',
# 'torch_npu/utils/benchmark/utils/_stubs.py',
# 'torch_npu/utils/benchmark/utils/common.py',
# 'torch_npu/utils/benchmark/utils/compare.py',
# 'torch_npu/utils/benchmark/utils/compile.py',
# 'torch_npu/utils/benchmark/utils/cpp_jit.py',
# 'torch_npu/utils/benchmark/utils/fuzzer.py',
# 'torch_npu/utils/benchmark/utils/sparse_fuzzer.py',
# 'torch_npu/utils/benchmark/utils/timer.py',
# 'torch_npu/utils/benchmark/utils/valgrind_wrapper/__init__.py',
# 'torch_npu/utils/benchmark/utils/valgrind_wrapper/timer_interface.py',
# 'torch_npu/utils/bundled_inputs.py',
# 'torch_npu/utils/checkpoint.py',
# 'torch_npu/utils/collect_env.py',
# 'torch_npu/utils/cpp_backtrace.py',
# 'torch_npu/utils/cpp_extension.py',
# 'torch_npu/utils/dlpack.py',
# 'torch_npu/utils/file_baton.py',
# 'torch_npu/utils/flop_counter.py',
# 'torch_npu/utils/hipify/__init__.py',
# 'torch_npu/utils/hipify/constants.py',
# 'torch_npu/utils/hipify/cuda_to_hip_mappings.py',
# 'torch_npu/utils/hipify/hipify_python.py',
# 'torch_npu/utils/hipify/version.py',
# 'torch_npu/utils/hooks.py',
# 'torch_npu/utils/jit/__init__.py',
# 'torch_npu/utils/jit/log_extract.py',
# 'torch_npu/utils/mkldnn.py',
# 'torch_npu/utils/mobile_optimizer.py',
# 'torch_npu/utils/model_dump/__init__.py',
# 'torch_npu/utils/model_dump/__main__.py',
# 'torch_npu/utils/model_zoo.py',
# 'torch_npu/utils/show_pickle.py',
# 'torch_npu/utils/tensorboard/__init__.py',
# 'torch_npu/utils/tensorboard/_caffe2_graph.py',
# 'torch_npu/utils/tensorboard/_convert_np.py',
# 'torch_npu/utils/tensorboard/_embedding.py',
# 'torch_npu/utils/tensorboard/_onnx_graph.py',
# 'torch_npu/utils/tensorboard/_proto_graph.py',
# 'torch_npu/utils/tensorboard/_pytorch_graph.py',
# 'torch_npu/utils/tensorboard/_utils.py',
# 'torch_npu/utils/tensorboard/summary.py',
# 'torch_npu/utils/tensorboard/writer.py',
# 'torch_npu/utils/throughput_benchmark.py',
# 'torch_npu/utils/viz/__init__.py',
# 'torch_npu/utils/viz/_cycles.py',
# # NPUGraph logs files
# 'torch_npu/_logging/_internal.py',
# 'torch_npu/npu/_graph_tree.py',
# 'torch_npu/npu/graphs.py',
# 'torch_npu/utils/_graph_tree.py',
# ]
# is_formatter = true
# [[linter]]
# code = 'PYPROJECT'
# command = [
# 'uv',
# 'run',
# '--script',
# 'tools/linter/adapters/pyproject_linter.py',
# '--',
# '@{{PATHSFILE}}'
# ]
# include_patterns = [
# "**/pyproject.toml",
# ]
# [[linter]]
# code = 'CMAKE_MINIMUM_REQUIRED'
# command = [
# 'uv',
# 'run',
# '--script',
# 'tools/linter/adapters/cmake_minimum_required_linter.py',
# '--',
# '@{{PATHSFILE}}'
# ]
# include_patterns = [
# "**/pyproject.toml",
# "**/CMakeLists.txt",
# "**/CMakeLists.txt.in",
# "**/*.cmake",
# "**/*.cmake.in",
# "**/*requirements*.txt",
# "**/*requirements*.in",
# ]
[[linter]]
code = 'COPYRIGHT'
include_patterns = ['**']
exclude_patterns = [
'.lintrunner.toml',
'fb/**',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=Confidential and proprietary',
'--linter-name=COPYRIGHT',
'--error-name=Confidential Code',
"""--error-description=\
Proprietary and confidential source code\
should not be contributed to PyTorch codebase\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'BAZEL_LINTER'
include_patterns = ['WORKSPACE']
command = [
'python3',
'tools/linter/adapters/bazel_linter.py',
'--binary=.lintbin/bazel',
'--',
'@{{PATHSFILE}}'
]
init_command = [
'python3',
'tools/linter/adapters/s3_init.py',
'--config-json=tools/linter/adapters/s3_init_config.json',
'--linter=bazel',
'--dry-run={{DRYRUN}}',
'--output-dir=.lintbin',
'--output-name=bazel',
]
is_formatter = true
[[linter]]
code = 'LINTRUNNER_VERSION'
include_patterns = ['**']
exclude_patterns = [
'fb/**',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/lintrunner_version_linter.py'
]
# [[linter]]
# code = 'RUFF'
# include_patterns = [
# '**/*.py',
# '**/*.pyi',
# '**/*.ipynb',
# 'pyproject.toml',
# ]
# exclude_patterns = [
# 'caffe2/**',
# 'functorch/docs/**',
# 'torch_npu/_inductor/fx_passes/serialized_patterns/**',
# 'torch_npu/_inductor/autoheuristic/artifacts/**',
# 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/kernels/**',
# 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py',
# 'test/dynamo/cpython/**',
# 'test/test_torchfuzz_repros.py',
# 'test/npu/test_fault_mode.py',
# 'torch_npu/utils/_dynamo.py',
# 'test/npu/test_resnet.py',
# 'test/npu/test_public_bindings.py',
# 'test/npu/test_compatibility.py',
# 'scripts/**',
# 'third_party/**',
# 'fb/**',
# '**/fb/**',
# # NPUGraph logs files
# 'torch_npu/_logging/_internal.py',
# 'torch_npu/npu/_graph_tree.py',
# 'torch_npu/npu/graphs.py',
# 'torch_npu/utils/_graph_tree.py',
# ]
# command = [
# 'uv',
# 'run',
# '--script',
# 'tools/linter/adapters/ruff_linter.py',
# '--config=pyproject.toml',
# '--show-disable',
# '--',
# '@{{PATHSFILE}}'
# ]
# is_formatter = true
# This linter prevents merge conflicts in csv files in pytorch by enforcing
# three lines of whitespace between entries such that unless people are modifying
# the same line, merge conflicts should not arise in git or hg
[[linter]]
code = 'MERGE_CONFLICTLESS_CSV'
include_patterns = [
'benchmarks/dynamo/ci_expected_accuracy/*.csv',
'benchmarks/dynamo/pr_time_benchmarks/expected_results.csv',
]
command = [
'python3',
'tools/linter/adapters/no_merge_conflict_csv_linter.py',
'--',
'@{{PATHSFILE}}'
]
is_formatter = true
[[linter]]
code = 'META_NO_CREATE_UNBACKED'
include_patterns = [
"torch_npu/_meta_registrations.py"
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=create_unbacked',
'--linter-name=META_NO_CREATE_UNBACKED',
'--error-name=no create_unbacked in meta registrations',
"""--error-description=\
Data-dependent operators should have their meta \
registration in torch_npu/_subclasses/fake_impls.py, \
not torch_npu/_meta_registrations.py
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'ATEN_CPU_GPU_AGNOSTIC'
include_patterns = [
# aten source
"aten/src/ATen/*.cpp",
"aten/src/ATen/cpu/*.cpp",
"aten/src/ATen/functorch/**/*.cpp",
"aten/src/ATen/nnapi/*.cpp",
"aten/src/ATen/quantized/*.cpp",
"aten/src/ATen/vulkan/*.cpp",
"aten/src/ATen/metal/*.cpp",
"aten/src/ATen/detail/CPUGuardImpl.cpp",
"aten/src/ATen/detail/MetaGuardImpl.cpp",
# aten native source
"aten/src/ATen/native/cpu/*.cpp",
"aten/src/ATen/native/ao_sparse/cpu/kernels/*.cpp",
"aten/src/ATen/native/ao_sparse/quantized/cpu/kernels/*.cpp",
"aten/src/ATen/native/quantized/cpu/kernels/*.cpp",
"aten/src/ATen/native/*.cpp",
"aten/src/ATen/native/cpu/**/*.cpp",
"aten/src/ATen/native/ao_sparse/*.cpp",
"aten/src/ATen/native/ao_sparse/**/*.cpp",
"aten/src/ATen/native/ao_sparse/quantized/*.cpp",
"aten/src/ATen/native/ao_sparse/quantized/**/*.cpp",
"aten/src/ATen/native/nested/*.cpp",
"aten/src/ATen/native/quantized/*.cpp",
"aten/src/ATen/native/quantized/**/*.cpp",
"aten/src/ATen/native/sparse/*.cpp",
"aten/src/ATen/native/transformers/*.cpp",
"aten/src/ATen/native/utils/*.cpp",
"aten/src/ATen/native/xnnpack/*.cpp",
"aten/src/ATen/native/metal/MetalPrepackOpRegister.cpp",
# aten headers
"aten/src/ATen/*.h",
"aten/src/ATen/functorch/**/*.h",
"aten/src/ATen/ops/*.h",
"aten/src/ATen/cpu/**/*.h",
"aten/src/ATen/nnapi/*.h",
"aten/src/ATen/quantized/*.h",
"aten/src/ATen/vulkan/*.h",
"aten/src/ATen/metal/*.h",
"aten/src/ATen/mps/*.h",
# aten native headers
"aten/src/ATen/native/*.h",
"aten/src/ATen/native/cpu/**/*.h",
"aten/src/ATen/native/nested/*.h",
"aten/src/ATen/native/sparse/*.h",
"aten/src/ATen/native/ao_sparse/*.h",
"aten/src/ATen/native/ao_sparse/cpu/*.h",
"aten/src/ATen/native/ao_sparse/quantized/*.h",
"aten/src/ATen/native/ao_sparse/quantized/cpu/*.h",
"aten/src/ATen/native/quantized/*.h",
"aten/src/ATen/native/quantized/cpu/*.h",
"aten/src/ATen/native/transformers/*.h",
"aten/src/ATen/native/quantized/cpu/qnnpack/include/*.h",
"aten/src/ATen/native/utils/*.h",
"aten/src/ATen/native/vulkan/ops/*.h",
"aten/src/ATen/native/xnnpack/*.h",
"aten/src/ATen/native/metal/MetalPrepackOpContext.h",
"aten/src/ATen/native/mps/Copy.h",
"aten/src/ATen/native/mkldnn/**/*.h",
]
exclude_patterns = [
"aten/src/ATen/Context.h",
"aten/src/ATen/Context.cpp",
"aten/src/ATen/DLConvertor.cpp",
"aten/src/ATen/core/Array.h",
"aten/src/ATen/native/quantized/ConvUtils.h",
"aten/src/ATen/native/sparse/SparseBlasImpl.cpp", # triton implementation
"aten/src/ATen/native/transformers/attention.cpp",
"aten/src/ATen/native/**/cudnn/**", # cudnn is cuda specific
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=(^#if.*USE_ROCM.*)|(^#if.*USE_CUDA.*)',
'--linter-name=ATEN_CPU',
'--error-name=aten-cpu should be gpu agnostic',
"""--error-description=\
We strongly discourage the compile-time divergence \
on ATen-CPU code for different GPU code. This \
disallows sharing the same aten-cpu shared object \
between different GPU backends \
""",
'--',
'@{{PATHSFILE}}'
]
is_formatter = true
# # `set_linter` detects occurrences of built-in `set` in areas of Python code like
# # _inductor where the instability of iteration in `set` has proven a problem.
# [[linter]]
# code = 'SET_LINTER'
# command = [
# 'python3',
# 'tools/linter/adapters/set_linter.py',
# '--lintrunner',
# '--',
# '@{{PATHSFILE}}'
# ]
# include_patterns = [
# "torch_npu/_inductor/**/*.py",
# "torch_npu/_functorch/partitioners.py",
# ]
# is_formatter = true
# # `docstring_linter` reports on long Python classes, methods, and functions
# # whose definitions have very small docstrings or none at all.
# #
# [[linter]]
# code = 'DOCSTRING_LINTER'
# command = [
# 'python3',
# 'tools/linter/adapters/docstring_linter.py',
# '--lintrunner',
# '--',
# '@{{PATHSFILE}}'
# ]
# include_patterns = [
# 'torch_npu/_inductor/**/*.py'
# ]
# exclude_patterns = [
# 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/kernels/**',
# 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py',
# ]
# is_formatter = false
# `import_linter` reports on importing disallowed third party libraries.
[[linter]]
code = 'IMPORT_LINTER'
command = [
'python3',
'tools/linter/adapters/import_linter.py',
'--',
'@{{PATHSFILE}}'
]
include_patterns = [
'torch_npu/_dynamo/**',
]
is_formatter = false
[[linter]]
code = 'TEST_DEVICE_BIAS'
command = [
'python3',
'tools/linter/adapters/test_device_bias_linter.py',
'--',
'@{{PATHSFILE}}',
]
include_patterns = [
'test/**/test_*.py',
]
exclude_patterns = [
# CPython tests
'test/dynamo/cpython/**',
]
# 'header_only_linter' reports on properly testing header-only APIs.
[[linter]]
code = 'HEADER_ONLY_LINTER'
command = [
'python3',
'tools/linter/adapters/header_only_linter.py',
]
include_patterns = [
'torch_npu/header_only_apis.txt',
]
is_formatter = false
[[linter]]
code = "GB_REGISTRY"
include_patterns = ["torch_npu/_dynamo/**/*.py"]
command = [
"python3",
"tools/linter/adapters/gb_registry_linter.py",
]
# [[linter]]
# code = 'STABLE_SHIM_VERSION'
# include_patterns = [
# 'torch_npu/csrc/stable/c/shim.h',
# 'torch_npu/csrc/inductor/aoti_torch/c/shim.h'
# ]
# command = [
# 'python3',
# 'tools/linter/adapters/stable_shim_version_linter.py',
# '--',
# '@{{PATHSFILE}}'
# ]
[[linter]]
code = 'STABLE_SHIM_USAGE'
include_patterns = [
'torch_npu/csrc/stable/**/*.h',
]
command = [
'python3',
'tools/linter/adapters/stable_shim_usage_linter.py',
'--',
'@{{PATHSFILE}}'
]