【docs】fix community contributing docs

Co-authored-by: zyw-hw<zhangyouwen7@huawei.com>



# message auto-generated for no-merge-commit merge:
!44879 merge fix_contribute_docs into master

【docs】fix community contributing docs

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

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

- [ ] 需求
- [x] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新

# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
修改社区贡献文档,将相关内容整理在同一章节,提升文档易用性,解决以下问题:
1、贡献场景格式老旧,和当前的格式存在差异
2、章节介绍逻辑混乱,提交PR等需要反复跳转,未循序渐进
3、缺少SIG等机制的介绍,社区沟通方式不完整
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
> 不涉及功能等资料变更

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

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

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

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


See merge request: Ascend/pytorch!44879
This commit is contained in:
zyw-hw
2026-09-16 16:13:00 +08:00
committed by ascend-robot
parent c49c282770
commit 9132ca84f8
2 changed files with 531 additions and 466 deletions
+299 -264
View File
@@ -10,27 +10,27 @@ TorchNPU is a deep learning adaptation plug-in based on Ascend NPU. It is optimi
```text
pytorch
├── docs/ #Project Documentation
├── ci/ #Script for building the CI.
├── tools/ #Development tool
├── cmake/ #CMake Configuration
├── torch_npu/ #NPU Core Adaptation Module
│ ├── csrc/ #C++ backend implementation
│ ├── distributed/ #Distributed Python interface
│ ├── _inductor/ #Inductor backend adaptation
│ ├── dynamo/ #Dynamo Compiler Adaptation
│ ├── npu/ #NPU Python interface
│ ├── profiler/ #Performance Analysis Python Interface
│ ├── _afd/ #AFD Python Interface
│ ├── _logging/ #Python interface of the log module
│ ├── asd/ #Asynchronous detection tool
│ ├── contrib/ #Extended Modules Contributed
│ ├── onnx/ #ONNX adaptation
│ └── optim/ #Optimizer adaptation
├── third_party/ #Third-Party Dependency
├── torchnpugen/ #Code generation tool
├── examples/ #Sample Code
└── test/ #Test Case
├── docs/ # Project Documentation
├── ci/ # Script for building the CI.
├── tools/ # Development tool
├── cmake/ # CMake Configuration
├── torch_npu/ # NPU Core Adaptation Module
│ ├── csrc/ # C++ backend implementation
│ ├── distributed/ # Distributed Python interface
│ ├── _inductor/ # Inductor backend adaptation
│ ├── dynamo/ # Dynamo Compiler Adaptation
│ ├── npu/ # NPU Python interface
│ ├── profiler/ # Performance Analysis Python Interface
│ ├── _afd/ # AFD Python Interface
│ ├── _logging/ # Python interface of the log module
│ ├── asd/ # Asynchronous detection tool
│ ├── contrib/ # Extended Modules Contributed
│ ├── onnx/ # ONNX adaptation
│ └── optim/ # Optimizer adaptation
├── third_party/ # Third-Party Dependency
├── torchnpugen/ # Code generation tool
├── examples/ # Sample Code
└── test/ # Test Case
```
### Core Module Description
@@ -44,355 +44,390 @@ pytorch
| `torch_npu/npu/amp` | Automatic blending precision: GradScaler, FP16/BF16 support |
| `torchnpugen` | Code generation tools: automatic differential code generation, code templates |
| `examples` | Sample code: distributed communication, model inference, ResNet example |
| `third_party/op-plugin` | Operator plug-in: custom operator implementation and PyTorch operator coverage |
| `third_party/op-plugin` | Operator plug-in: custom operator implementation and TorchNPU operator coverage |
| `test/npu` | NPU function test: device management, memory allocation, and operator test |
## Contribution Mode
## Contribution Overview
We look forward to your joining! Each contribution is an important driving force behind TorchNPU's progress:
### Contribution Modes
- **Feedback on issues**: Report bugs or submit feature suggestions to help us find and solve problems
- **Contribute code**: Submit code fixing or new function implementation, and directly participate in project development.
- **Complete the document**: Improve the document or supplement the missing content to improve the project readability.
- **Code review**: Review Pull requests to help improve code quality.
- **Share and communicate**: Share projects on blogs and social media, and point to the warehouse.
We look forward to your joining! Every contribution is an important driving force for TorchNPU's progress:
## Contribution Scenario
- **Report issues**: Report bugs or submit feature suggestions to help us discover and solve problems
- **Submit proposals**: Propose technical solutions or architectural designs to guide project evolution
- **Contribute code**: Submit code fixes or new feature implementations, directly participating in project development
- **Improve documentation**: Improve documentation or supplement missing content to enhance project readability
- **Code review**: Review Pull Requests to help improve code quality
- **Assist the community**: Answer questions and share solutions to help more developers
- **Share and promote**: Share the project on blogs and social media to expand community influence
This project warmly welcomes all forms of contributions and looks forward to your participation!
### Communication Channels
### 1. Requirements and Function Suggestions
We provide multiple communication channels for you to engage in community interaction:
If you have new feature suggestions or performance optimization ideas, we invite you to submit an issue for further discussion in the community.
- **[Issues](https://gitcode.com/Ascend/pytorch/issues)**: For reporting bugs and proposing feature suggestions
- **[Pull Requests](https://gitcode.com/Ascend/pytorch/pulls)**: For code review and discussion
- **[SIG](https://gitcode.com/Ascend/community/tree/master/AscendForPyTorch/sigs)**: Community collaboration organizations divided by technical area, responsible for code review and technical decisions
**Issue type: requirement/function suggestion**
### Contribution Scenarios
**Contents to be included:**
Submitting an Issue is the first step in contributing. When [creating an Issue](https://gitcode.com/Ascend/pytorch/issues/create/choose), please select the corresponding template:
- **Function background**: What problems can this function solve and what benefits can it bring to users?
- **Function description**: Describe the recommended functions in detail.
- **Design solution**: technical idea, key module design, and relationship between upstream and downstream components.
- **Expected benefits**: function objectives, performance indicators, and precision performance.
#### Bug Report
### 2. Bug feedback and fixing
When you find a bug, please use the 🐛 Bug report template to submit an Issue. The template includes the following required fields:
If you find a bug or documentation problem, we sincerely welcome your feedback and suggestions for fixing it.
- **Environment information**: Operating system, Ascend hardware information, CANN software version, and installed software versions
- **🐛 Problem description**: Clearly and concisely describe the specific phenomenon and occurrence scenario of the bug; if reproducible, provide a **minimal reproducible example** (stripped of irrelevant code and business dependencies, directly runnable), and paste the error message including the **full traceback**
**Bug report format:**
> ⚠️ Please desensitize: Before submitting, remove sensitive information such as API keys, passwords, private addresses, and personal data; use placeholders such as `<TOKEN>` if necessary.
- **Environment information**: PyTorch version, OS, Python version, and CANN version.
- **Problem Description**: Add a tag to highlight on the problem dashboard.
- **Reproduction procedure**: Describe how to reproduce the problem in detail.
- **Expected Behavior**: Describe the behavior you expect to occur.
- **Special Note to Reviewer**: If there are any special circumstances.
#### Feature Request
**Repair process:**
When you have new feature suggestions or performance optimization ideas, please use the ✨ Feature request template to submit. The template includes the following fields:
1. Find the corresponding bug description in the Issue.
2. Comment on the`/assign`Claim this task
3. Creating a Branch for Repair
4. Submit a Pull Request.
- **💻 Requirement background, current status, expected feature content, specific design proposal, and test plan** (required): Explain the requirement scenario, why current capabilities are insufficient, the proposed feature content and design approach; relevant Issue/PR links may be attached
- **Alternative solutions**: Describe other implementation approaches you have considered
- **Additional notes**: Other relevant notes or screenshots
### 3. Assistance in community building
#### RFC (Request for Comments)
If you have the ability to solve the problem others have raised, we look forward to sharing your solution in the Issue.
For major architectural changes or technical proposals, please use the 📜 RFC (Request for Comments) template to initiate an RFC, which will be advanced after community discussion and review. The RFC template is a structured document with the following main sections:
## Contribution process
- **Overview**: Introduction, motivation, goals and non-goals
- **Use case analysis**: Scenario use cases, key performance indicators, security/privacy and DFX requirements
- **Design proposal**: Overall proposal, technology selection, functional and performance design, security/privacy and DFX design, programming and invocation design (including interface definitions)
- **Test design**: Unit tests, integration tests, end-to-end tests
- **Drawbacks and risks**: Breaking changes, performance regression, implementation cost, compatibility, etc.
- **Prior art**: Similar designs referenced from other projects/communities
- **Unresolved questions**: Open questions awaiting community discussion and decision
### Contributor License Agreement
## Contribution Process
Before you submit your code to the Ascend for PyTorch community for the first time, you need to sign [CLA](https://clasign.osinfra.cn/sign-cla/690ca9ddf91c03dee6082ab1/individual).
To ensure smooth contributions, please follow this process:
### Development and test
### Step 1: Sign the CLA
1. **Fork repository**: On the GitCode platform, click Fork in the upper right corner of the repository to clone the repository to the personal account.
2. **Clone to local:**
```bash
git clone https://gitcode.com/<your-username>/pytorch.git
cd pytorch
```
Before you submit code to the TorchNPU community for the first time, you need to sign the CLA (Contributor License Agreement).
3. **To create a development branch:**
```bash
git checkout -b {new_branch_name} origin/master
```
- **Individual contributors**: please refer to the [ICLA online document](https://clasign.osinfra.cn/sign-cla/690ca9ddf91c03dee6082ab1/individual)
- **Corporate contributors**: please refer to the [CCLA online document](https://clasign.osinfra.cn/sign-cla/690ca9ddf91c03dee6082ab1/employee)
4. **Code development**: Please follow the [Code Specifications](#code-specifications).
5. **Code test**: Run tests to ensure that the code functions properly.
6. **Access control check**: Run the CI check to ensure that the code passes the compilation, static check, and UT test.
7. **Submit a Pull Request**: Submit a PR and wait for the code review.
8. **Community review**: If patches, header file macros, and API interface updates are involved, submit the updates to the community for review.
### Step 2: Submit an Issue
### Code Incorporation Review Requirements
Before starting development, please submit an Issue describing the problem you want to solve or the feature you propose, so that the community can understand and discuss it. For the detailed format requirements of Issues, please refer to [Contribution Scenarios](#contribution-scenarios).
The following types of modifications require community review:
### Step 3: Community Discussion
- **Patch replacement**: Replace the patch of the PyTorch native interface.
- **Header file macro update**: Add or modify macro definitions.
- **API interface change**: adding, modifying, or deleting public APIs.
- **Core component changes**: Core modules such as memory management and device management are modified.
After submitting an Issue, please discuss it in the community and confirm the proposal is feasible before starting development.
## Code Specifications
#### Claim a Task
Follow these styles to make the Torch NPU easy to develop, review, and maintain.
If you want to fix a bug, please comment `/assign` under the corresponding Issue to claim the task and avoid duplicate work by multiple people.
### Coding Guide
#### SIG Review
- **Python**: recommended [PEP 8 Coding Style](https://pep8.org/).
- **C++**: recommended [Google C++ Coding Guide](http://google.github.io/styleguide/cppguide.html).
The following types of changes require community review through the SIG (Special Interest Group) mechanism:
Check the code. For details, see the [Local static check](#local-static-check).
- **Patch replacement**: Patch replacement of TorchNPU native interfaces
- **Header file macro update**: Add or modify macro definitions
- **API interface change**: Add, modify, or delete public APIs
- **Core component change**: Modifications to core modules such as memory management and device management
- **RFC proposal**: Major architectural changes or technical proposals that require initiating an RFC to solicit community input
### Unit Test Guide
A SIG is a community collaboration organization divided by technical area, responsible for code review and technical decisions. For the detailed SIG list, please refer to the [Ascend community SIG page](https://gitcode.com/Ascend/community/tree/master/AscendForPyTorch/sigs). For changes involving the above types, please declare community review through the SIG mechanism in the PR.
- **Python**: recommended [pytest](http://pytest.org/en/latest/).
- **C++**: recommended [Googletest Primer](https://github.com/google/googletest/blob/master/docs/primer.md).
### Step 4: Fork and Clone
The design intent of a test case should be reflected by its annotation name.
1. **Fork the repository**: On the GitCode platform, click the "Fork" button in the upper right corner of the repository to create a copy under your personal account
### Refactoring Guide
2. **Clone to local**:
Developers are encouraged to refactor the code to eliminate code odors. All code should conform to the coding style and test style requirements.
```bash
git clone https://gitcode.com/<your-username>/pytorch.git
cd pytorch
```
## hands-on guide
3. **Create a development branch**:
### Environment setup and compilation
```bash
git checkout -b {new_branch_name} origin/master
```
**Compilation and building:**
### Step 5: Code Development
Please follow the coding styles below to make TorchNPU easy to develop, review, and maintain.
#### Coding Guide
- **Python**: recommended [PEP 8 Coding Style](https://pep8.org/)
- **C++**: recommended [Google C++ Coding Guide](http://google.github.io/styleguide/cppguide.html)
#### Refactoring Guide
Developers are encouraged to refactor the code to eliminate code smells. All code should conform to the coding style and test style requirements.
#### Environment Setup
For detailed installation guidance (including dependencies and environment requirements for each version), please refer to the [Ascend community installation guide](https://www.hiascend.com/document/detail/zh/Pytorch/master/installguide/ref/docs/zh/installation_guide/references/building_from_source.md).
Quick build commands:
```bash
#Installing and Compiling the Dependency (If --torch is not specified, the installed version of PyTorch in the environment is used.)
# Install dependencies and compile
bash ci/build.sh --python=3.10
#Build for the specified PyTorch version (supporting version 2.13 and later. The available version is the version.txt file.)
#--The value of torch indicates the version of the package to be built, which can contain the post number. (For example, 2.13.0.post1 indicates the post build of the 2.13 main line.)
#The PyTorch corresponding to major.minor has been installed.
# Build for a specified PyTorch version (supporting version 2.13 and later. The available version is the version.txt file.)
# --The value of torch indicates the version of the package to be built, which can contain the post number. (For example, 2.13.0.post1 indicates the post build of the 2.13 main line.)
# The PyTorch corresponding to major.minor has been installed.
bash ci/build.sh --python=3.10 --torch=2.14.0
#Or manually compile with CMake
# Or manually compile with CMake
mkdir build && cd build
cmake ..
make -j$(nproc)
```
### Compilation Acceleration Skills
To speed up compilation, the project has built-in automatic detection for Ninja, Mold linker, and CCache. For usage, see [Build Acceleration](docs/en/installation_guide/references/build_acceleration.md).
For instructions on using Ninja, Mold, CCache, and building only the required targets, see [Build Acceleration](docs/en/installation_guide/references/build_acceleration.md).
### Step 6: Local Static Check
After completing code development, please run static checks locally to ensure code style and quality meet the requirements. For details, see [Appendix A: Local Static Check](#appendix-a-local-static-check).
### Building with Clang
For instructions on compiling with Clang, please refer to [Building with Clang](docs/en/installation_guide/references/building_with_clang.md)
### Local static check
### Step 7: Local Functional Verification
Project Use [lintrunner](https://github.com/suo/lintrunner) Perform static check. Check items that are the same as CI can be run locally, including Python code style (Flake8, Ruff, and PYFMT), C++ format (ClangFormat and ClangTidy), and spelling check (Codespell).
Please write and run unit tests to ensure the code functions correctly. If new features are added, corresponding test cases must be added. For details, see [Appendix B: Unit Tests and Functional Verification](#appendix-b-unit-tests-and-functional-verification).
#### Installation Dependency
### Step 8: Submit a Pull Request
```bash
#Install lintrunner and UV (required by some linters).
pip install lintrunner
pip install uv
```
1. **Push code to the remote repository**:
#### Initialize (once at first use or update)
```bash
git add .
git status
git commit -m "feat(module): brief description of changes"
git commit -s --amend # Add a detailed description
git push origin {new_branch_name}
```
```bash
#Download the external binary tools required by the lintrunner, such as clang-format and clang-tidy.
lintrunner init
```
> **Note**: One PR per commit is the recommended practice for this project. If multiple incremental commits are produced during development, please use `git rebase -i` to squash them into a single commit before pushing, to keep the commit history clean.
#### Perform static checks
2. **Create a Pull Request**
```bash
#Checks the current workspace changes and the file delta committed by HEAD (Workspace + HEAD)
lintrunner
Create a Pull Request on GitCode, filling it out completely according to the [PR template](./.gitcode/PULL_REQUEST_TEMPLATE.md):
#Run only specified checks
lintrunner --take FLAKE8,RUFF,PYFMT,SPACES,TABS,NEWLINE
- Merge source
- Modification proposal
- Documentation changes
- Interface changes
- Functional verification
- Checklist
#Automatically fix problems that can be automatically fixed (formatter class linter, e.g., ignore PYREFLY)
lintrunner --skip PYREFLY -a
After confirming the information is complete and accurate, submit the Pull Request and wait for code review.
#Check only file deltas for changes in the current workspace
git diff --name-only HEAD | xargs lintrunner
```
### Step 9: Trigger Gate Checks
> **Hint:**`--take`You can specify the parameters to run only some check items. The common check items are as follows:
>
> | Code | Description |
> | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
> | `FLAKE8` | Python Syntax and Style Check |
> | `RUFF` | Python fast lint and import sorting |
> | `PYFMT` | Python code formatting (usort + ruff-format) |
> | `CLANGFORMAT` | C++ code formatting |
> | `CLANGTIDY` | C++ static analysis |
> | `SPACES` | Line end blank check |
> | `TABS` | Tab character check |
> | `NEWLINE` | Newline check at the end of a file |
> | `CODESPELL` | Spell check, and if it's a false positive, add the false positive words in lexicographic order to`tools/linter/dictionary.txt`And then re-check |
After submitting the PR, type `compile` in the PR comment area to trigger the gate checks. For more bot command details, refer to the [Ascend community bot usage guide](https://gitcode.com/Ascend/infrastructure/blob/master/docs/robot/robot%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97.md).
For more commands, see the [lintrunner wiki](https://github.com/pytorch/pytorch/wiki/lintrunner).
Gate check failures mainly include the following types. Please resolve them according to the related prompts:
### PR Incorporation Requirements
- **Compilation error**: Check the cause of the code compilation failure, resolve the issue, and recompile
- **Static check exception**: Follow the prompts to find and resolve issues in the code (such as code style, potential bugs, etc.)
- **UT test failure**: Locate the failing test cases according to the prompts and investigate the cause
**Checklist** (For details, see the PR template):
### Step 10: Code Review and Merge
- \[\] Code compilation is successful.
- \[\] Static check (such as CppLint and CppCheck) passed.
- \[\] UT test case passed.
- \[\] The code style complies with the specifications (PEP 8 and Google C++ Style).
- \[\] Specification for submission of information (conventional Commits compliance)
- \[\] PR Header Correct use of type labels (feat, fix, refactor, docs, test, etc.)
- \[\] The code comments are complete and error logs are recorded correctly.
- \[\] The code implementation verifies the return value and null pointer.
#### PR Merge Requirements
### Function Verification Guide
**Merge checklist** (for detailed requirements, see the [PR template](./.gitcode/PULL_REQUEST_TEMPLATE.md)):
**Test Case Location:**
- [ ] Code compiles successfully
- [ ] Static checks pass (CppLint, CppCheck, etc.)
- [ ] UT test cases pass
- [ ] Code style complies with specifications (PEP 8, Google C++ Style)
- [ ] Commit message is standardized (Conventional Commits compliant)
- [ ] PR title correctly uses type labels (feat, fix, refactor, docs, test, etc.)
- [ ] Code comments are complete and error logs are recorded correctly
- [ ] Code implementation includes return value and null pointer validation
- `test/npu/`\- NPU function test
- `test/nn/`\- Network layer test
- `test/distributed/`\- Distributed test
- `test/dynamo/`\- Compiler test
#### Code Review Process
**Run the test** (for details, see the Test Document):
1. **Reviewer review**: After the reviewer of the corresponding module reviews the code, type `/lgtm` in the PR comment area to indicate approval
2. **Committer approval**: After the committer of the corresponding module reviews and approves, type `/approve` in the PR comment area to indicate consent to merge
3. **Automatic merge**: After the PR meets the merge conditions, the bot will automatically merge the code
```bash
#Installation test dependency
pip3 install -r test/requirements.txt
> **Tip**: The complete list of reviewers and committers can be viewed by clicking the corresponding link in the first comment of the PR.
#Complete the test file.
cd test
bash get_synchronized_files.sh
## Advanced Guide
#Running a Single Test File
python test_autocast.py
### AI-Assisted R&D
#or run_test.py
python run_test.py -i test_autocast
The TorchNPU project encourages the use of AI-assisted R&D and document development to improve contribution efficiency. We provide the official Ascend agent-skills repository, which contains a series of AI Agent Skill configurations for the Ascend ecosystem, helping you better utilize AI coding assistants during development.
#Running a Specified Test Case
python test_autocast.py -v -k test_autocast_nn_fp32
- **agent-skills repository**: [https://gitcode.com/Ascend/agent-skills](https://gitcode.com/Ascend/agent-skills)
- This repository provides Skill templates and tools commonly used in Ascend chip scenarios, applicable to code generation, problem diagnosis, performance analysis, and more.
- The skills in the repository are continuously updated. New skills are welcome, as are improvement suggestions for existing skills.
#Running the full UT
cd ..
python ci/access_control_test.py --all
```
When using AI-assisted R&D, please note:
### Troubleshooting Access Control Exceptions
- AI-generated code still requires manual review to ensure code quality, security, and correctness.
- Follow the project's [Coding Guide](#step-5-code-development) and [Appendix B: Unit Tests and Functional Verification](#appendix-b-unit-tests-and-functional-verification).
- Submitted code must pass gate checks (compilation, static checks, UT tests, etc.).
The access control exceptions include the following. Rectify the faults according to the related prompts:
### Document Development Notes
- **Compilation error**: Check the cause of the code compilation failure, rectify the fault, and then recompile the code.
- **Static check exception**: Follow the prompt to locate and solve the problems (such as the code style and potential bugs) in the code.
- **If the UT test fails**: Locate the items that fail to pass the test and locate the cause.
#### Document Hosting
### AI-assisted R&D
This project's documentation is in Markdown format, stored in the `docs/en/` directory of the repository, and hosted on the GitCode platform together with the code.
The TorchNPU project encourages AI-assisted R&D and document development to improve contribution efficiency. we provides the official Ascend agent-skills repository, which contains a series of AI agent skills applicable to the Ascend ecosystem, helping you better use AI coding assistants during development.
> **Note**: Documentation is hosted on long-term stable version branches, such as `v2.7.1`. If you need to view or modify documentation, please switch to the corresponding long-term stable version branch.
- **agent-skills repository:**https://gitcode.com/Ascend/agent-skills
- This repository provides skill templates and tools that are commonly used in the Ascend chip scenario, which can be used in scenarios such as code generation, problem diagnosis, and performance analysis.
- The skills in the warehouse are continuously updated. New skills are welcome to contribute or propose improvement suggestions for existing skills.
The documentation mainly includes the following categories:
When using AI to assist R&D, pay attention to the following points:
- **Installation Guide** (`installation_guide/`): Environment preparation, source compilation, pip installation, etc.
- **Quick Start** (`quick_start/`): Quick start tutorials.
- **Native API Documentation** (`native_apis/`): TorchNPU native API support status for each version.
- **Framework Feature Guide** (`framework_feature_guide_pytorch/`): NPU graph mode, Inductor, memory optimization, and other feature descriptions.
- **Environment Variable Reference** (`environment_variable_reference/`): NPU-related environment variable descriptions.
- **Troubleshooting** (`troubleshooting/`): Common problems and error code analysis.
- **Security Statement** (`SECURITYNOTE.md`): Security-related notes.
- **Contribution Guide** (`CONTRIBUTING.en.md`): This document.
- AI-generated code still needs to be manually reviewed to ensure code quality, security, and correctness.
- Following the project's [Code Specifications](#code-specifications)And to the [Unit Test Guide](#unit-test-guide).
- The submitted code must pass the access control check (compilation, static check, and UT test).
#### How to Submit Documentation
### Document Development Description
The documentation submission process is the same as the code submission process. Please refer to [Contribution Process](#contribution-process):
#### Document bearing mode
1. Fork the repository and create a local branch.
2. Add or modify the corresponding Markdown file in the `docs/en/` directory.
3. When writing documentation, note:
- Use clear and accurate English expressions.
- Code examples must be runnable.
- Follow the format and style of existing documentation.
4. Submit a Pull Request and describe the documentation changes in the PR description.
The documents of this project are in Markdown format and stored in the`docs/zh/`Directory, hosted with the code on the GitCode platform.
#### CI Documentation Checks
> **Note: The document is carried in the branch of the long-term stable version, such as**`v2.7.1`. If you need to view or modify the document, switch to the corresponding long-term stable version branch and perform the operation.
After a documentation Pull Request is submitted, the CI gate will automatically perform the following checks on the changed Markdown files:
The document mainly includes the following categories:
- **Installation Guide** (`installation_guide/`): environment preparation, source code compilation, and pip installation.
- **Quick Start** (`quick_start/`): Quick Start Tutorial.
- **Native API Documentation** (`native_apis/`): PyTorch native APIs supported by each version.
- **Framework Feature Guide** (`framework_feature_guide_pytorch/`): describes the NPU diagram mode, Inductor, and memory optimization features.
- **Environment Variable Reference** (`environment_variable_reference/`): describes the environment variables related to the NPU.
- **Troubleshooting** (`troubleshooting/`): FAQs and error code analysis.
- **Safety Statement** (`SECURITYNOTE.md`): safety-related description.
- **Contribution Guide** (`CONTRIBUTING.md`): This document.
#### How to submit a document
The document submission process is the same as the code submission process. For details, see the [Contribution process](#contribution-process):
1. Fork repository and create a local branch.
2. In the `docs/zh/` Add or modify the corresponding Markdown file in the directory.
3. Note the following when writing the document:
- Use clear and accurate Chinese expressions.
- The code sample must be runable.
- Follows the format and style of the existing document.
4. Submit a pull request and describe the document changes in the PR description.
#### Check the CI document
After the Pull Request is submitted, the CI access control system automatically checks the changed Markdown file as follows:
- **NEWLINE**: Ensure that the file contains only one newline character at the end of the file and that the file does not contain redundant blank lines.
- **Trailing Space Check (SPACES)**: Ensure that there are no extra spaces at the end of each line.
- **Tab Check (TABS)**: Ensure that the file is indented with spaces instead of tabs (Tab).
- **CodeSPELL**: Use the codespell tool to check spelling errors.
## Submit a Pull Request
1. **Push code to the remote repository:**
```bash
git add .
git status
git commit -m "Your commit title"
git commit -s --amend #Added detailed description.
git push origin {new_branch_name}
```
2. **Creating a Pull Request**
Create a Pull Request on the GitCode based on the PR Template Complete:
- Incorporation Source
- Modification scheme
- Document change
- Interface Changes
- Function Verification
- CheckList
Submit a Pull Request after confirming that the information is complete and correct, and wait for code review.
- **Newline check (NEWLINE)**: Ensure the file has exactly one newline at the end and no redundant blank lines.
- **Trailing space check (SPACES)**: Ensure no extra spaces at the end of each line.
- **Tab check (TABS)**: Ensure spaces are used for indentation instead of tabs (Tab).
- **Spell check (CODESPELL)**: Check English spelling errors using the codespell tool.
## Community Guidelines
### Code of Conduct
We are committed to providing a friendly, safe and inclusive environment for all participants:
We are committed to providing a friendly, safe, and inclusive environment for all participants:
- **Respect for differences**: respect for different views and experiences and inclusiveness of multiculturalism.
- **Open mind**: Accept constructive criticism and keep learning and improving.
- **Focus on contributions**: Focus on what is most beneficial to the community and promote project development.
- **Empathy**: Empathy for other community members and help each other.
- **Respect differences**: Respect different viewpoints and experiences, and embrace multiculturalism
- **Open mind**: Accept constructive criticism, and keep learning and improving
- **Focus on contributions**: Focus on what is most beneficial to the community and drive project development
- **Empathy**: Show empathy to other community members and help each other
### Communication channel
## Question Consultation
We provide you with multiple communication channels to engage in community interactions:
We warmly welcome every developer to actively participate in community discussions! Looking forward to growing together with you:
- **[Issues](https://gitcode.com/Ascend/pytorch/issues)**: used to report bugs and provide function suggestions.
- **[Pull Requests](https://gitcode.com/Ascend/pytorch/pulls)**: for code review and discussion.
- **Unresolved issues found**: Feel free to comment in Issues to showcase your solution
- **Long-unhandled issues**: Pre-checking before solving is recommended to avoid duplicate work
- **Successfully solved your own reported issue**: Please also share your solution so the community can learn and progress together
### Question consultation
If you have any questions, feel free to discuss in the community at any time. We look forward to your wonderful contributions!
We warmly welcome every developer to participate in the community discussion! Looking forward to growing with you:
## Appendix A: Local Static Check
- **Unresolved issues found**: Feel free to comment on the Issue to demonstrate your solution.
- **Problems that have not been handled for a long time**: It is recommended to perform pre-check before solving the problems to avoid repeated work.
- **Successfully solved the problems you reported**: Please also share your solution so that the community can learn and progress together.
The project uses [lintrunner](https://github.com/suo/lintrunner) for static checks, supporting running check items locally that are fully consistent with CI, including Python code style (Flake8, Ruff, PYFMT), C++ format (ClangFormat, ClangTidy), and spell check (Codespell).
If you have any questions, please feel free to exchange and discuss in the community and look forward to your wonderful contributions!
### Install Dependencies
```bash
# Install lintrunner and uv (required by some linters)
pip install lintrunner
pip install uv
```
### Initialize (run once on first use or update)
```bash
# Download external binary tools required by lintrunner (clang-format, clang-tidy, etc.)
lintrunner init
```
### Run Static Checks
```bash
# Check file deltas of current workspace changes and HEAD commit (workspace + HEAD)
lintrunner
# Run only specified check items
lintrunner --take FLAKE8,RUFF,PYFMT,SPACES,TABS,NEWLINE
# Automatically fix auto-fixable issues (formatter linters; skip PYREFLY if needed)
lintrunner --skip PYREFLY -a
# Check only file deltas of current workspace changes
git diff --name-only HEAD | xargs lintrunner
```
> **Tip**: The `--take` parameter specifies running only some check items. Common items:
>
> | Code | Description |
> |-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
> | `FLAKE8` | Python syntax and style check |
> | `RUFF` | Python fast lint and import sorting |
> | `PYFMT` | Python code formatting (usort + ruff-format) |
> | `CLANGFORMAT` | C++ code formatting |
> | `CLANGTIDY` | C++ static analysis |
> | `SPACES` | Trailing space check |
> | `TABS` | Tab character check |
> | `NEWLINE` | End-of-file newline check |
> | `CODESPELL` | Spell check. If a false positive occurs, add the word in lexicographic order to `tools/linter/dictionary.txt` and re-check |
For more commands, see the [lintrunner wiki](https://github.com/pytorch/pytorch/wiki/lintrunner).
## Appendix B: Unit Tests and Functional Verification
### Unit Test Guide
- **Python**: recommended [pytest](http://pytest.org/en/latest/)
- **C++**: recommended [Googletest Primer](https://github.com/google/googletest/blob/main/docs/primer.md)
The design intent of a test case should be reflected by its annotation name.
### Functional Verification Guide
**Test case locations**:
- `test/npu/` - NPU functional tests
- `test/nn/` - Network layer tests
- `test/distributed/` - Distributed tests
- `test/dynamo/` - Compiler tests
**Run tests** (for details, see the [test documentation](./test/README.md)):
```bash
# Install test dependencies
pip3 install -r test/requirements.txt
# Complete the test files
cd test
bash get_synchronized_files.sh
# Run a single test file
python test_autocast.py
# Or use run_test.py
python run_test.py -i test_autocast
# Run a specified test case
python test_autocast.py -v -k test_autocast_nn_fp32
# Run the full UT
cd ..
python ci/access_control_test.py --all
```
+232 -202
View File
@@ -44,68 +44,102 @@ pytorch
| `torch_npu/npu/amp` | 自动混合精度:GradScaler、FP16/BF16 支持 |
| `torchnpugen` | 代码生成工具:自动微分代码生成、代码模板 |
| `examples` | 示例代码:分布式通信、模型推理、ResNet 示例 |
| `third_party/op-plugin` | 算子插件:自定义算子实现、PyTorch 算子覆盖 |
| `third_party/op-plugin` | 算子插件:自定义算子实现、TorchNPU 算子覆盖 |
| `test/npu` | NPU 功能测试:设备管理、内存分配、算子测试 |
## 贡献方式
## 贡献概览
### 贡献方式
我们热情期待您的加入!每一个贡献都是推动 TorchNPU 进步的重要力量:
- **反馈问题**:报告 Bug 或提交功能建议,帮助我们发现并解决问题
- **提交方案**:提出技术方案或架构设计,为项目演进提供方向指引
- **贡献代码**:提交代码修复或新功能实现,直接参与项目开发
- **完善文档**:改进文档或补充缺失内容,提升项目可读性
- **代码审查**:审查 Pull Request,帮助提升代码质量
- **分享传播**:在博客、社交媒体上分享项目,给仓库点个 ⭐
- **协助社区**:解答他人问题、分享解决方案,帮助更多开发者
- **分享传播**:在博客、社交媒体上分享项目,扩大社区影响力
## 贡献场景
### 沟通渠道
本项目热烈欢迎各种形式的贡献,期待您的参与!
我们为您提供多种沟通渠道,方便您参与社区互动:
### 一、需求与功能建议
- **[Issues](https://gitcode.com/Ascend/pytorch/issues)**:用于报告 Bug、提出功能建议
- **[Pull Requests](https://gitcode.com/Ascend/pytorch/pulls)**:用于代码审查和讨论
- **[SIG](https://gitcode.com/Ascend/community/tree/master/AscendForPyTorch/sigs)**:按技术领域划分的社区协作组织,负责代码评审和技术决策
如果您有新功能建议或性能优化想法,我们热情邀请您提交 Issue 与社区深入讨论。
### 贡献场景
**Issue 类型**:需求/功能建议
提交 Issue 是参与贡献的第一步。在 [创建 Issue](https://gitcode.com/Ascend/pytorch/issues/create/choose) 时,请选择对应的模板:
**需要包含的内容**:
#### Bug Report(缺陷报告)
- **功能背景**:该功能解决什么问题、能为用户带来什么价值
- **功能描述**:详细描述建议的功能
- **设计方案**:技术思路、关键模块设计、上下游组件关系
- **预期收益**:功能目标、性能指标、精度表现
发现 Bug 时,请使用 🐛 Bug report 模板提交 Issue,模板包含以下必填项:
### 二、Bug 反馈与修复
- **环境信息**:操作系统、昇腾硬件信息、CANN 软件版本、已安装的对应软件版本
- **🐛 问题描述**:清晰简洁地描述 Bug 的具体现象与出现场景;若可复现,请提供**最小可复现示例**(剔除无关代码与业务依赖、可直接运行),并粘贴包含**完整堆栈(Full Traceback)**的报错信息
如果您发现 Bug 或文档问题,我们真诚欢迎您的反馈和修复建议。
> ⚠️ 请注意脱敏:提交前移除 API 密钥、密码、私有地址、个人数据等敏感信息,必要时用 `<TOKEN>` 等占位符替代。
**Bug Report 格式**:
#### Feature Request(需求建议)
- **环境信息**:PyTorch 版本、OS、Python 版本、CANN 版本等
- **问题描述**:添加标签以便在问题仪表板上突出显示
- **复现步骤**:尽可能详细地描述如何重现问题
- **预期行为**:描述您预期发生的行为
- **给审稿人的特别说明**:如有任何特殊情况
有新功能建议或性能优化想法时,请使用 ✨ Feature request 模板提交,模板包含以下字段:
**修复流程**:
- **💻 需求背景、当前现状、期望实现的功能内容、具体的设计方案、以及测试方案**(必填):说明需求场景、当前无法满足的原因、提议的功能内容与设计思路,可附相关 Issue/PR 链接
- **替代方案**:描述你考虑过的其他实现方案
- **补充说明**:其他相关说明或截图
1. 在 Issue 中找到对应的 Bug 描述
2. 评论 `/assign` 认领该任务
3. 创建分支进行修复
4. 提交 Pull Request
#### RFC(方案提案)
### 三、协助社区建设
如有较大的架构变更或技术方案,请使用 📜 RFC(Request for Comments)模板发起 RFC,经社区讨论和评审后推进实施。RFC 模板为结构化文档,主要章节包括:
如果您有能力解决他人提出的问题,我们热烈期待您在 Issue 中分享您的解决方案。
- **概述**:简介、动机、目标与非目标
- **用例分析**:场景用例、关键性能指标、安全隐私及 DFX 要求
- **方案设计**:总体方案、技术选型、功能与性能设计、安全隐私与 DFX 设计、编程与调用设计(含接口定义)
- **测试设计**:单元测试、集成测试、端到端测试
- **缺点和风险**:Breaking Change、性能回退、实现成本、兼容性等
- **现有技术**:参考其他项目/社区的类似设计
- **未解决问题**:待社区讨论决策的开放问题
## 贡献流程
### 贡献者许可协议
为确保贡献顺利进行,请按照以下流程操作:
在您第一次向 Ascend for PyTorch 社区提交代码之前,需要签署 [CLA](https://clasign.osinfra.cn/sign-cla/690ca9ddf91c03dee6082ab1/individual)。
### 第一步:签署 CLA
### 开发与测试
在您第一次向 TorchNPU 社区提交代码之前,需要签署 CLA(Contributor License Agreement)。
1. **Fork 仓库**:在 GitCode 平台点击仓库右上角 "Fork" 按钮,将仓库克隆到个人账户
- **个人贡献者**:请参考 [ICLA 在线文档](https://clasign.osinfra.cn/sign-cla/690ca9ddf91c03dee6082ab1/individual)
- **企业贡献者**:请参考 [CCLA 在线文档](https://clasign.osinfra.cn/sign-cla/690ca9ddf91c03dee6082ab1/employee)
### 第二步:提交 Issue
在开始开发之前,请先提交 Issue 描述您要解决的问题或建议的功能,以便社区了解和讨论。Issue 的详细格式要求请参考[贡献场景](#贡献场景)。
### 第三步:社区讨论
提交 Issue 后,请在社区中进行讨论,确认方案可行后再开始开发。
#### 认领任务
如果您要修复某个 Bug,请在对应 Issue 下评论 `/assign` 认领该任务,避免多人重复开发。
#### SIG 评审
以下类型的修改需要通过 SIG(Special Interest Group)机制进行社区评审:
- **Patch 替换**:对 TorchNPU 原生接口的 patch 替换
- **头文件宏更新**:新增或修改宏定义
- **API 接口变更**:新增、修改或删除公共 API
- **核心组件变更**:内存管理、设备管理等核心模块的修改
- **RFC 提案**:涉及重大架构变更或技术方案,需先发起 RFC 征集社区意见
SIG 是按技术领域划分的社区协作组织,负责代码评审和技术决策。详细的 SIG 列表请参考 [Ascend 社区 SIG 页面](https://gitcode.com/Ascend/community/tree/master/AscendForPyTorch/sigs)。涉及以上类型的修改,请在 PR 中通过 SIG 机制申报社区评审。
### 第四步:Fork 与克隆
1. **Fork 仓库**:在 GitCode 平台点击仓库右上角 "Fork" 按钮,在您的个人账号下创建一份仓库副本
2. **克隆到本地**:
@@ -120,55 +154,27 @@ pytorch
git checkout -b {new_branch_name} origin/master
```
4. **代码开发**:请遵循 **[代码规范](#代码规范)**
### 第五步:代码开发
5. **代码测试**:运行测试确保代码功能正常
请遵循以下编码风格,使 TorchNPU 易于开发、审查和维护。
6. **门禁检查**:运行 CI 检查,确保代码通过编译、静态检查、UT 测试
7. **提交 Pull Request**:提交 PR 并等待代码审查
8. **社区评审**:如果涉及 patch、头文件宏、API 接口等更新,需提交社区评审
### 代码合入评审要求
以下类型的修改需要社区评审:
- **Patch 替换**:对 PyTorch 原生接口的 patch 替换
- **头文件宏更新**:新增或修改宏定义
- **API 接口变更**:新增、修改或删除公共 API
- **核心组件变更**:内存管理、设备管理等核心模块的修改
## 代码规范
请遵循这些风格,使 TorchNPU 易于开发、审查和维护。
### 编码指南
#### 编码指南
- **Python**:建议使用 [PEP 8 编码样式](https://pep8.org/)
- **C++**:建议使用 [Google C++ 编码指南](http://google.github.io/styleguide/cppguide.html)
执行代码检查,可参照[本地静态检查](#本地静态检查)。
### 单元测试指南
- **Python**:建议使用 [pytest](http://pytest.org/en/latest/)
- **C++**:建议使用 [Googletest Primer](https://github.com/google/googletest/blob/master/docs/primer.md)
测试用例的设计意图应该通过它的注释名称来反映。
### 重构指南
#### 重构指南
我们鼓励开发人员重构代码以消除代码异味。所有的代码都应该符合编码风格和测试风格的需求。
## 实操指南
#### 环境搭建
### 环境搭建与编译
详细的安装指导(包括各版本依赖、环境要求等)请参考[昇腾社区安装指南](https://www.hiascend.com/document/detail/zh/Pytorch/master/installguide/ref/docs/zh/installation_guide/references/building_from_source.md)。
**编译构建**:
快速构建命令:
```bash
# 安装依赖并编译(未指定 --torch 时,使用环境中已安装的 PyTorch 版本)
# 安装依赖并编译
bash ci/build.sh --python=3.10
# 针对指定的 PyTorch 版本构建(支持 2.13 及以上,可用版本以 version.txt 为准)
@@ -182,19 +188,162 @@ cmake ..
make -j$(nproc)
```
### 编译加速技巧
如需加快编译速度,项目已内置 Ninja、Mold 链接器、CCache 的自动检测逻辑,使用方法请参见[编译加速](docs/zh/installation_guide/references/build_acceleration.md)。
使用 Ninja、Mold、CCache 和仅编译所需目标的方法,请参见[编译加速](docs/zh/installation_guide/references/build_acceleration.md)。
### 第六步:本地静态检查
### 使用Clang编译
完成代码开发后,请在本地运行静态检查,确保代码风格和质量符合要求。详细操作请参考 [附录 A:本地静态检查](#附录-a本地静态检查)。
使用 Clang 进行编译的方法,请参见[使用Clang编译](docs/zh/installation_guide/references/building_with_clang.md)。
### 使用 Clang 编译
### 本地静态检查
使用 Clang 进行编译的方法,请参见[使用 Clang 编译](docs/zh/installation_guide/references/building_with_clang.md)。
### 第七步:本地功能验证
请编写并运行单元测试,确保代码功能正确。如有新增功能,需同步新增对应的测试用例。详细操作请参考 [附录 B:单元测试与功能验证](#附录-b单元测试与功能验证)。
### 第八步:提交 Pull Request
1. **推送代码到远程仓库**:
```bash
git add .
git status
git commit -m "feat(module): 简要描述变更内容"
git commit -s --amend # 添加详细描述
git push origin {new_branch_name}
```
> **说明**:一个 PR 对应一个提交是本项目的推荐做法。若开发过程中产生了多个增量提交,请在推送前使用 `git rebase -i` 将它们压缩为单个提交,保持提交历史清晰。
2. **创建 Pull Request**
在 GitCode 上创建 Pull Request,根据 [PR 模板](./.gitcode/PULL_REQUEST_TEMPLATE.md) 完整填写:
- 合入来源
- 修改方案
- 资料变更
- 接口变更
- 功能验证
- CheckList
确认信息完整准确后提交 Pull Request,等待代码审查。
### 第九步:触发门禁检查
提交 PR 后,在 PR 评论区输入 `compile` 即可触发门禁检查。更多 Bot 命令说明请参考 [Ascend 社区 Bot 使用指南](https://gitcode.com/Ascend/infrastructure/blob/master/docs/robot/robot%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97.md)。
门禁异常主要包含如下几种,请根据相关提示解决:
- **编译异常**:请检查代码编译失败的原因,解决问题后重新编译
- **静态检查异常**:请依照提示查找代码中的问题并解决(如代码风格、潜在 Bug 等)
- **UT 测试未通过**:请根据提示查找测试用例不通过项并检查原因
### 第十步:代码审查与合入
#### PR 合入要求
**合入检查清单**(详细要求参考 [PR 模板](./.gitcode/PULL_REQUEST_TEMPLATE.md)):
- [ ] 代码编译通过
- [ ] 静态检查通过(CppLint、CppCheck 等)
- [ ] UT 测试用例通过
- [ ] 代码风格符合规范(PEP 8、Google C++ Style)
- [ ] 提交信息规范(符合 Conventional Commits)
- [ ] PR 标题正确使用类型标签(feat、fix、refactor、docs、test 等)
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
#### 代码审查流程
1. **Reviewer 审查**:对应模块的 reviewer 审查代码后,在 PR 评论区输入 `/lgtm` 表示认可
2. **Committer 审批**:对应模块的 committer 审查通过后,在 PR 评论区输入 `/approve` 表示同意合入
3. **自动合入**:PR 满足合入条件后,机器人会自动合入代码
> **提示**:完整的 reviewer 和 committer 名单可以在 PR 的第一条评论中点击对应链接查看。
## 进阶指南
### AI 辅助研发
TorchNPU 项目鼓励使用 AI 辅助研发与文档开发,以提升贡献效率。我们提供了昇腾官方的 agent-skills 仓库,其中包含一系列适用于昇腾生态的 AI Agent Skill 配置,可帮助您在开发中更好地利用 AI 编码助手。
- **agent-skills 仓库**:[https://gitcode.com/Ascend/agent-skills](https://gitcode.com/Ascend/agent-skills)
- 该仓库提供了昇腾芯片场景下常用的 Skill 模板和工具,可用于代码生成、问题诊断、性能分析等场景。
- 仓库中的 skills 持续更新中,同时欢迎贡献新的 Skill 或对现有 Skill 提出改进建议。
使用 AI 辅助研发时请注意:
- AI 生成的代码仍需人工审查,确保代码质量、安全性和正确性。
- 遵循项目的[编码指南](#第五步代码开发)和[附录 B:单元测试与功能验证](#附录-b单元测试与功能验证)。
- 提交的代码需通过门禁检查(编译、静态检查、UT 测试等)。
### 文档开发说明
#### 文档承载方式
本项目的文档采用 Markdown 格式,存放于仓库的 `docs/zh/` 目录下,随代码一同托管在 GitCode 平台。
> **注意**:文档承载在长稳版本的分支中,如 `v2.7.1`。如果您需要查看或修改文档,请切换到对应的长稳版本分支进行操作。
文档主要包含以下类目:
- **安装指南**(`installation_guide/`):环境准备、源码编译、pip 安装等说明。
- **快速入门**(`quick_start/`):快速上手教程。
- **原生 API 文档**(`native_apis/`):各版本 TorchNPU 原生 API 支持情况。
- **框架特性指南**(`framework_feature_guide_pytorch/`):NPU 图模式、Inductor、内存优化等特性说明。
- **环境变量参考**(`environment_variable_reference/`):NPU 相关环境变量说明。
- **故障排除**(`troubleshooting/`):常见问题及错误码分析。
- **安全声明**(`SECURITYNOTE.md`):安全相关说明。
- **贡献指南**(`CONTRIBUTING.md`):本文档。
#### 如何提交文档
文档的提交流程与代码提交一致,请参考[贡献流程](#贡献流程):
1. Fork 仓库并在本地创建分支。
2. 在 `docs/zh/` 目录下新增或修改对应的 Markdown 文件。
3. 编写文档时注意:
- 使用清晰、准确的中文表述。
- 代码示例需确保可运行。
- 遵循现有文档的格式和风格。
4. 提交 Pull Request,并在 PR 描述中说明文档变更内容。
#### CI 文档检查
提交文档的 Pull Request 后,CI 门禁会自动对变更的 Markdown 文件进行以下检查:
- **换行符检查(NEWLINE)**:确保文件末尾有且仅有一个换行符,且文件不包含多余的空行。
- **尾随空格检查(SPACES)**:确保每行末尾没有多余的空格。
- **制表符检查(TABS)**:确保文件中使用空格缩进而非制表符(Tab)。
- **拼写检查(CODESPELL)**:通过 codespell 工具检查英文拼写错误。
## 社区准则
### 行为准则
我们致力于为所有参与者提供一个友好、安全、包容的环境:
- **尊重差异**:尊重不同的观点和经验,包容多元文化
- **开放心态**:接受建设性的批评,持续学习和进步
- **聚焦贡献**:关注对社区最有利的事情,推动项目发展
- **同理心**:对其他社区成员表示同理心,互帮互助
## 问题咨询
我们热烈欢迎每一位开发者积极参与社区讨论!期待与您共同成长:
- **发现未解决的问题**:欢迎在 Issue 中发表评论,展示您的解决方案
- **遇到长期未处理的问题**:建议在解决前进行预检查,避免重复工作
- **成功解决了自己报告的问题**:也请分享您的解决方案,让社区一起学习和进步
有任何疑问,随时欢迎在社区中交流讨论,期待您的精彩贡献!
## 附录 A:本地静态检查
项目使用 [lintrunner](https://github.com/suo/lintrunner) 进行静态检查,支持在本地运行与 CI 完全一致的检查项,包括 Python 代码风格(Flake8、Ruff、PYFMT)、C++ 格式(ClangFormat、ClangTidy)、拼写检查(Codespell)等。
#### 安装依赖
### 安装依赖
```bash
# 安装 lintrunner 及 uv(部分 linter 需要)
@@ -202,14 +351,14 @@ pip install lintrunner
pip install uv
```
#### 初始化(首次使用或更新时执行一次)
### 初始化(首次使用或更新时执行一次)
```bash
# 下载 lintrunner 所需的外部二进制工具(clang-format、clang-tidy 等)
lintrunner init
```
#### 执行静态检查
### 执行静态检查
```bash
# 检查当前工作区改动和HEAD提交的文件增量(工作区 + HEAD)
@@ -218,7 +367,7 @@ lintrunner
# 仅运行指定检查项
lintrunner --take FLAKE8,RUFF,PYFMT,SPACES,TABS,NEWLINE
# 自动修复可自动修复的问题(formatter 类 linter, 如忽略PYREFLY)
# 自动修复可自动修复的问题(formatter 类 linter,如需忽略 PYREFLY)
lintrunner --skip PYREFLY -a
# 仅检查当前工作区改动的文件增量
@@ -241,18 +390,14 @@ git diff --name-only HEAD | xargs lintrunner
更多执行命令可参照[lintrunner wiki](https://github.com/pytorch/pytorch/wiki/lintrunner)。
### PR 合入要求
## 附录 B:单元测试与功能验证
**合入检查清单**(详细要求参考 [PR 模板](./.gitcode/PULL_REQUEST_TEMPLATE.md)):
### 单元测试指南
- [ ] 代码编译通过
- [ ] 静态检查通过(CppLint、CppCheck 等)
- [ ] UT 测试用例通过
- [ ] 代码风格符合规范(PEP 8、Google C++ Style)
- [ ] 提交信息规范(符合 Conventional Commits)
- [ ] PR 标题正确使用类型标签(feat、fix、refactor、docs、test 等)
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- **Python**:建议使用 [pytest](http://pytest.org/en/latest/)
- **C++**:建议使用 [Googletest Primer](https://github.com/google/googletest/blob/main/docs/primer.md)
测试用例的设计意图应该通过它的注释名称来反映。
### 功能验证指导
@@ -286,118 +431,3 @@ python test_autocast.py -v -k test_autocast_nn_fp32
cd ..
python ci/access_control_test.py --all
```
### 门禁异常处理
门禁异常主要包含如下几种,请根据相关提示解决:
- **编译异常**:请检查代码编译失败的原因,解决问题后重新编译
- **静态检查异常**:请依照提示查找代码中的问题并解决(如代码风格、潜在 Bug 等)
- **UT 测试未通过**:请根据提示查找测试用例不通过项并检查原因
### AI辅助研发
TorchNPU 项目鼓励使用 AI 辅助研发与文档开发,以提升贡献效率。我们提供了昇腾官方的 agent-skills 仓库,其中包含一系列适用于昇腾生态的 AI Agent Skill 配置,可帮助您在开发中更好地利用 AI 编码助手。
- **agent-skills 仓库**:[https://gitcode.com/Ascend/agent-skills](https://gitcode.com/Ascend/agent-skills)
- 该仓库提供了昇腾芯片场景下常用的 Skill 模板和工具,可用于代码生成、问题诊断、性能分析等场景。
- 仓库中的 skills 持续更新中,同时欢迎贡献新的 Skill 或对现有 Skill 提出改进建议。
使用 AI 辅助研发时请注意:
- AI 生成的代码仍需人工审查,确保代码质量、安全性和正确性。
- 遵循项目的[代码规范](#代码规范)和[单元测试指南](#单元测试指南)。
- 提交的代码需通过门禁检查(编译、静态检查、UT 测试等)。
### 文档开发说明
#### 文档承载方式
本项目的文档采用 Markdown 格式,存放于仓库的 `docs/zh/` 目录下,随代码一同托管在 GitCode 平台。
> **注意**:文档承载在长稳版本的分支中,如 `v2.7.1`。如果您需要查看或修改文档,请切换到对应的长稳版本分支进行操作。
文档主要包含以下类目:
- **安装指南**(`installation_guide/`):环境准备、源码编译、pip 安装等说明。
- **快速入门**(`quick_start/`):快速上手教程。
- **原生 API 文档**(`native_apis/`):各版本 PyTorch 原生 API 支持情况。
- **框架特性指南**(`framework_feature_guide_pytorch/`):NPU 图模式、Inductor、内存优化等特性说明。
- **环境变量参考**(`environment_variable_reference/`):NPU 相关环境变量说明。
- **故障排除**(`troubleshooting/`):常见问题及错误码分析。
- **安全声明**(`SECURITYNOTE.md`):安全相关说明。
- **贡献指南**(`CONTRIBUTING.md`):本文档。
#### 如何提交文档
文档的提交流程与代码提交一致,请参考[贡献流程](#贡献流程):
1. Fork 仓库并在本地创建分支。
2. 在 `docs/zh/` 目录下新增或修改对应的 Markdown 文件。
3. 编写文档时注意:
- 使用清晰、准确的中文表述。
- 代码示例需确保可运行。
- 遵循现有文档的格式和风格。
4. 提交 Pull Request,并在 PR 描述中说明文档变更内容。
#### CI 文档检查
提交文档的 Pull Request 后,CI 门禁会自动对变更的 Markdown 文件进行以下检查:
- **换行符检查(NEWLINE)**:确保文件末尾有且仅有一个换行符,且文件不包含多余的空行。
- **尾随空格检查(SPACES)**:确保每行末尾没有多余的空格。
- **制表符检查(TABS)**:确保文件中使用空格缩进而非制表符(Tab)。
- **拼写检查(CODESPELL)**:通过 codespell 工具检查英文拼写错误。
## 提交 Pull Request
1. **推送代码到远程仓库**:
```bash
git add .
git status
git commit -m "Your commit title"
git commit -s --amend # 添加详细描述
git push origin {new_branch_name}
```
2. **创建 Pull Request**
在 GitCode 上创建 Pull Request,根据 [PR 模板](./.gitcode/PULL_REQUEST_TEMPLATE.md) 完整填写:
- 合入来源
- 修改方案
- 资料变更
- 接口变更
- 功能验证
- CheckList
确认信息完整准确后提交 Pull Request,等待代码审查。
## 社区准则
### 行为准则
我们致力于为所有参与者提供一个友好、安全、包容的环境:
- **尊重差异**:尊重不同的观点和经验,包容多元文化
- **开放心态**:接受建设性的批评,持续学习和进步
- **聚焦贡献**:关注对社区最有利的事情,推动项目发展
- **同理心**:对其他社区成员表示同理心,互帮互助
### 沟通渠道
我们为您提供多种沟通渠道,方便您参与社区互动:
- **[Issues](https://gitcode.com/Ascend/pytorch/issues)**:用于报告 Bug、提出功能建议
- **[Pull Requests](https://gitcode.com/Ascend/pytorch/pulls)**:用于代码审查和讨论
### 问题咨询
我们热烈欢迎每一位开发者积极参与社区讨论!期待与您共同成长:
- **发现未解决的问题**:欢迎在 Issue 中发表评论,展示您的解决方案
- **遇到长期未处理的问题**:建议在解决前进行预检查,避免重复工作
- **成功解决了自己报告的问题**:也请分享您的解决方案,让社区一起学习和进步
有任何疑问,随时欢迎在社区中交流讨论,期待您的精彩贡献!