| ci: upgrade api-scan-action to v1.0.2 and unify Detect_file_changes image Co-authored-by: BOCHENGZHANG<zhangbocheng6@h-partners.com> # message auto-generated for no-merge-commit merge: !230 merge ci-api-scan-v102 into master ci: upgrade api-scan-action to v1.0.2 and unify Detect_file_changes image Created-by: BOCHENGZHANG Commit-by: BOCHENGZHANG Merged-by: ascend-robot Description: ## 修改原因 - API_SCAN 作业当前使用 openlibing/api-scan-action@v1.0.1,升级到 v1.0.2 以获取 action 的最新修复与改进。 - Detect_file_changes 作业镜像与 CodeCheck_pre_commit 统一,从 pytorch_images_x86/pytorchx86:v_03 换为 atlas-ci/common:latest,减少流水线使用的镜像数量。 ## 主要改动 .gitcode/workflows/pr-pipeline-mindspeed-ops.yml: - API_SCAN 作业的 action 版本从 v1.0.1 升级到 v1.0.2,其余配置不变。 - Detect_file_changes 作业容器镜像改为 swr.cn-north-4.myhuaweicloud.com/atlas-ci/common:latest,与 CodeCheck_pre_commit 一致;其余配置不变。 ## 用户可见影响 无。仅调整 CI 流水线配置,不影响仓库功能代码。 ## 测试方式 - 两项变更均已在 ComputingActionTest/MindSpeed-Ops master 分支落地(commit 9ea2be6、d6e8014),作为评论触发的真实验证基线。 - PR 更新后评论 compile 触发流水线,确认 Detect_file_changes 与 API_SCAN 作业在新配置下运行通过。 (CI 配置调整,沿用 !216 同类变更惯例,未建单独 Issue。) See merge request: Ascend/MindSpeed-Ops!230 | 12 days ago |
| feat(atb): add MatmulAdd operators for fused wgrad accumulation Co-authored-by: Liz<lizhi166@huawei.com> # message auto-generated for no-merge-commit merge: !182 merge master into master feat(atb): add MatmulAdd operators for fused wgrad accumulation Created-by: Liz_ Commit-by: Liz Merged-by: ascend-robot Description: ## What this PR does / why we need it? Megatron gradient accumulation updates the main weight-gradient buffer as grad += grad_output.T @ total_input. The previous decomposed path materializes an [N, K] intermediate and launches a separate add kernel, increasing allocation and memory traffic. This PR adapts the MindSpeed MatmulAdd implementation to MindSpeed-Ops and provides: - npu_matmul_add_fp32 for bf16/fp16 operands accumulated into an fp32 grad; it uses the ATB fused MatmulAdd path on A2/A3 and addmm_ on A5. - npu_matmul_add_fp16 for bf16/fp16 operands and a matching half-precision grad; it replaces matmul + add_ with one in-place addmm_ call. - zero-sized-input protection, chip dispatch, builder integration, public documentation, and expanded unit coverage. - reproducible ATK case definitions and execution plugin for accuracy, device performance, and device memory validation. Generated cases, reports, and logs stay ignored; the final result summary is retained at tests/atk_tests/atb/matmul_add/atk_output/console/SUMMARY.md. This is feature enablement, not a bug fix. Related issue: N/A. ## Does this PR introduce any user-facing change? Yes. NPU callers can import npu_matmul_add_fp32 or npu_matmul_add_fp16 from mindspeed_ops.api.atb.npu_matmul_add. Both APIs mutate grad in place and return None. Inputs must be 2-D tensors with shapes total_input=[M,K], grad_output=[M,N], and grad=[N,K]. Operand dtypes must match and be bf16 or fp16. The fp32 API requires an fp32 grad buffer; the fp16 API requires grad to match the operand dtype. Empty inputs are a no-op. Usage and benchmark documentation: docs/zh/atb/matmul_add.md. ATK reproduction guide: tests/atk_tests/atb/matmul_add/README.md. ## How was this patch tested? Unit test in the 018 environment: - conda activate lz_py312_018 - python -m pytest tests/unit_tests/atb/test_npu_matmul_add.py -q -rs - Result: 8 passed, 7 skipped. The skipped cases require cann-nnal/ATB and were skipped because ATB_HOME_PATH was not set in this environment. ATK 26.4.30 was run on Ascend 910B3 (A2) with CANN 9.0.0 + ATB, Python 3.10, torch 2.7.1, and torch_npu 2.7.1.post4. Each API used 8 cases covering {bf16, fp16} operands across four shape tuples. - Accuracy, NPU vs CPU high-precision reference: fp32 8/8 Pass; fp16 8/8 Pass. - Device performance, fused dev0 vs decomposed dev1: fp32 average ratio 1.3662 with 100% case pass rate; fp16 average ratio 1.0007 with 87.5% case pass rate and overall Pass. - Device memory, fused dev0 vs decomposed dev1: fp32 and fp16 both 8/8 Pass with 100% memory pass rate under the fused/reference <= 1.1 criterion. The A2/A3 fp32 path requires cann-nnal and ATB_HOME_PATH. Its first invocation JIT-builds the C++ extension and takes about 30 seconds; performance measurements must use warmed, cache-hit runs. The public APIs are Ascend NPU-specific and do not provide a CUDA fallback. [RFC](https://gitcode.com/Ascend/MindSpeed-Ops/issues/80) See merge request: Ascend/MindSpeed-Ops!182 | 1 month ago |
| feat: support catlass Co-authored-by: zhuweichen<calvin_zhu0210@outlook.com> # message auto-generated for no-merge-commit merge: !131 merge feat/catlass-build-support into master feat: support catlass Created-by: Pr0Wh1teGive Commit-by: zhuweichen Merged-by: ascend-robot Description: ## What this PR does / why we need it? This PR adds common build support for CATLASS operators in MindSpeed-Ops: Adds the opt-in switch MINDSPEED_BUILD_CATLASS=1. Automatically detects and normalizes the target SoC. Automatically downloads a pinned CATLASS revision, while supporting local source through CATLASS_SOURCE_DIR. Adds an isolated Bisheng build process and packages the generated shared libraries. Adds a private BF16 BasicMatmul operator to verify the CATLASS build and runtime path. This is a feature PR rather than a bugfix. ## Does this PR introduce any user-facing change? CATLASS compilation can now be enabled with: export MINDSPEED_BUILD_CATLASS=1 pip install -e . --no-build-isolation --no-deps The default build behavior is unchanged when the option is disabled. Documentation: README.md. ## How was this patch tested? Tested on Atlas A3 with CANN, PyTorch, and torch_npu: CATLASS kernel compilation and shared-library loading succeeded. BF16 128 × 128 BasicMatmul was compared with torch.matmul. The observed maximum absolute error was 0. The regular build without CATLASS enabled was also verified. Limitations: the smoke operator only supports contiguous BF16 2D inputs, with M/N/K aligned to 16. See merge request: Ascend/MindSpeed-Ops!131 | 2 months ago |
| docs: 合入英文 Co-authored-by: f60123591<fanghui49@h-partners.com> Co-authored-by: EliasKaslan<eliaskaslan@outlook.com> # message auto-generated for no-merge-commit merge: !239 merge master into master docs: 合入英文 Created-by: chic666 Commit-by: chic666;EliasKaslan;f60123591 Merged-by: ascend-robot Description: [#98](https://gitcode.com/Ascend/MindSpeed-Ops/issues/98) ## What this PR does / why we need it? 合入英文 ## Does this PR introduce any user-facing change? 合入英文 ## How was this patch tested? CI PASSED See merge request: Ascend/MindSpeed-Ops!239 | 2 days ago |
| docs: 合入英文 Co-authored-by: f60123591<fanghui49@h-partners.com> Co-authored-by: EliasKaslan<eliaskaslan@outlook.com> # message auto-generated for no-merge-commit merge: !239 merge master into master docs: 合入英文 Created-by: chic666 Commit-by: chic666;EliasKaslan;f60123591 Merged-by: ascend-robot Description: [#98](https://gitcode.com/Ascend/MindSpeed-Ops/issues/98) ## What this PR does / why we need it? 合入英文 ## Does this PR introduce any user-facing change? 合入英文 ## How was this patch tested? CI PASSED See merge request: Ascend/MindSpeed-Ops!239 | 2 days ago |
| docs: 合入英文 Co-authored-by: f60123591<fanghui49@h-partners.com> Co-authored-by: EliasKaslan<eliaskaslan@outlook.com> # message auto-generated for no-merge-commit merge: !239 merge master into master docs: 合入英文 Created-by: chic666 Commit-by: chic666;EliasKaslan;f60123591 Merged-by: ascend-robot Description: [#98](https://gitcode.com/Ascend/MindSpeed-Ops/issues/98) ## What this PR does / why we need it? 合入英文 ## Does this PR introduce any user-facing change? 合入英文 ## How was this patch tested? CI PASSED See merge request: Ascend/MindSpeed-Ops!239 | 2 days ago |
| feat: 新增gitleaks敏感信息检测 Co-authored-by: wujinyuan1<wujinyuan1@huawei.com> # message auto-generated for no-merge-commit merge: !81 merge master into master feat: 新增gitleaks敏感信息检测 Created-by: wujinyuan1 Commit-by: wujinyuan1 Merged-by: ascend-robot Description: ## What this PR does / why we need it? 1. 引入gitleaks二进制离线扫描工具 2. 新增pre-commit/.gitleaks.toml配置,继承官方全部检测规则 3. 配置pre-commit钩子,提交前自动扫描密钥硬编码风险。 ## Does this PR introduce any user-facing change? 无. ## How was this patch tested? PR流水线pre-commit检测新增敏感信息检测. See merge request: Ascend/MindSpeed-Ops!81 | 4 months ago |
| feat(triton): add chunk_gated_delta_rule_fwd_kkt_solve Co-authored-by: gcw_K5CvmS79<18042662766@163.com> # message auto-generated for no-merge-commit merge: !135 merge feature/chunk_gated_delta_rule_fwd_kkt_solve_kernel into master feat(triton): add chunk_gated_delta_rule_fwd_kkt_solve Created-by: gcw_K5CvmS79 Commit-by: gcw_K5CvmS79 Merged-by: ascend-robot Description: issue: https://gitcode.com/Ascend/MindSpeed-Ops/issues/55 ## What this PR does / why we need it? 迁移并优化 fla-org/flash-linear-attention 的 chunk_gated_delta_rule_fwd_kkt_solve_kernel 到 MindSpeed-Ops(triton-ascend, arch32)。新增独立融合算子 chunk_gated_delta_rule_fwd_kkt_solve,一条调用等价于 solve_tril(chunk_scaled_dot_kkt_fwd(...)) 两步路径:保留官方 kkt 构造与 16×16 前代两个 kernel,将官方的两级 merge(16→32→64)+ 输出 torch.zeros 预清零压缩为**单个merge kernel**,消除 32×32 中间张量的 HBM 往返与两次清零开销。 **交付件(5 处,纯新增):** - mindspeed_ops/arch32/triton/gdn/chunk_gated_delta_rule_fwd_kkt_solve.py:自研 merge kernel + arch32 wrapper - mindspeed_ops/api/triton/chunk_gated_delta_rule_fwd_kkt_solve.py:公开 API - tests/unit_tests/triton/test_chunk_gated_delta_rule_fwd_kkt_solve.py:UT 53 项 - tests/atk_tests/triton/chunk_gated_delta_rule_fwd_kkt_solve/:ATK 三件套(yaml + generate + runner) - docs/triton/chunk_gated_delta_rule_fwd_kkt_solve.md:算子文档 **性能(910B/Atlas 800T A2, bf16, msprof 设备侧 kernel 时间,vs 仓内两算子调用):** | shape (B,T,H,K) | 两算子 ms/iter | 融合 ms/iter | 加速比 | |---|---|---|---| | (1, 256, 8, 128) | 0.1144 | 0.0982 | 1.165 | | (1, 512, 8, 128) | 0.1330 | 0.1104 | 1.204 | | (1, 1024, 8, 128) | 0.1515 | 0.1249 | 1.213 | | (1, 2048, 8, 128) | 0.1865 | 0.1543 | 1.208 | | (2, 2048, 4, 128) | 0.1951 | 0.1656 | 1.178 | | (1, 4096, 4, 128) | 0.1946 | 0.1656 | 1.175 | | (1, 8192, 2, 128) | 0.1970 | 0.1610 | 1.224 | | (1, 8192, 4, 128) | 0.2564 | 0.2247 | 1.141 | | (1, 8192, 8, 128) | 0.4318 | 0.3593 | 1.202 | | (1, 8192, 16, 128) | 0.7139 | 0.6365 | 1.122 | | (1, 16384, 8, 128) | 0.7136 | 0.6113 | 1.167 | | (2, 16384, 16, 128)| 2.5123 | 2.2771 | 1.103 | | (2, 16384, 32, 128)| 4.8985 | 4.9368 | 0.992 | 12/13 shape ≥ 1.1x,几何平均 ~1.16。最大极端 shape (2,16384,32,128) 与两算子持平:H=32 大行跨距下 merge 访存为硬件极限(官方双 merge 同样受限)。 **精度:** 与未融合两算子链**位级一致**(13 基准 + 10 泛化 shape 全部 mismatch=0%,含 T 非 64 倍数、B>1、奇数头数);与 CPU fp32/fp64 参考 mean_rel ≤ 1.4e-7,远优于 0.1% 要求。 ## Does this PR introduce any user-facing change? 新增公开 API(纯新增,不改任何现有行为,完全向后兼容): python from mindspeed_ops.api.triton.chunk_gated_delta_rule_fwd_kkt_solve import chunk_gated_delta_rule_fwd_kkt_solve A = chunk_gated_delta_rule_fwd_kkt_solve( k, g=None, beta=None, cu_seqlens=None, chunk_size=64, output_dtype=None ) # k: [B,T,H,K] → A: (I+A)^{-1} [B,T,H,64] - chunk_size=64(kernel 硬编码 4 个 BC=16 子块)与 cu_seqlens=None(定长)走融合路径;其他配置自动回退未融合链,行为不变 ## How was this patch tested? **UT(53 项,NPU 实跑全过,golden 为 CPU 小算子基准):** fp32/bf16/fp16 × 9 shape(含 B=2、partial last chunk、NT 奇偶边界、长序列)、±g/±beta、varlen(cu_seqlens 拆段交叉验证)、与仓内未融合链逐位交叉验证、chunk_size≠64 回退路径。 **ATK:** accuracy 60 case Pass(single_bm,CPU golden);performance_device 60 case Pass。   **复现命令:** bash cd tests/atk_tests/triton/chunk_gated_delta_rule_fwd_kkt_solve atk case -f chunk_gated_delta_rule_fwd_kkt_solve.yaml -p generate_chunk_gated_delta_rule_fwd_kkt_solve.py atk node --backend triton --devices 0 node --backend cpu --devices 0 task \ -c result/chunk_gated_delta_rule_fwd_kkt_solve/json/all_chunk_gated_delta_rule_fwd_kkt_solve.json \ --task accuracy -p triton_chunk_gated_delta_rule_fwd_kkt_solve.py **性能复现:** msprof --application=... 后读 op_summary_*.csv 的 Task Duration(us),对两算子调用与融合 API 分别累计全部 NPU kernel 时间。 **使用约束:** 融合路径仅 arch32、chunk_size=64、定长输入;其余自动回退未融合链。 See merge request: Ascend/MindSpeed-Ops!135 | 10 days ago |
| docs: 优化文档,删除多余空格,修改英文标点,torch_npu修改为TorchNPU,有序列表刷新为无序列表等 Co-authored-by: f60123591<fanghui49@h-partners.com> # message auto-generated for no-merge-commit merge: !204 merge master into master docs: 优化文档,删除多余空格,修改英文标点,torch_npu修改为TorchNPU,有序列表刷新为无序列表等 Created-by: chic666 Commit-by: f60123591 Merged-by: ascend-robot Description: [#90](https://gitcode.com/Ascend/MindSpeed-Ops/issues/90) ## What this PR does / why we need it? docs: 优化文档,删除多余空格,修改英文标点,torch_npu修改为TorchNPU,有序列表刷新为无序列表等 ## Does this PR introduce any user-facing change? 不涉及 ## How was this patch tested? CI PASSED See merge request: Ascend/MindSpeed-Ops!204 | 25 days ago |
| 【feat】修改完善pre-commit配置文件 Co-authored-by: wujinyuan1<wujinyuan1@huawei.com> | 5 months ago |
| feat(atb): add MatmulAdd operators for fused wgrad accumulation Co-authored-by: Liz<lizhi166@huawei.com> # message auto-generated for no-merge-commit merge: !182 merge master into master feat(atb): add MatmulAdd operators for fused wgrad accumulation Created-by: Liz_ Commit-by: Liz Merged-by: ascend-robot Description: ## What this PR does / why we need it? Megatron gradient accumulation updates the main weight-gradient buffer as grad += grad_output.T @ total_input. The previous decomposed path materializes an [N, K] intermediate and launches a separate add kernel, increasing allocation and memory traffic. This PR adapts the MindSpeed MatmulAdd implementation to MindSpeed-Ops and provides: - npu_matmul_add_fp32 for bf16/fp16 operands accumulated into an fp32 grad; it uses the ATB fused MatmulAdd path on A2/A3 and addmm_ on A5. - npu_matmul_add_fp16 for bf16/fp16 operands and a matching half-precision grad; it replaces matmul + add_ with one in-place addmm_ call. - zero-sized-input protection, chip dispatch, builder integration, public documentation, and expanded unit coverage. - reproducible ATK case definitions and execution plugin for accuracy, device performance, and device memory validation. Generated cases, reports, and logs stay ignored; the final result summary is retained at tests/atk_tests/atb/matmul_add/atk_output/console/SUMMARY.md. This is feature enablement, not a bug fix. Related issue: N/A. ## Does this PR introduce any user-facing change? Yes. NPU callers can import npu_matmul_add_fp32 or npu_matmul_add_fp16 from mindspeed_ops.api.atb.npu_matmul_add. Both APIs mutate grad in place and return None. Inputs must be 2-D tensors with shapes total_input=[M,K], grad_output=[M,N], and grad=[N,K]. Operand dtypes must match and be bf16 or fp16. The fp32 API requires an fp32 grad buffer; the fp16 API requires grad to match the operand dtype. Empty inputs are a no-op. Usage and benchmark documentation: docs/zh/atb/matmul_add.md. ATK reproduction guide: tests/atk_tests/atb/matmul_add/README.md. ## How was this patch tested? Unit test in the 018 environment: - conda activate lz_py312_018 - python -m pytest tests/unit_tests/atb/test_npu_matmul_add.py -q -rs - Result: 8 passed, 7 skipped. The skipped cases require cann-nnal/ATB and were skipped because ATB_HOME_PATH was not set in this environment. ATK 26.4.30 was run on Ascend 910B3 (A2) with CANN 9.0.0 + ATB, Python 3.10, torch 2.7.1, and torch_npu 2.7.1.post4. Each API used 8 cases covering {bf16, fp16} operands across four shape tuples. - Accuracy, NPU vs CPU high-precision reference: fp32 8/8 Pass; fp16 8/8 Pass. - Device performance, fused dev0 vs decomposed dev1: fp32 average ratio 1.3662 with 100% case pass rate; fp16 average ratio 1.0007 with 87.5% case pass rate and overall Pass. - Device memory, fused dev0 vs decomposed dev1: fp32 and fp16 both 8/8 Pass with 100% memory pass rate under the fused/reference <= 1.1 criterion. The A2/A3 fp32 path requires cann-nnal and ATB_HOME_PATH. Its first invocation JIT-builds the C++ extension and takes about 30 seconds; performance measurements must use warmed, cache-hit runs. The public APIs are Ascend NPU-specific and do not provide a CUDA fallback. [RFC](https://gitcode.com/Ascend/MindSpeed-Ops/issues/80) See merge request: Ascend/MindSpeed-Ops!182 | 1 month ago |
| feature: 引入 markdownlint 做文档语法检查,清理存量问题 Co-authored-by: wangjiangben<wangjiangben@huawei.com> # message auto-generated for no-merge-commit merge: !150 merge master into master feature: 引入 markdownlint 做文档语法检查,清理存量问题 Created-by: wangjiangben Commit-by: wangjiangben Merged-by: ascend-robot Description: # feature: 引入 markdownlint 做文档语法检查,清理存量问题 ## 概述 为仓库引入 **markdownlint-cli**(pre-commit 集成)做 Markdown 语法检查,并一次性清理存量问题,npx markdownlint-cli --config .markdownlint.yaml "**/*.md" 现为 0 issues。 裁剪了与中文正文、原生 HTML、多阶段标题冲突的风格规则,只保留真语法/结构检查;配置文件 .markdownlint.yaml 可被 VS Code markdownlint 扩展直接读取,本地编辑即时提示。 ## 变更清单 ### 新增 | 文件 | 说明 | |------|------| | .markdownlint.yaml | lint 配置:默认规则 + 规则裁剪 | | .markdownlintignore | 忽略清单(node_modules、.npm-cache、docs/zh/_menu.md) | ### 修改 | 文件 | 说明 | |------|------| | .pre-commit-config.yaml | 新增 markdownlint hook(rev v0.47.0) | | README.md | 失效锚点 #版本配套表 → #版本说明;补表格尾竖线 | | docs/zh/install_guide.md | 非描述性链接 [Link] → [TorchNPU插件版本] | | docs/zh/introduction.md | 图片补 alt | | ci/CI_GUID.md 及 docs/zh/**、tests/unit_tests/README.md、tools/skills/** 共 12 个 md | --fix 空行/列表标记/裸链接清理 | | tools/skills/operator-performance-profile/SKILL.md | 修复 130+ 处 emoji 乱码、14 处内联代码块、front matter 未转义引号 | ## 规则裁剪 | 关闭的规则 | 原因 | |------|------| | MD013 行宽 | 中文 + 宽表格 | | MD025 | 手册型文档多 H1 | | MD033 | <term>/<table> 原生 HTML | | MD036 | **表 1** 加粗题注 | | MD040 | shell/text 代码块未标注语言 | | MD060 | 表格 compact 风格不强制对齐 | | MD024(放宽 siblings_only) | 允许不同章节同名标题 | 保留语法关键规则:MD011/MD034/MD042/MD051(链接)、MD022/MD031/MD032(空行包裹)、MD009/MD047(尾随空格/末尾换行)、MD012/MD007/MD029/MD030(空行/列表)等。 ## 验证 bash npx markdownlint-cli --config .markdownlint.yaml "**/*.md" # 结果:0 issues 基线从约 1600 条违规收敛到 0:关闭风格类规则 → 约 230 条结构类问题,--fix 清约 230 处,手工修 4 处语义问题,重写 SKILL.md 乱码,最终归零。 ## 相关 - RFC:[[RFC]: MindSpeed-Ops 引入 markdownlint 做文档语法检查](https://gitcode.com/Ascend/MindSpeed-Ops/issues/64) See merge request: Ascend/MindSpeed-Ops!150 | 1 month ago |
| docs: 合入英文 Co-authored-by: f60123591<fanghui49@h-partners.com> Co-authored-by: EliasKaslan<eliaskaslan@outlook.com> # message auto-generated for no-merge-commit merge: !239 merge master into master docs: 合入英文 Created-by: chic666 Commit-by: chic666;EliasKaslan;f60123591 Merged-by: ascend-robot Description: [#98](https://gitcode.com/Ascend/MindSpeed-Ops/issues/98) ## What this PR does / why we need it? 合入英文 ## Does this PR introduce any user-facing change? 合入英文 ## How was this patch tested? CI PASSED See merge request: Ascend/MindSpeed-Ops!239 | 2 days ago |
| ci: add GitCode PR pipeline Co-authored-by: BOCHENGZHANG<zhangbocheng6@h-partners.com> # message auto-generated for no-merge-commit merge: !154 merge master into master ci: add GitCode PR pipeline Created-by: BOCHENGZHANG Commit-by: BOCHENGZHANG Merged-by: ascend-robot Description: ## What this PR does / why we need it? Add a repository-specific GitCode PR pipeline based on the current MindSpeed-Ops CodeArts configuration. - Add CodeCheck and changed-file detection. - Add four sharded MindSpeed-Ops UT jobs using the confirmed Runner labels, container image, and existing CI entry script. - Support PR open/update/reopen events and the exact compile comment trigger for master and 26.1.0. - Add the Bandit TOML dependency required by the existing pre-commit configuration. ## Does this PR introduce any user-facing change? No. This change only adds GitCode CI configuration. ## How was this patch tested? The workflow was deployed to ComputingActionTest/MindSpeed-Ops and exercised through a validation PR. Trigger routing, Runner selection, container startup, merge-ref checkout, and UT entry-script execution were verified. The YAML diff and whitespace checks also passed locally. See merge request: Ascend/MindSpeed-Ops!154 | 1 month ago |
| feat: Add add_rms_norm_bias compiletion Co-authored-by: Liccol<740821011@qq.com> # message auto-generated for no-merge-commit merge: !54 merge aclnn-case into master feat: Add add_rms_norm_bias compiletion Created-by: Liccol Commit-by: Liccol Merged-by: ascend-robot Description: ## What this PR does / why we need it? 新增 add_rms_norm_bias 自定义 ACLNN 算子,将逐元素加法(Add)与 RMS 归一化合并为单个 AscendC Kernel 执行,用于 Transformer 模型推理中残差连接 + RMSNorm 的融合优化。 主要变更: - 新增 add_rms_norm_bias 算子源码 - 新增 cann/ 下的 ACLNN 绑定及 torch_binding 算子注册 - 新增 Python 调用接口(api/aclnn/)及 JIT 构建器(op_builder/) - 引入 cmake/common/scripts/utils 等编译工具链及公共组件 - 新增算子使用文档及开发指南(docs/aclnn/) ## Does this PR introduce any user-facing change? 是,新增 npu_add_rms_norm_bias 接口 ## How was this patch tested? 通过单元测试与 CPU 参考实现对比验证: - 对比分离执行 Add + RMSNorm 与融合算子的数值精度 - 覆盖 float32 / float16 / bfloat16 三种数据类型 - 覆盖有 beta / 无 beta 两种场景  See merge request: Ascend/MindSpeed-Ops!54 | 4 months ago |
| fix: 商发wheel安全编译扫描整改(rpath/RELRO/栈保护/strip) Co-authored-by: Raining__<wangruining5@huawei.com> # message auto-generated for no-merge-commit merge: !173 merge master into master fix: 商发wheel安全编译扫描整改(rpath/RELRO/栈保护/strip) Created-by: Raining__ Commit-by: Raining__ Merged-by: ascend-robot Description: ## 背景 商发 wheel 包华为安全编译扫描整改。本 PR 修复扫描命中的 4 类问题,覆盖 wheel 内全部 host 侧 ELF 产物(pybind 扩展 + CATLASS 子库 + 设备 kernel .o)。设备 kernel .o 的 PIE/RELRO/栈保护/FS/strip 项因 CANN 设备二进制格式所限不适用,单独走豁免说明。 ## 修改明细 ### 1. 禁止 rpath(c781b17,另含 037ba4c+a57dfd5 的 kernel 侧修复) - mindspeed_ops/csrc/CMakeLists.txt:OPS_COMPILE_OPTIONS 追加 -fno-rtlib-add-rpath,消除 ccec 驱动默认 -frtlib-add-rpath 给设备 kernel .o 写入的 DT_RPATH - CMakeLists.txt:删除 mindspeed_ops_C 的 BUILD_RPATH/INSTALL_RPATH "$ORIGIN:$ORIGIN/lib" - mindspeed_ops/csrc/catlass/{basic_matmul,chunk_loss}/CMakeLists.txt:删除 INSTALL_RPATH "$ORIGIN" - mindspeed_ops/__init__.py:新增 _preload_catlass_libraries()(置于引导序列首位)——以绝对路径 ctypes.CDLL(..., RTLD_GLOBAL) 预载 mindspeed_ops/lib/*.so,利用 SONAME 注册机制使扩展的 NEEDED 依赖在不带 RPATH 的情况下正常解析,功能与原 $ORIGIN/lib RPATH 等价;与文件内既有 _preload_custom_opapi_library 同一模式,CATLASS 未使能(无 lib/ 目录)时为空操作 ### 2. GOT 重定位只读 (全 RELRO)与立即绑定(BIND_NOW)(39354c4、0706d44) - CMakeLists.txt:mindspeed_ops_C 追加链接选项 -Wl,-z,relro,-z,now - 两个 CATLASS 子库 target_link_options 追加 -Wl,-z,relro,-z,now(bisheng 默认仅 -z relro 部分 RELRO,补 -z now 到全 RELRO) - 验证:产物均出现 GNU_RELRO 段 + DT_BIND_NOW + FLAGS_1 NOW ### 3. 栈保护(3de5382) - CMakeLists.txt:mindspeed_ops_C 追加编译选项 -fstack-protector-all(选 -all 而非 -strong,确保所有函数插桩、确定性产生 __stack_chk_fail 引用) - 验证:产物动态符号表出现 __stack_chk_fail@GLIBC_2.4 ### 4. strip(fe649b5) - 两个 CATLASS 子库 target_link_options 追加 -Wl,-s - 验证:.symtab/.strtab 去除,.dynsym 完整保留(动态链接不受影响),file 判定 stripped ## 验证 - 每轮均在 py3.12 + CANN 9.1.0 标准构建镜像内全量重建 wheel,解包对全部 10 个 ELF 逐个 readelf 核验,已修复项无回归(rpath 全为 0) - 容器内 pip install 后 import mindspeed_ops 正常,CATLASS 预载链路日志确认生效 ## 兼容性 - 全部为编译/链接选项与装载顺序调整,无 API/行为变更;-fstack-protector-all 有常规量级运行时开销(每函数 canary 检查),对 host 侧绑定层可忽略 - 不带 CATLASS 的构建(MINDSPEED_BUILD_CATLASS=0)不受影响 See merge request: Ascend/MindSpeed-Ops!173 | 1 month ago |
| docs: 优化文档,删除多余空格,修改英文标点,torch_npu修改为TorchNPU,有序列表刷新为无序列表等 Co-authored-by: f60123591<fanghui49@h-partners.com> # message auto-generated for no-merge-commit merge: !204 merge master into master docs: 优化文档,删除多余空格,修改英文标点,torch_npu修改为TorchNPU,有序列表刷新为无序列表等 Created-by: chic666 Commit-by: f60123591 Merged-by: ascend-robot Description: [#90](https://gitcode.com/Ascend/MindSpeed-Ops/issues/90) ## What this PR does / why we need it? docs: 优化文档,删除多余空格,修改英文标点,torch_npu修改为TorchNPU,有序列表刷新为无序列表等 ## Does this PR introduce any user-facing change? 不涉及 ## How was this patch tested? CI PASSED See merge request: Ascend/MindSpeed-Ops!204 | 25 days ago |
| docs: 合入英文 Co-authored-by: f60123591<fanghui49@h-partners.com> Co-authored-by: EliasKaslan<eliaskaslan@outlook.com> # message auto-generated for no-merge-commit merge: !239 merge master into master docs: 合入英文 Created-by: chic666 Commit-by: chic666;EliasKaslan;f60123591 Merged-by: ascend-robot Description: [#98](https://gitcode.com/Ascend/MindSpeed-Ops/issues/98) ## What this PR does / why we need it? 合入英文 ## Does this PR introduce any user-facing change? 合入英文 ## How was this patch tested? CI PASSED See merge request: Ascend/MindSpeed-Ops!239 | 2 days ago |
| add ci& add ut Co-authored-by: shiyuan680<917935075@qq.com> | 6 months ago |
| feat: Add Inplace Rope Co-authored-by: liu_zhi_xu<liuzhexu1@huawei.com> # message auto-generated for no-merge-commit merge: !175 merge master into master feat: Add Inplace Rope Created-by: liu_zhi_xu Commit-by: liu_zhi_xu Merged-by: ascend-robot Description: ## What this PR does / why we need it? 补充一个inplace的rope算子消除不必要的concat与反向viewcopy,提升ds v4端到端性能。 ## Does this PR introduce any user-facing change? 详见doc目录下对应markdown ## How was this patch tested?   See merge request: Ascend/MindSpeed-Ops!175 | 22 days ago |
| docs: 合入英文 Co-authored-by: f60123591<fanghui49@h-partners.com> Co-authored-by: EliasKaslan<eliaskaslan@outlook.com> # message auto-generated for no-merge-commit merge: !239 merge master into master docs: 合入英文 Created-by: chic666 Commit-by: chic666;EliasKaslan;f60123591 Merged-by: ascend-robot Description: [#98](https://gitcode.com/Ascend/MindSpeed-Ops/issues/98) ## What this PR does / why we need it? 合入英文 ## Does this PR introduce any user-facing change? 合入英文 ## How was this patch tested? CI PASSED See merge request: Ascend/MindSpeed-Ops!239 | 2 days ago |
| Fix docker build files and move torch to 2.10/cann to 9.1.0/triton-ascend to 3.2.2 Co-authored-by: Liccol<lichenhan2@huawei.com> # message auto-generated for no-merge-commit merge: !113 merge add-docker into master Fix docker build files and move torch to 2.10/cann to 9.1.0/triton-ascend to 3.2.2 Created-by: Liccol Commit-by: Liccol Merged-by: ascend-robot Description: ## What this PR does / why we need it? 本 PR 将 docker/ 目录下镜像构建的软件版本配套整体升级,并修复镜像构建流程。 **注意**:CI目录下的配套暂不进行修改,等CI机器上长跑验证后再另起PR合入,本PR仅关注镜像构建部分。 ### 软件版本配套 | 组件 | 旧版本 | 新版本 | |------|--------|--------| | CANN | 9.0.0-beta.2 | **9.1.0** | | PyTorch | 2.7.1 | **2.10.0** | | torch-npu | 2.7.1 | **2.10.0** | | triton-ascend | 3.2.1 | **3.2.2** | | Python | 3.11 | **3.12** | ### docker/Dockerfile 优化 - 移除无实际作用的 DNS 配置块 - 移除构建成功后的错误 Usage 提示输出 - rm /tmp/configure_repo.sh 改为 rm -f /tmp/configure_repo.sh,避免文件不存在时构建中断 - Ubuntu 分支 apt-get install 增加 --no-install-recommends,减小镜像体积 - 补充系统依赖与CI流程拉齐:findutils、jq、numactl-devel、tar、vim、which - 安装 MindSpeed-Ops 时增加 --no-build-isolation,复用容器内已装好的 torch-npu / triton-ascend,避免构建隔离环境重复拉取依赖 ### 文档同步 - docker/OVERVIEW.md:版本配套表、参数默认值表、示例命令全部更新;容器名 mindspeed → mindspeed-ops ## Does this PR introduce any user-facing change? 不涉及。 **构建参数接口无变化**。image_build.sh 和 build.sh 的命令行参数保持不变。 默认镜像 Tag 命名规则不变:mindspeed-ops:{branch}-{npu_type}-{os}-py{python_version}-{arch} **默认值变更**:基础镜像版本(9.0.0-beta.2 → 9.1.0)、Python(3.11 → 3.12)、PyTorch(2.7.1 → 2.10.0)、torch-npu(2.7.1 → 2.10.0)、triton-ascend(3.2.1 → 3.2.2)。 ## How was this patch tested? ### 构建验证 分别在A2/A3节点上完成镜像构建测试,通过: A2:  A3:   ### 容器环境验证 bash # 创建容器 docker run -itd \ --name mindspeed-ops \ --privileged \ --network host \ --ipc=host \ -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ -v /usr/local/dcmi:/usr/local/dcmi \ -v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \ -v /etc/ascend_install.info:/etc/ascend_install.info \ -v /home:/home \ -v /data:/data \ -v /mnt:/mnt \ mindspeed-ops:master-a3-openeuler24.03-py3.11-x86_64 bash # 这里切换成具体生成的镜像名称 # 进入容器 docker exec mindspeed-ops bash # 执行import测试 source /usr/local/Ascend/ascend-toolkit/set_env.sh python -c "import mindspeed_ops; print(\"mindspeed_ops: OK\")"  ### 单元测试 bash pytest tests/unit_tests A2:  **TODO注意**:tests/unit_tests/triton/test_chunk_gated_delta_rule.py::TestChunkGatedDeltaRule::test_chunk_gated_delta_rule_forward_backward[B1-T1121-H8-K128-V128-chunk_size64-use_qk_l2norm_in_kernelTrue-cu_seqlens[0, 112, 209, 240, 281, 489, 523, 566, 689, 721, 785, 837, 985, 1071, 1121]] 异常,需在A2环境复测后提单跟踪 A3:   arm下tests/unit_tests/triton/test_mhc_pre_only.py::TestMhcPreOnlyOperator::test_mhc_pre_only偶发异常,已知问题,重跑后正常 x86下正常  See merge request: Ascend/MindSpeed-Ops!113 | 2 months ago |
| Fix docker build files and move torch to 2.10/cann to 9.1.0/triton-ascend to 3.2.2 Co-authored-by: Liccol<lichenhan2@huawei.com> # message auto-generated for no-merge-commit merge: !113 merge add-docker into master Fix docker build files and move torch to 2.10/cann to 9.1.0/triton-ascend to 3.2.2 Created-by: Liccol Commit-by: Liccol Merged-by: ascend-robot Description: ## What this PR does / why we need it? 本 PR 将 docker/ 目录下镜像构建的软件版本配套整体升级,并修复镜像构建流程。 **注意**:CI目录下的配套暂不进行修改,等CI机器上长跑验证后再另起PR合入,本PR仅关注镜像构建部分。 ### 软件版本配套 | 组件 | 旧版本 | 新版本 | |------|--------|--------| | CANN | 9.0.0-beta.2 | **9.1.0** | | PyTorch | 2.7.1 | **2.10.0** | | torch-npu | 2.7.1 | **2.10.0** | | triton-ascend | 3.2.1 | **3.2.2** | | Python | 3.11 | **3.12** | ### docker/Dockerfile 优化 - 移除无实际作用的 DNS 配置块 - 移除构建成功后的错误 Usage 提示输出 - rm /tmp/configure_repo.sh 改为 rm -f /tmp/configure_repo.sh,避免文件不存在时构建中断 - Ubuntu 分支 apt-get install 增加 --no-install-recommends,减小镜像体积 - 补充系统依赖与CI流程拉齐:findutils、jq、numactl-devel、tar、vim、which - 安装 MindSpeed-Ops 时增加 --no-build-isolation,复用容器内已装好的 torch-npu / triton-ascend,避免构建隔离环境重复拉取依赖 ### 文档同步 - docker/OVERVIEW.md:版本配套表、参数默认值表、示例命令全部更新;容器名 mindspeed → mindspeed-ops ## Does this PR introduce any user-facing change? 不涉及。 **构建参数接口无变化**。image_build.sh 和 build.sh 的命令行参数保持不变。 默认镜像 Tag 命名规则不变:mindspeed-ops:{branch}-{npu_type}-{os}-py{python_version}-{arch} **默认值变更**:基础镜像版本(9.0.0-beta.2 → 9.1.0)、Python(3.11 → 3.12)、PyTorch(2.7.1 → 2.10.0)、torch-npu(2.7.1 → 2.10.0)、triton-ascend(3.2.1 → 3.2.2)。 ## How was this patch tested? ### 构建验证 分别在A2/A3节点上完成镜像构建测试,通过: A2:  A3:   ### 容器环境验证 bash # 创建容器 docker run -itd \ --name mindspeed-ops \ --privileged \ --network host \ --ipc=host \ -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ -v /usr/local/dcmi:/usr/local/dcmi \ -v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \ -v /etc/ascend_install.info:/etc/ascend_install.info \ -v /home:/home \ -v /data:/data \ -v /mnt:/mnt \ mindspeed-ops:master-a3-openeuler24.03-py3.11-x86_64 bash # 这里切换成具体生成的镜像名称 # 进入容器 docker exec mindspeed-ops bash # 执行import测试 source /usr/local/Ascend/ascend-toolkit/set_env.sh python -c "import mindspeed_ops; print(\"mindspeed_ops: OK\")"  ### 单元测试 bash pytest tests/unit_tests A2:  **TODO注意**:tests/unit_tests/triton/test_chunk_gated_delta_rule.py::TestChunkGatedDeltaRule::test_chunk_gated_delta_rule_forward_backward[B1-T1121-H8-K128-V128-chunk_size64-use_qk_l2norm_in_kernelTrue-cu_seqlens[0, 112, 209, 240, 281, 489, 523, 566, 689, 721, 785, 837, 985, 1071, 1121]] 异常,需在A2环境复测后提单跟踪 A3:   arm下tests/unit_tests/triton/test_mhc_pre_only.py::TestMhcPreOnlyOperator::test_mhc_pre_only偶发异常,已知问题,重跑后正常 x86下正常  See merge request: Ascend/MindSpeed-Ops!113 | 2 months ago |
| fix: pass cmake --build targets as separate arguments Co-authored-by: EliasKaslan<eliaskaslan@outlook.com> # message auto-generated for no-merge-commit merge: !187 merge fix/issue-72-cmake-target-arg into master fix: pass cmake --build targets as separate arguments Created-by: EliasKaslan Commit-by: EliasKaslan Merged-by: ascend-robot Description: ## What this PR does / why we need it? Fixes https://gitcode.com/Ascend/MindSpeed-Ops/issues/72 . setup.py assembled the CMake build command with the build target as a single --target=<name> token: python *[f"--target={name}" for name in targets], cmake --build documents and parses targets as separate arguments (--target <tgt>..., -t <tgt>...). CMake releases that parse the --build options manually reject the = form, and the build aborts **before** anything is compiled: Unknown argument --target=mindspeed_ops_C Usage: cmake --build <dir> [options] [-- [native-options]] This is reachable from the documented installation command, because --no-build-isolation makes pip skip installing the cmake>=3.26 declared in [build-system].requires, so the CMake found on PATH is used instead (see README.md:86, ci/MindSpeed_Ops_ut.sh:30, docker/Dockerfile:191). On a host whose system CMake is older than 3.21, the installation therefore fails even though the declared build requirement is satisfied. The fix passes the targets as separate arguments (--target <tgt>...), which every CMake version accepts, and drops the flag when there is no target. mindspeed_ops/csrc/build.sh already uses this form. Measured compatibility of the two spellings (cmake --build <dir> -j 2 <target-form> on a mini project, fresh configure per version): | CMake | --target=<tgt> | --target <tgt> | first line when it fails | |---|---|---|---| | 3.13.4 (system) | fails | ok | Unknown argument --target=mindspeed_ops_C | | 3.16.8 | fails | ok | Unknown argument --target=mindspeed_ops_C | | 3.17.3 / 3.18.0 / 3.18.4.post1 | fails | ok | Unknown argument --target=mindspeed_ops_C | | 3.20.3 / 3.20.4 / 3.20.5 | fails | ok | CMake Error: '--target=<tgt>' is invalid syntax for --target | | 3.21.0 / 3.21.2 / 3.21.3 | ok | ok | — | | 3.22.6 / 3.26.4 / 4.3.4 / 4.4.3 | ok | ok | — | (3.20.2 is an outlier: it happens to accept the = form, while 3.20.3 onwards reject it again.) ## Does this PR introduce any user-facing change? No. The generated CMake command is equivalent, only the argument spelling changes; no API, no documented behaviour and no file layout is touched. Users on a new CMake see an identical build. ## How was this patch tested? Verified on an Ascend 910 host (256 cores) with **CMake 3.16.8** — the oldest CMake allowed by cmake_minimum_required(VERSION 3.16) in CMakeLists.txt, and a version that rejects the = form (see the table above). 1. **Captured the argv** this code hands to CMake, with a stub cmake first on PATH (PATH=<shim>:$PATH python setup.py build_ext): - before: --build . -j 256 --target=mindspeed_ops_C - after: --build . -j 256 --target mindspeed_ops_C 2. **End-to-end A/B on two copies of the repository**, whose git diffs differ only in this hunk (an unrelated test fixture that skips the ACLNN build was applied identically to both copies, and both were run with CMake 3.16.8 and the same compiler): - before: Unknown argument --target=mindspeed_ops_C subprocess.CalledProcessError: Command '['cmake', '--build', '.', '-j', '48', '--target=mindspeed_ops_C']' returned non-zero exit status 1 exit status 1, and nothing was compiled — exactly the failure reported in the issue. - after: [100%] Linking CXX shared module mindspeed_ops_C.cpython-311-x86_64-linux-gnu.so [100%] Built target mindspeed_ops_C exit status 0, mindspeed_ops_C.cpython-311-x86_64-linux-gnu.so produced and installed. 3. ruff check --config pre-commit/pyproject.toml setup.py, ruff format --check and git diff --check are all clean. Note on the test host: its GCC 8.3.0 trips PyTorch's GCC 9 or later guard in c10/util/C++17.h, so both the before and after runs were built with the host's clang-11. This is a property of that machine and is unrelated to this change; the before run never reaches the compiler at all. See merge request: Ascend/MindSpeed-Ops!187 | 1 month ago |