Ascend NPU Operator Adaptation Sub-repository for TorchNPU
English | 简体中文
Compatibility · Installation · Operator Development · API Reference · Contributing · TorchNPU Repository
OpPlugin is the operator adaptation sub-repository of TorchNPU. It provides Ascend NPU implementations for native PyTorch operators and TorchNPU custom operators.
TorchNPU integrates this repository through the third_party/op-plugin submodule and compiles its operator adaptation code into the torch_npu package. Building and running OpPlugin depend on TorchNPU. To use these operators, install a compatible TorchNPU package; no separate OpPlugin package is required.
- Operator adaptation: Connects to CANN operator interfaces to implement NPU computation for native PyTorch operators and TorchNPU custom operators.
- Configuration and code generation: Uses YAML configuration to manage operator interfaces, version adaptation, and forward/backward bindings, with support for structured adaptation code generation.
- Development and verification: Provides operator adaptation guides, custom operator extension examples, and test cases.
OpPlugin is integrated and released with the corresponding TorchNPU version. Refer to TorchNPU for shared environment requirements and support policies:
- Compatibility: Version mappings for PyTorch, TorchNPU, CANN, and Python.
- Support: Version support status and lifecycle.
For historical versions, read the documentation on the corresponding branch.
Follow the TorchNPU installation guide to prepare the driver, firmware, CANN, PyTorch, and TorchNPU. Then verify your NPU environment with the TorchNPU quick start.
To modify or add operators, choose one of the following workflows:
- Build from the TorchNPU repository: Follow the TorchNPU source installation guide (Chinese) to obtain the source and submodules, develop in
third_party/op-plugin, and build with TorchNPU. - Build from this repository: Follow the OpPlugin source build guide to prepare the environment, then use
ci/build.shto build with a specified TorchNPU version.
The build script in this repository obtains the TorchNPU source, integrates the local operator adaptation code, and produces a torch_npu wheel in dist/. Select the Python version and TorchNPU branch according to the target version's requirements.
| Task | Documentation |
|---|---|
| Configure operator interfaces, version adaptation, forward/backward bindings, and structured adaptation | API adaptation workflow (Chinese) |
| Adapt Ascend C custom operators through OpPlugin | TorchNPU operator adaptation guide |
| Build custom operator extensions using C++ extensions | Custom operator extension examples (Chinese) |
| Review and add operator test cases | Tests |
The TorchNPU custom API reference (Chinese) describes API functionality, signatures, parameters, constraints, and usage examples. Refer to each API document for its supported versions and hardware.
├── ci # Build and test scripts
├── codegen # Operator adaptation code generation
├── docs # Installation, security, and API documentation
├── examples # Custom operator extension examples
├── op_plugin # Operator adaptation implementations
│ ├── config # Operator interface and adaptation configuration
│ ├── ops # Operator implementations
│ │ ├── aclops # aclop operator adaptation
│ │ └── opapi # aclnn operator adaptation
│ └── python # Python-related implementations
├── test # Operator test cases
└── torchnpugen # TorchNPU code generation tools
OpPlugin follows the development workflow and contribution conventions in the TorchNPU contribution guide. Submit changes to this repository's code, tests, and documentation as OpPlugin PRs.
Report operator adaptation issues or suggestions through OpPlugin Issues. For TorchNPU framework issues, use TorchNPU Issues.
The Ascend for PyTorch community's Core SIG is responsible for the design, implementation, and maintenance of OpPlugin. Contributions and discussions are welcome.
Read the OpPlugin security statement before using this repository. For shared security hardening and runtime requirements, see the TorchNPU security note.
To OpPlugin plug-in users
-
This plug-in is for debugging and development only. You must bear the risks and understand the following:
- Data processing and deletion: The data generated during the use of this plug-in belongs to the user's responsibility. You are advised to delete related data in time after using the data to prevent information leakage.
- Data confidentiality and dissemination: Users understand and agree not to send or disseminate the data generated through this plug-in at will. This plug-in and its developers are not responsible for any information leakage, data leakage, or other adverse consequences arising therefrom.
- User input security: Users must ensure the security of the entered command lines and bear any security risks or losses caused by improper input. This plug-in and its developers are not responsible for any problems caused by improper command line input.
-
Scope of Disclaimer: This disclaimer applies to all individuals or entities using this plug-in. By using this plug-in, you agree to and accept the content of this statement and are willing to bear the risks and responsibilities arising from the use of this function. If you have any objection, please stop using this plug-in.
-
Read and understand the disclaimer before using this tool. For any questions or questions arising from the use of this plug-in, please contact the developer in time.
See LICENSE for the OpPlugin license.
Thanks for every PR from the community! Contributions to OpPlugin code, tests, and documentation are welcome.