文件最后提交记录最后更新时间
mc2 doc fix Co-authored-by: caoqiku<caoqiku1@h-partners.com> # message auto-generated for no-merge-commit merge: !4397 merge mc2_doc_fix_v3 into master mc2 doc fix Created-by: cqk1107 Commit-by: caoqiku Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #000--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] 🐛 Bug 修复 - [ ] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] ♻️ 重构 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [x] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [ ] 🧹 代码清理 - [ ] ❓ 其他,请描述: See merge request: cann/ops-transformer!43971 个月前
MC2算子资料完善 Co-authored-by: lyt_claire<luyitong1@huawei.com> # message auto-generated for no-merge-commit merge: !2997 merge mc2AIDD into master MC2算子资料完善 Created-by: lyt_claire Commit-by: lyt_claire Merged-by: cann-robot Description: ## 描述 修改MC2相关算子资料和示例代码 ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #000--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] 🐛 Bug 修复 - [ ] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] ♻️ 重构 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [X] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [ ] 🧹 代码清理 - [ ] ❓ 其他,请描述: See merge request: cann/ops-transformer!29971 个月前
fix: cleancode Co-authored-by: libohao6<libohao3@huawei.com> # message auto-generated for no-merge-commit merge: !5489 merge fix-cleancode-issues into master fix: cleancode Created-by: libohao6 Commit-by: libohao6 Merged-by: cann-robot Description: ## 描述 修复基础算子主线cleancode问题。 ## 关联的Issue [Bug-Report|缺陷反馈]: MC2基础算子主线存在cleancode问题 #2566 ## 测试 二级冒烟。 ## 文档更新 不涉及。 ## 类型标签 <!-- [x] 表示选中 --> - [x] 🐛 Bug 修复 - [ ] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] ♻️ 重构 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [ ] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [ ] 🧹 代码清理 - [ ] ❓ 其他,请描述: # PR #5489 代码检视报告 **PR**: https://gitcode.com/cann/ops-transformer/pull/5489 **标题**: merge 'fix-cleancode-issues' into 'master' **作者**: libohao6 | **范围**: 19 files, +453 -531 | **日期**: 2026-05-21 --- ## 改动分类 | 类型 | 改动数 | 说明 | |------|-------|------| | 删除未使用函数 | 5个 | matmul_util.cpp删3个static函数 + aclnn_matmul_reduce_scatter_v2.cpp删CreateWinTensor | | 删除冗余变量 | 2个 | x1Dtype/biasDtype 在 aclnn_weight_quant_matmul_all_reduce.cpp | | const修饰添加 | 5处 | 多个Tiling函数context参数加const | | 位操作类型修复 | 1处 | int32_t code → uint32_t bitCode | | 魔法数字→常量 | 1处 | alignas(8) → alignas(L2_CACHE_ALIGNMENT) | | 变量重命名 | 多处 | Kernel侧blockLocCoord→blockLocCoord_等; Host侧index→idx/i | | 参数名拼写修正 | 1处 | rcfCfg→rcsCfg | | include guard | 1处 | matmul_reduce_scatter_v2_tiling_common.h | | 头文件清理 | 3处 | 移除冗余#include | | 未使用参数标记 | 5处 | (void)opType等 | | 注释风格更新 | 大量 | 决策树层级注释从======改为差异化标记 | | 代码格式修复 | 多处 | 空格/缩进/换行 | --- ## 假设检验检视结果 ### 1. 删除未使用函数 ✅ PASS **涉及文件**: matmul_util.cpp, aclnn_matmul_reduce_scatter_v2.cpp 删除5个static函数(CheckShapeValidWithTrans、ProcessEmptyTensor、ProcessEmptyTensorWithTrans、GetMatmulOpInfoWithTrans、CreateWinTensor)。均为static,无跨文件引用风险。 | 规范条款 | 检查项 | 结果 | |---------|--------|------| | cpp-secure 5.2 资源泄露防护 | 删除是否遗漏调用点 | ✅ static函数仅文件内可见 | ### 2. const修饰添加 ✅ PASS **涉及文件**: all_gather_matmul_tiling_base.cpp/.h, quant_all_reduce_tiling.cpp, quant_reduce_scatter_tiling.cpp gert::TilingContext *contextconst gert::TilingContext *context。GetNodeName()、GetAttrPointer()等方法为const兼容,头文件声明同步更新。 | 规范条款 | 检查项 | 结果 | |---------|--------|------| | cpp-secure 1.1 静态类型安全 | const修饰是否导致编译错误 | ✅ 方法兼容const | ### 3. 位操作类型修复 ✅ PASS **涉及文件**: matmul_reduce_scatter_v2_aiv_mode_tiling.cpp int32_t codeuint32_t bitCode。对有符号数做右移(>>=)存在符号扩展问题,改为uint32_t消除风险。 | 规范条款 | 检查项 | 结果 | |---------|--------|------| | cpp-secure 2.1 有符号整数不溢出 | int32_t右移符号扩展 | ✅ 修复正确 | | cpp-secure 2.2 无符号整数不回绕 | uint32_t位操作安全 | ✅ | ### 4. 魔法数字→常量 ✅ PASS **涉及文件**: unquant_matmul_all_reduce_tiling_data.h static constexpr size_t L2_CACHE_ALIGNMENT = 8; 替换 alignas(8)。值等价,不影响ABI。 | 规范条款 | 检查项 | 结果 | |---------|--------|------| | cpp-secure 10.4 结构体字段末尾添加 | 常量定义位置 | ✅ 不影响ABI | ### 5. 冗余变量删除 ✅ PASS **涉及文件**: aclnn_weight_quant_matmul_all_reduce.cpp 删除 const auto x1Dtype = x1->GetDataType(); const auto biasDtype = bias->GetDataType();。两变量后续无引用,OP_CHECK_DTYPE_NOT_SAME宏自行获取dtype。 | 规范条款 | 检查项 | 结果 | |---------|--------|------| | cpp-secure 3.1 禁止未初始化变量 | 删除后功能等价 | ✅ | ### 6. 参数名拼写修正 ✅ PASS **涉及文件**: matmul_reduce_scatter_tiling_base.cpp rcfCfgrcsCfg(RCS=ReduceScatter拼写修正)。所有引用已同步替换。 | 规范条款 | 检查项 | 结果 | |---------|--------|------| | MC2 MC2-13 CCU通信数据量限制 | AdjustHCCLLimit逻辑是否保留 | ✅ 256MB限制保留 | ### 7. include guard添加 ✅ PASS **涉及文件**: matmul_reduce_scatter_v2_tiling_common.h 新增 #ifndef MATMUL_REDUCE_SCATTER_V2_TILING_COMMON_H 保护。命名与文件路径一致。 ### 8. 未使用参数标记 ✅ PASS **涉及文件**: quant_reduce_scatter_util_tiling.cpp 添加 (void)opType; (void)context; (void)xDimNum; (void)outputDim; 消除编译器警告。注释声明"Reserved for future extension"。 | 规范条款 | 检查项 | 结果 | |---------|--------|------| | TOPK TOPK-7 外部输入校验 | 校验逻辑是否削弱 | ✅ 未削弱 | ### 9. LOG参数安全 ✅ PASS **涉及文件**: allto_allv_quant_grouped_mat_mul_tiling_base.cpp 循环变量 indexidx/isendCounts[%lu] should be in [0, %lu], but get %lu — 3个%lu对应3个uint64_t(idx, bsk_, sendCounts[idx]),类型和数量匹配。 | 规范条款 | 检查项 | 结果 | |---------|--------|------| | cpp-secure 11.2 参数数量与占位符匹配 | 3个%lu=3个uint64_t | ✅ | | cpp-secure 11.3 参数类型与格式化说明符匹配 | uint64_t用%lu | ✅ | | MC2 MC2-07 专家参数合法性校验 | sendCounts/recvCounts校验完整 | ✅ | ### 10. 头文件清理 ✅ PASS **涉及文件**: matmul_reduce_scatter_tiling_base.h, quant_reduce_scatter_util_tiling.h, all_gather_matmul_tiling_base.h 移除冗余 #include "ops_utils.h"#include "mc2_log.h"。 --- ## 规范条款引用汇总 | 规范来源 | 条款编号 | 条款名称 | 检查结果 | |---------|---------|---------|---------| | cpp-secure.md | 1.1 | 保证静态类型安全 | ✅ | | cpp-secure.md | 2.1 | 有符号整数运算不溢出 | ✅ | | cpp-secure.md | 2.2 | 无符号整数运算不回绕 | ✅ | | cpp-secure.md | 3.1 | 禁止使用未初始化的变量 | ✅ | | cpp-secure.md | 5.2 | 资源泄露防护 | ✅ | | cpp-secure.md | 10.4 | 结构体字段末尾添加 | ✅ | | cpp-secure.md | 11.2 | LOG参数数量与占位符必须匹配 | ✅ | | cpp-secure.md | 11.3 | LOG参数类型与格式化说明符必须匹配 | ✅ | | mc2-specific.md | MC2-07 | 专家参数合法性校验 | ✅ | | mc2-specific.md | MC2-13 | CCU通信数据量限制 | ✅ | | ascendc-topk.md | TOPK-1 | 必须校验函数返回值 | ✅ | | ascendc-topk.md | TOPK-7 | 融合规则/InferShape/Tiling外部输入校验 | ✅ | --- ## 总体结论 **✅ 无问题** — PR #5489 为代码清理类改动,所有10项检视均PASS。改动不引入安全风险,不削弱校验逻辑,规范合规性100%。 See merge request: cann/ops-transformer!54897 天前
MatmulAllReduce AICPU适配 Co-authored-by: ouyf<ouyangfei9@huawei.com> # message auto-generated for no-merge-commit merge: !5259 merge aicpu into master MatmulAllReduce AICPU适配 Created-by: ouyf Commit-by: ouyf Merged-by: cann-robot Description: ## 描述 MatmulAllReduce AICPU适配 ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #000--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] 🐛 Bug 修复 - [ ] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] ♻️ 重构 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [ ] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [ ] 🧹 代码清理 - [ ] ❓ 其他,请描述: See merge request: cann/ops-transformer!525914 天前
修改为twoshot且仅V核进行通信初始化 Co-authored-by: ouyf<ouyangfei9@huawei.com> # message auto-generated for no-merge-commit merge: !5827 merge aicpu_twoshot into master 修改为twoshot且仅V核进行通信初始化 Created-by: ouyf Commit-by: ouyf Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #000--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] 🐛 Bug 修复 - [ ] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] ♻️ 重构 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [ ] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [ ] 🧹 代码清理 - [ ] ❓ 其他,请描述: See merge request: cann/ops-transformer!58274 天前
修改为twoshot且仅V核进行通信初始化 Co-authored-by: ouyf<ouyangfei9@huawei.com> # message auto-generated for no-merge-commit merge: !5827 merge aicpu_twoshot into master 修改为twoshot且仅V核进行通信初始化 Created-by: ouyf Commit-by: ouyf Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #000--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] 🐛 Bug 修复 - [ ] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] ♻️ 重构 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [ ] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [ ] 🧹 代码清理 - [ ] ❓ 其他,请描述: See merge request: cann/ops-transformer!58274 天前
删除matmul allreduce 的 st Co-authored-by: SimpleBright_Man<tangpanrui1@huawei.com> # message auto-generated for no-merge-commit merge: !5910 merge deleteMMARST1 into master 删除matmul allreduce 的 st Created-by: SimpleBright_Man Commit-by: SimpleBright_Man Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> 后续统一使用aclnn方法调用算子进行st测试 ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #000--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] 🐛 Bug 修复 - [ ] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] ♻️ 重构 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [ ] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [ ] 🧹 代码清理 - [ ] ❓ 其他,请描述: See merge request: cann/ops-transformer!59103 天前
mc2新特性开发 Co-authored-by: xutianze<xutianze2@huawei.com> # message auto-generated for no-merge-commit merge: !500 merge feature_mc2 into master mc2新特性开发 Created-by: xutianze Commit-by: xutianze Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #000--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/ops-transformer!5005 个月前
MC2算子资料完善 Co-authored-by: lyt_claire<luyitong1@huawei.com> # message auto-generated for no-merge-commit merge: !2997 merge mc2AIDD into master MC2算子资料完善 Created-by: lyt_claire Commit-by: lyt_claire Merged-by: cann-robot Description: ## 描述 修改MC2相关算子资料和示例代码 ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #000--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] 🐛 Bug 修复 - [ ] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] ♻️ 重构 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [X] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [ ] 🧹 代码清理 - [ ] ❓ 其他,请描述: See merge request: cann/ops-transformer!29971 个月前
README.md

MatmulAllReduce

产品支持情况

产品 是否支持
Ascend 950PR/Ascend 950DT
Atlas A3 训练系列产品/Atlas A3 推理系列产品 x
Atlas A2 训练系列产品/Atlas A2 推理系列产品
Atlas 200I/500 A2 推理产品 x
Atlas 推理系列产品 x
Atlas 训练系列产品 x

功能说明

  • 算子功能:完成MatMul计算与AllReduce通信融合。

  • 计算公式:

    非量化场景:

    • 情形1:

      yi=xi×weighti+biasiy_i=x_i\times weight_i + bias_i

    • 情形2:

      output=AllReduce(x1@x2+bias+x3)output = AllReduce(x1 @ x2 + bias + x3)

    • 情形3:对量化后的入参x1、x2进行MatMul计算后,接着进行Dequant计算,接着与x3进行Add操作,最后做AllReduce计算。

      output=AllReduce(dequantScale∗(x1int8@x2int8+biasint32)+x3)output= AllReduce(dequantScale*(x1_{int8}@x2_{int8} + bias_{int32}) + x3)

    • 情形4:对量化后的入参x1、x2进行MatMul计算后,接着进行Dequant和pertoken计算,接着与x3进行Add操作,最后做AllReduce计算。

      output=AllReduce(dequantScale∗pertokenScaleOptional∗(x1int8@x2int8+biasOptionalint32)+x3Optional)output= AllReduce(dequantScale * pertokenScaleOptional * (x1_{int8}@x2_{int8} + biasOptional_{int32}) + x3Optional)

    • 情形5:对量化后的入参x1、x2进行MatMul、Dequant和pertoken计算,接着与x3进行Add操作,再对输出进行perchannel量化,然后进行AllToAll通信,对第一次通讯结果进行reduceSum计算,接着进行AllGather通信,最后对第二次通信结果进行Dequant,得到最终输出。

      matmulAddOutput=(dequantScale∗pertokenScaleOptional∗(x1int8@x2int8+biasOptionalint32)+x3Optional);matmulAddOutput = (dequantScale * pertokenScaleOptional * (x1_{int8}@x2_{int8} + biasOptional_{int32}) + x3Optional);

      alltoallOutPutint8=AllToAll(matmulAddOutput/commQuantScale1Optional);alltoallOutPut_{int8} = AllToAll(matmulAddOutput / commQuantScale1Optional);

      reduceSumOutPutint8=(add(alltoallOutPutint8)∗(commQuantScale1Optional/commQuantScale2Optional));reduceSumOutPut_{int8} = (add(alltoallOutPut_{int8}) * (commQuantScale1Optional / commQuantScale2Optional));

      outPut=(AllGather(reduceSumOutPutint8)∗commQuantScale2Optional);outPut = (AllGather(reduceSumOutPut_{int8}) * commQuantScale2Optional);

    • 情形6:

      • commQuantScale1Optional, commQuantScale2Optional不为空时:

        matmulAddOutput=(x2Scale∗x1ScaleOptional∗(x1int8@x2int8+biasOptionalint32)+x3Optional);matmulAddOutput = (x2Scale * x1ScaleOptional * (x1_{int8}@x2_{int8} + biasOptional_{int32}) + x3Optional);

        alltoallOutputint8=AllToAll(matmulAddOutput/commQuantScale1Optional);alltoallOutput_{int8} = AllToAll(matmulAddOutput / commQuantScale1Optional);

        reduceSumOutputint8=(add(alltoallOutputint8)∗(commQuantScale1Optional/commQuantScale2Optional));reduceSumOutput_{int8} = (add(alltoallOutput_{int8}) * (commQuantScale1Optional / commQuantScale2Optional));

        output=(AllGather(reduceSumOutputint8)∗commQuantScale2Optional);output = (AllGather(reduceSumOutput_{int8}) * commQuantScale2Optional);

      • x1,x2为INT8,无x1ScaleOptional,x2Scale为INT64/UINT64,可选biasOptional为INT32,out为BFLOAT16/FLOAT16:

        output=AllReduce((x1@x2+biasOptional)∗x2Scale+x3Optional)output = AllReduce((x1@x2 + biasOptional) * x2Scale + x3Optional)

      • x1,x2为INT8,x1ScaleOptional为FLOAT32,x2Scale为FLOAT32/BFLOAT16,可选biasOptional为INT32, out为FLOAT16/BFLOAT16:

        output=AllReduce((x1@x2+biasOptional)∗x2Scale∗x1ScaleOptional+x3Optional)output = AllReduce((x1@x2 + biasOptional) * x2Scale * x1ScaleOptional + x3Optional)

      • x1,x2为FLOAT4_E2M1/FLOAT8_E4M3FN/FLOAT8_E5M2,x1ScaleOptional为FLOAT8_E8M0,x2Scale为FLOAT8_E8M0,可选biasOptional为FLOAT32, out为FLOAT16/BFLOAT16/FLOAT32:

        output=AllReduce((x1∗x1ScaleOptional)@(x2∗x2Scale)+biasOptional+x3Optional)output = AllReduce((x1* x1ScaleOptional)@(x2* x2Scale) + biasOptional + x3Optional)

      • x1,x2为FLOAT8_E4M3FN/FLOAT8_E5M2/HIFLOAT8,x1ScaleOptional为FLOAT32,x2Scale为FLOAT32,可选bias为FLOAT32, out为FLOAT16/BFLOAT16/FLOAT32:

        output=AllReduce((x1@x2+biasOptional)∗x2Scale∗x1ScaleOptional+x3Optional)output = AllReduce((x1@x2 + biasOptional) * x2Scale * x1ScaleOptional + x3Optional)

      • x1,x2为FLOAT8_E4M3FN/FLOAT8_E5M2/HIFLOAT8,x1ScaleOptional为FLOAT32,x2Scale为FLOAT32,无biasOptional。当x1为(a0, a1),x2为(b0, b1)时x1ScaleOptional为(ceildiv(a0,128), ceildiv(a1,128)),x2Scale为(ceildiv(b0,128), ceildiv(b1,128)),out为FLOAT16/BFLOAT16/FLOAT32:

        outputpq=AllReduce(∑0⌊k128⌋(x1pr@x2rq∗(x1ScaleOptionalpr∗x2Scalerq))+x3)output_{pq} = AllReduce(\sum_{0}^{\left \lfloor \frac{k}{128} \right \rfloor} (x1_{pr}@x2_{rq}*(x1ScaleOptional_{pr}*x2Scale_{rq})) + x3)

    • 情形7:

      output = Allreduce(x1 @ ((x2 + antiquantOffset) ∗antiquantScale) + bias+ x3) output = Allreduce(x1 @ ((x2 + antiquantOffset) *antiquantScale) + bias+ x3) 

参数说明

参数名 输入/输出/属性 描述 数据类型 数据格式
x1 输入 MatMul左矩阵,即公式中的输入x1。 FLOAT16、BFLOAT16、INT8、HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN、FLOAT4_E2M1 ND
x2 输入 MatMul右矩阵,即公式中的输入x2。 FLOAT16、BFLOAT16、INT8、INT4、HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN、FLOAT4_E2M1 ND、FRACTAL_NZ
bias 可选输入 公式中的输入bias。 FLOAT16、BFLOAT16、INT32、FLOAT ND
x3 可选输入 MatMul计算后的Add计算,即公式中的输入x3。 FLOAT16、BFLOAT16、FLOAT ND
antiquantScale 可选输入 公式中的输入antiquantScale。 FLOAT16、BFLOAT16 ND
antiquantOffset 可选输入 公式中的输入antiquantOffset。 FLOAT16、BFLOAT16 ND
dequantScale 可选输入 MatMul计算后的去量化系数,即公式中的输入dequantScale。 FLOAT16、BFLOAT16、FLOAT、UINT64、FLOAT8_E8M0 ND
pertoken_scale 可选输入 MatMul计算后的pertoken去量化系数,即公式中的输入pertokenScaleOptional。 FLOAT、BFLOAT16、FLOAT8_E8M0 ND
comm_quant_scale_1 可选输入 matmulAdd计算后的perchannel量化系数,即公式中的输入comm_quant_scale_1。 FLOAT、BFLOAT16、FLOAT16 ND
comm_quant_scale_2 可选输入 allGather计算后的perchannel量化系数,即公式中的输入comm_quant_scale_2。 FLOAT、BFLOAT16、FLOAT16 ND
output 输出 计算+通信的结果,即公式中的输出output。 FLOAT、BFLOAT16、FLOAT16 ND
group 属性
  • Host侧标识列组的字符串,通信域名称。
  • 通过Hccl提供的接口“extern HcclResult HcclGetCommName(HcclComm comm, char* commName);”获取,其中commName即为group。
CHAR*、STRING -
reduceOp 可选属性
  • reduce操作类型。
  • 默认值为"sum"。
CHAR*、STRING -
is_trans_a 可选属性
  • 决定x1是否执行矩阵乘前进行转置。
  • 默认值为false。
BOOL -
is_trans_b 可选属性
  • 决定x2是否执行矩阵乘前进行转置。
  • 默认值为false。
BOOL -
commTurn 可选属性
  • 通信数据切分数,即总数据量/单次通信量。
  • 默认值为0。
INT64 -
antiquant_group_size 可选属性 伪量化pergroup模式下,对x2进行反量化计算的groupSize输入。 INT64 -
group_size 可选属性
  • 在输入张量 x1/x2 中,M、N、K 维度上的数值数量共同对应一个反量化系数。
  • 默认值为0。
  • 保留属性
INT64 -
comm_quant_mode 可选属性
  • 静态量化和动态量化的标志位,数值为0和1。
  • 默认值为0。
INT64 -

约束说明

  • 增量场景不使能MC2,全量场景使能MC2。
  • 输入x1可为二维或者三维,其shape为(b, s, k)或者(m, k),不支持非连续输入。
  • 输入x2必须是二维。其shape为(k, n),k轴满足mm算子入参要求,k轴相等,m的范围为[1, 2147483647],k、n的范围为[1, 65535]。
  • 输入x2的数据格式:
    • Atlas A2 训练系列产品/Atlas A2 推理系列产品:支持ND(当前版本仅支持二维输入)和FRACTAL_NZ格式(当前版本仅支持四维输入)。
    • Ascend 950PR/Ascend 950DT:支持ND格式。
    • 当x2的数据格式为FRACTAL_NZ时,配合aclnnCalculateMatmulWeightSizeV2和aclnnTransMatmulWeight到数据格式NZ的转换,非连续Tensor仅支持transpose场景。当x2的数据格式为ND时,当前版本仅支持二维输入。
  • 传入的x1、x2、antiquantScale或者output不为空指针。
  • 当输入x1的shape为(b, s, k)时,x3(非空场景)与输出output的shape为(b, s, n),pertoken_scale的shape为(b*s);当输入x1的shape为(m, k)时,x3(非空场景)与输出output的shape为(m, n),pertoken_scale的shape为(m)。
  • 输入comm_quant_scale_1和comm_quant_scale_2可选,可为空,当x2为(k, n)时, shape可为(n)或者(1,n)。
  • 输入dequantScale可选,可为空,shape在pertensor场景为(1),perchannel场景为(n)/(1, n)。输出为BFLOAT16时,直接将BFLOAT16类型的dequantScale传入本接口。输出为FLOAT16时,如果pertokenScaleOptional不为空,可直接将FLOAT32类型的dequantScale传入本接口,如果pertokenScaleOptional为空,则需提前调用TransQuantParamV2算子的aclnn接口来将dequantScale转成INT64/UINT64数据类型。
  • bias若非空,当前版本仅支持一维,shape大小与output最后一维大小相等。antiquantScale在pertensor场景下shape为(1),在perchannel场景下shape为(1,n)/(n),在pergroup场景shape为(ceil(k,antiquantGroupSize), n)。antiquantOffset若非空,其shape与antiquantScale一致。
  • x1和x2,x3(非空场景)、antiquantScale、antiquantOffset(非空场景)、output、bias(非空场景)的数据类型和数据格式需要在支持的范围之内。
  • x1、antiquantScale、antiquantOffset(非空场景)、x3(非空场景)、bias(非空场景)和output的数据类型相同。antiquantGroupSize在不支持pergroup场景时,传入0,在支持pergroup场景时,传入值的范围为[32, min(k-1,INT_MAX)],且为32的倍数。k取值范围与mm接口保持一致。
  • group_size在perblock场景下,只支持549764202624。其他场景,只支持0。
  • 只支持x2矩阵转置/不转置,x1矩阵不支持转置场景。
  • 属性reduceOp当前版本仅支持输入"sum"。
  • 属性commTurn当前版本仅支持输入0。
  • 在长序列场景,随着b/s或者m的增大,可能出现OOM或者计算超时。
  • 仅支持hccs链路all mesh组网。
    • Atlas A2 训练系列产品/Atlas A2 推理系列产品:支持1、2、4、8卡。
    • Ascend 950PR/Ascend 950DT:支持1、2、4、8、16、32、64卡。
  • Atlas A2 训练系列产品/Atlas A2 推理系列产品:一个模型中的通算融合MC2算子,仅支持相同通信域。

调用说明

调用方式 样例代码 说明
aclnn接口 test_aclnn_matmul_all_reduce.cpp 通过aclnnMatMulAllReduce接口方式调用MatMulAllReduce算子。