| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
[Feature][ops]Add norm_rope_concat fused operator Co-authored-by: zhangtian6691844<zhangtiantian5@huawei.com> # message auto-generated for no-merge-commit merge: !455 merge feat/norm_rope_concat_dev into dev [Feature][ops]Add norm_rope_concat fused operator Created-by: zhangtian6691844 Commit-by: zhangtian6691844 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20251224 --> # Which issue(s) this PR fixes or accomplishes > **如问题已解决,按照下方示例附上ISSUE单号 / Apply bug or request issue as follow if the solved**\ > Fixes #ISSUE ID\ > **Fixes关键字会自动关闭issue,如问题部分解决请不要使用Fixes,可以用下方标签替代\ > Fixes will automatically close issue, please use the following tag if only part of the issue is solved**\ > Fix part of #ISSUE ID N/A — 新增特性,非问题修复。 # Purpose 为 MindIE-SD 新增 **NormRopeConcat 融合算子**,将三个高频操作(LayerNorm/RMSNorm、RoPE 旋转位置编码、KV Concat)融合为一个 AscendC 自定义算子,减少显存访问次数和 kernel launch 开销,提升大模型推理性能。 **算子功能:** - 对 Query/Key 输入执行 LayerNorm 或 RMSNorm(可选 affine) - 对 Query/Key 执行 RoPE 旋转位置编码(支持 interleave / half 两种模式) - 将 encoder KV 与当前 KV concat 拼接(支持 encoder 在前或在后) - 支持训练模式,输出 norm 的 mean/rstd 用于反向传播 - 支持 16 个输入、11 个输出,全部可选张量自动处理 **变更范围(18 files, +3819/-6 lines):** | 模块 | 文件 | 说明 | |------|------|------| | AscendC Host | csrc/ops/norm_rope_concat/op_host/ (6 files) | 算子定义、Shape/Dtype 推导、Tiling 策略 | | AscendC Kernel | csrc/ops/norm_rope_concat/op_kernel/ (4 files) | NPU 核函数实现 | | PyTorch 插件 | csrc/plugin/norm_rope_concat.{cpp,h} (2 files) | 插件适配层,调用 ACLNN 接口 | | 构建集成 | build/build_ops.sh, csrc/CMakeLists.txt, csrc/plugin/register_ops.cpp | 算子注册与编译 | | 单元测试 | tests/ops/norm_rope_concat/ (3 files) | Python 功能测试 + C++ Kernel UT | # Test Plan > 设计了哪些测试内容,指导他人如何对你的PR进行测试\ > Apply information to show others your test design and how to test your Pull Request 1. **编译验证** - AscendC 算子编译(ascend910_93 / ascend910b / ascend950 三芯片) - PyTorch 插件编链(libPTAExtensionOPS.so) - 构建环境:CANN 9.1.T560 + bisheng + PyTorch 2.x 2. **单元测试(Python)** - test_norm_rope_concat.py:覆盖 norm_type (NONE/LAYER_NORM/RMS_NORM)、rope_type (NONE/INTERLEAVE/HALF)、concat_order (BEFORE/AFTER)、训练模式等组合 - run_simple_test.py:快速冒烟测试 3. **C++ Kernel UT** - test_norm_rope_concat_kernel.cpp:验证 Tiling 数据传递与 kernel 逻辑正确性 4. **回归验证** - 已有算子(LA、AdaLA、RainFusionAttention 等)编译不受影响 - build_ops.sh 中 norm_rope_concat 作为 ascendc_ops 之一参与构建 # Test Report | 测试项 | 芯片 | 结果 | |--------|------|------| | AscendC 编译 (op_host_aclnn) | - | ✅ PASS | | AscendC 编译 (opsproto) | - | ✅ PASS | | AscendC 编译 (optiling) | - | ✅ PASS | | AscendC Kernel 生成 | ascend910_93 | ✅ PASS | | AscendC Kernel 生成 | ascend910b | ✅ PASS | | AscendC Kernel 生成 | ascend950 | ✅ PASS | | CANN-custom_ops .run 打包 | - | ✅ PASS | | PyTorch 插件编译链接 | - | ✅ PASS (100%) | | 已有算子兼容性 | - | ✅ 无影响 | **测试环境:** CANN 9.1.T560, Ascend950PR NPU, Python 3.11, aarch64 See merge request: Ascend/MindIE-SD!455 | 1 个月前 | |
[feat][compilation]按torch版本兼容rms_norm/rope pattern的dtype cast分解 Co-authored-by: xuzhenqiang<xuzhenqiang3@huawei.com> # message auto-generated for no-merge-commit merge: !519 merge dev into dev [feat][compilation]按torch版本兼容rms_norm/rope pattern的dtype cast分解 Created-by: zqxu Commit-by: xuzhenqiang Merged-by: ascend-robot Description: # Which issue(s) this PR fixes or accomplishes Fixes [#298](https://gitcode.com/Ascend/MindIE-SD/issues/298) # Purpose torch_npu 2.9 起(MR 30358,commit 5c2817cd85,2026-02)移除了 Tensor.to 的 NPU 过适配:dtype cast 在编译图(AOT 分解)中由 torch.ops.npu._npu_dtype_cast 变为 torch.ops.aten._to_copy。 由于 compilation pattern 的匹配是文本级算子序列匹配(PatternMatchPass 基于 torch._inductor.pattern_matcher),按旧分解结构编写的 RMSNormPattern 与 RopePattern 在 torch 2.9+ 环境全部失配: - 修改前:PatternMatchPass replace 190 patterns(仅 AdaLayerNorm 114 + GELU 76,RMSNorm/RoPE 均 0 匹配) - 根因:rms_norm 经 core decomposition 表展开为 _to_copy → pow → mean → add → rsqrt → mul → mul → _to_copy,第一个 dtype cast 节点从 _npu_dtype_cast 变为 _to_copy,第一个节点不匹配则整链放弃 本 PR 的修改: 1. 在 rms_norm_pattern.py / rope_pattern.py 中按 torch.__version__ 版本分支选择 dtype cast 算子: - torch < 2.9:保持原有 _npu_dtype_cast 匹配逻辑,行为完全不变 - torch >= 2.9:pattern 适配为 torch.ops.aten._to_copy.default(dtype 为关键字参数) 2. 修复 rope_pattern.py 中 x_out.type_as(x) 未赋值的 no-op bug,并补充真实图中存在的末尾 .to(x.dtype) cast 节点(diffusers apply_rotary_emb 源码固有结构) # Test Plan 环境要求:torch 2.9 / torch_npu 2.9(或更新)、cache-dit 源码安装、FLUX.1-dev 权重。 bash # 1. 安装本 PR 分支 python3 -m pip install -e . # 2. 编译匹配数验证(cache-dit 标准 CLI,预期 494) MINDIE_LOG_LEVEL=debug python3 -m cache_dit.generate flux \ --model-path /data/weights/FLUX.1-dev \ --compile --warmup 2 --repeat 2 2>&1 | grep "PatternMatchPass replace" # 预期: 494 = 190(AdaLayerNorm+GELU) + 152(RMSNorm) + 152(RoPE) # 3. profiling 验证融合算子真实执行(torch_npu profiler 采集) # 在推理脚本中用 torch_npu.profiler.profile 包裹 generate 调用,导出后: grep -ci "rmsnorm\|rotary" ./profiling/*/kernel_details.csv # 预期: 出现 aclnnRmsNorm / RotaryPositionEmbedding,eager 对照为 0 # Test Report - 环境:torch 2.9 / torch_npu 2.9 / 910B - RMSNorm:PatternMatchPass replace 190 → 342(+152),profiling 中 npu_rms_norm 调用 152×steps 次(4 步采样 608 次),融合真实生效 - RoPE:profiling 中出现 RotaryPositionEmbedding 融合算子(456 次),eager 对照为 0 次 - torch 2.10 源码级验证:rms_norm_symint / rms_norm_composite / _to_copy decomposition 与 2.9 完全一致(layer_norm.cpp diff 为空),本修复在 2.10 上继续有效 # Summary Name Stmts Miss Branch BrPart Cover Missing ----------------------------------------------------------------------------------------------------- mindiesd/env.py 10 0 0 0 100% mindiesd/eplb/__init__.py 4 0 0 0 100% mindiesd/eplb/collector.py 28 19 2 0 30% 21-29, 32-36, 39-44, 47 mindiesd/eplb/dispatcher.py 71 53 0 0 25% 22-34, 37-43, 46-47, 50, 53, 56, 59, 64-79, 82, 85-88, 91-109, 112-127 mindiesd/eplb/eplb_scheduler.py 128 45 14 2 61% 53-64, 127-136, 176-184, 194-195, 200-208, 222-243, 247-248 mindiesd/eplb/greedy_algorithm.py 321 197 108 8 35% 97, 113-123, 131, 138, 180-182, 223-225, 256-339, 371, 374-469, 505-512, 519-628, 632-653, 699, 721-724 ...... .... ... .... .. .. mindiesd/quantization/utils.py 175 26 66 13 80% 36-48, 56, 72, 78, 123, 146, 156, 162, 183, 255, 259, 274, 285, 301 mindiesd/share_memory.py 106 106 26 0 0% 13-202 mindiesd/utils/__init__.py 3 0 0 0 100% mindiesd/utils/env.py 114 17 52 19 78% 54, 132, 135, 138, 141, 144, 147, 150, 153, 156, 159, 162, 166->172, 169, 174-175, 178->184, 181, 185->exit, 188 .......................................................................................... TOTAL 7152 2476 2326 369 63% See merge request: Ascend/MindIE-SD!519 | 17 天前 | |
[Feature][ops]Add norm_rope_concat fused operator Co-authored-by: zhangtian6691844<zhangtiantian5@huawei.com> # message auto-generated for no-merge-commit merge: !455 merge feat/norm_rope_concat_dev into dev [Feature][ops]Add norm_rope_concat fused operator Created-by: zhangtian6691844 Commit-by: zhangtian6691844 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20251224 --> # Which issue(s) this PR fixes or accomplishes > **如问题已解决,按照下方示例附上ISSUE单号 / Apply bug or request issue as follow if the solved**\ > Fixes #ISSUE ID\ > **Fixes关键字会自动关闭issue,如问题部分解决请不要使用Fixes,可以用下方标签替代\ > Fixes will automatically close issue, please use the following tag if only part of the issue is solved**\ > Fix part of #ISSUE ID N/A — 新增特性,非问题修复。 # Purpose 为 MindIE-SD 新增 **NormRopeConcat 融合算子**,将三个高频操作(LayerNorm/RMSNorm、RoPE 旋转位置编码、KV Concat)融合为一个 AscendC 自定义算子,减少显存访问次数和 kernel launch 开销,提升大模型推理性能。 **算子功能:** - 对 Query/Key 输入执行 LayerNorm 或 RMSNorm(可选 affine) - 对 Query/Key 执行 RoPE 旋转位置编码(支持 interleave / half 两种模式) - 将 encoder KV 与当前 KV concat 拼接(支持 encoder 在前或在后) - 支持训练模式,输出 norm 的 mean/rstd 用于反向传播 - 支持 16 个输入、11 个输出,全部可选张量自动处理 **变更范围(18 files, +3819/-6 lines):** | 模块 | 文件 | 说明 | |------|------|------| | AscendC Host | csrc/ops/norm_rope_concat/op_host/ (6 files) | 算子定义、Shape/Dtype 推导、Tiling 策略 | | AscendC Kernel | csrc/ops/norm_rope_concat/op_kernel/ (4 files) | NPU 核函数实现 | | PyTorch 插件 | csrc/plugin/norm_rope_concat.{cpp,h} (2 files) | 插件适配层,调用 ACLNN 接口 | | 构建集成 | build/build_ops.sh, csrc/CMakeLists.txt, csrc/plugin/register_ops.cpp | 算子注册与编译 | | 单元测试 | tests/ops/norm_rope_concat/ (3 files) | Python 功能测试 + C++ Kernel UT | # Test Plan > 设计了哪些测试内容,指导他人如何对你的PR进行测试\ > Apply information to show others your test design and how to test your Pull Request 1. **编译验证** - AscendC 算子编译(ascend910_93 / ascend910b / ascend950 三芯片) - PyTorch 插件编链(libPTAExtensionOPS.so) - 构建环境:CANN 9.1.T560 + bisheng + PyTorch 2.x 2. **单元测试(Python)** - test_norm_rope_concat.py:覆盖 norm_type (NONE/LAYER_NORM/RMS_NORM)、rope_type (NONE/INTERLEAVE/HALF)、concat_order (BEFORE/AFTER)、训练模式等组合 - run_simple_test.py:快速冒烟测试 3. **C++ Kernel UT** - test_norm_rope_concat_kernel.cpp:验证 Tiling 数据传递与 kernel 逻辑正确性 4. **回归验证** - 已有算子(LA、AdaLA、RainFusionAttention 等)编译不受影响 - build_ops.sh 中 norm_rope_concat 作为 ascendc_ops 之一参与构建 # Test Report | 测试项 | 芯片 | 结果 | |--------|------|------| | AscendC 编译 (op_host_aclnn) | - | ✅ PASS | | AscendC 编译 (opsproto) | - | ✅ PASS | | AscendC 编译 (optiling) | - | ✅ PASS | | AscendC Kernel 生成 | ascend910_93 | ✅ PASS | | AscendC Kernel 生成 | ascend910b | ✅ PASS | | AscendC Kernel 生成 | ascend950 | ✅ PASS | | CANN-custom_ops .run 打包 | - | ✅ PASS | | PyTorch 插件编译链接 | - | ✅ PASS (100%) | | 已有算子兼容性 | - | ✅ 无影响 | **测试环境:** CANN 9.1.T560, Ascend950PR NPU, Python 3.11, aarch64 See merge request: Ascend/MindIE-SD!455 | 1 个月前 | |
[Feature][ops]Add norm_rope_concat fused operator Co-authored-by: zhangtian6691844<zhangtiantian5@huawei.com> # message auto-generated for no-merge-commit merge: !455 merge feat/norm_rope_concat_dev into dev [Feature][ops]Add norm_rope_concat fused operator Created-by: zhangtian6691844 Commit-by: zhangtian6691844 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20251224 --> # Which issue(s) this PR fixes or accomplishes > **如问题已解决,按照下方示例附上ISSUE单号 / Apply bug or request issue as follow if the solved**\ > Fixes #ISSUE ID\ > **Fixes关键字会自动关闭issue,如问题部分解决请不要使用Fixes,可以用下方标签替代\ > Fixes will automatically close issue, please use the following tag if only part of the issue is solved**\ > Fix part of #ISSUE ID N/A — 新增特性,非问题修复。 # Purpose 为 MindIE-SD 新增 **NormRopeConcat 融合算子**,将三个高频操作(LayerNorm/RMSNorm、RoPE 旋转位置编码、KV Concat)融合为一个 AscendC 自定义算子,减少显存访问次数和 kernel launch 开销,提升大模型推理性能。 **算子功能:** - 对 Query/Key 输入执行 LayerNorm 或 RMSNorm(可选 affine) - 对 Query/Key 执行 RoPE 旋转位置编码(支持 interleave / half 两种模式) - 将 encoder KV 与当前 KV concat 拼接(支持 encoder 在前或在后) - 支持训练模式,输出 norm 的 mean/rstd 用于反向传播 - 支持 16 个输入、11 个输出,全部可选张量自动处理 **变更范围(18 files, +3819/-6 lines):** | 模块 | 文件 | 说明 | |------|------|------| | AscendC Host | csrc/ops/norm_rope_concat/op_host/ (6 files) | 算子定义、Shape/Dtype 推导、Tiling 策略 | | AscendC Kernel | csrc/ops/norm_rope_concat/op_kernel/ (4 files) | NPU 核函数实现 | | PyTorch 插件 | csrc/plugin/norm_rope_concat.{cpp,h} (2 files) | 插件适配层,调用 ACLNN 接口 | | 构建集成 | build/build_ops.sh, csrc/CMakeLists.txt, csrc/plugin/register_ops.cpp | 算子注册与编译 | | 单元测试 | tests/ops/norm_rope_concat/ (3 files) | Python 功能测试 + C++ Kernel UT | # Test Plan > 设计了哪些测试内容,指导他人如何对你的PR进行测试\ > Apply information to show others your test design and how to test your Pull Request 1. **编译验证** - AscendC 算子编译(ascend910_93 / ascend910b / ascend950 三芯片) - PyTorch 插件编链(libPTAExtensionOPS.so) - 构建环境:CANN 9.1.T560 + bisheng + PyTorch 2.x 2. **单元测试(Python)** - test_norm_rope_concat.py:覆盖 norm_type (NONE/LAYER_NORM/RMS_NORM)、rope_type (NONE/INTERLEAVE/HALF)、concat_order (BEFORE/AFTER)、训练模式等组合 - run_simple_test.py:快速冒烟测试 3. **C++ Kernel UT** - test_norm_rope_concat_kernel.cpp:验证 Tiling 数据传递与 kernel 逻辑正确性 4. **回归验证** - 已有算子(LA、AdaLA、RainFusionAttention 等)编译不受影响 - build_ops.sh 中 norm_rope_concat 作为 ascendc_ops 之一参与构建 # Test Report | 测试项 | 芯片 | 结果 | |--------|------|------| | AscendC 编译 (op_host_aclnn) | - | ✅ PASS | | AscendC 编译 (opsproto) | - | ✅ PASS | | AscendC 编译 (optiling) | - | ✅ PASS | | AscendC Kernel 生成 | ascend910_93 | ✅ PASS | | AscendC Kernel 生成 | ascend910b | ✅ PASS | | AscendC Kernel 生成 | ascend950 | ✅ PASS | | CANN-custom_ops .run 打包 | - | ✅ PASS | | PyTorch 插件编译链接 | - | ✅ PASS (100%) | | 已有算子兼容性 | - | ✅ 无影响 | **测试环境:** CANN 9.1.T560, Ascend950PR NPU, Python 3.11, aarch64 See merge request: Ascend/MindIE-SD!455 | 1 个月前 |
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 1 个月前 | ||
| 17 天前 | ||
| 1 个月前 | ||
| 1 个月前 |