| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
add inductor check and bench tools for precision check tool Co-authored-by: yurongkun<yurongkun@huawei.com> # message auto-generated for no-merge-commit merge: !3366 merge indcutor_check_tools into master add inductor check and bench tools for precision check tool Created-by: yurongkun Commit-by: yurongkun Merged-by: ascend-robot Description: add inductor check and bench tools for precision check tool See merge request: Ascend/torchair!3366 | 6 天前 | |
keep raw format for generated af c++ code Co-authored-by: medivh<xuepeng4@huawei.com> # message auto-generated for no-merge-commit merge: !2569 merge master into master keep raw format for generated af c++ code Created-by: medivh-x Commit-by: medivh Merged-by: ascend-robot Description: 不参与代码打包。 See merge request: Ascend/torchair!2569 | 5 个月前 | |
放开pylint规则,并修复现存的pylint问题 Co-authored-by: 冯振强<fengzhenqiang@huawei.com> # message auto-generated for no-merge-commit merge: !3417 merge pre_commit_test into master 放开pylint规则,并修复现存的pylint问题 Created-by: feng_zhenqiang Commit-by: 冯振强 Merged-by: ascend-robot Description: | 工具 | 错误码 | 问题描述 | 处理数量 | 处理方式 | 验证结果 | | --- | --- | --- | ---: | --- | --- | | Pylint | C0412 | 导入未按包分组。 | 9 | 回退 import 分组调整,在触发的 import 代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | C0412 局部屏蔽后定向验证通过,退出码 0 | | Pylint | C2801 | 直接调用双下划线方法。 | 2 | 在对应 __setattr__ 调用代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | C2801 局部屏蔽后定向验证通过,退出码 0 | | Pylint | E0402 | 相对导入层级越过包顶层。 | 18 | 尽量替换为绝对导入,保留函数内延迟导入语义;未新增屏蔽配置 | E0402 定向验证通过,退出码 0 | | Pylint | E0710 | raise 的对象不是异常。 | 1 | 按要求将 raise out 改为 return out,保持 converter 返回语义 | E0710 定向验证通过,退出码 0 | | Pylint | R0402 | 可将模块导入改成显式成员导入。 | 6 | 将对应导入改为 from module import name 形式;setup 文件保留 C0412 局部屏蔽 | R0402 定向验证通过,退出码 0;setup 文件 C0412 复查通过 | | Pylint | R1711 | 函数末尾存在无实际作用的 return。 | 105 | 删除函数末尾无效 return / return None,必要处改为 pass | --enable=R1711 全量验证通过 | | Pylint | W0102 | 函数参数使用可变默认值。 | 2117 | 在 1842 个唯一触发代码行添加行级 dangerous-default-value 屏蔽;未在配置或文件顶部全局屏蔽 | 15 个普通文件 Pylint 验证通过,自动生成文件静态校验通过 | | Pylint | W0401 | 使用星号导入,导入名称集合无法被静态明确。 | 936 | 在 942 处星号导入代码行添加行级 wildcard-import,unused-wildcard-import 屏蔽;未在配置中全局屏蔽 | 代表性文件 Pylint 验证通过,937 个文件、942 处 import * 行静态校验通过 | | Pylint | W0404 | 同一名称被重复导入。 | 4 | 在对应 import 代码处添加 reimported 局部屏蔽,保留导入语义 | W0404 定向验证通过,退出码 0 | | Pylint | W0406 | 模块导入了自身。 | 4 | 对包初始化入口的副作用导入添加行级 import-self 屏蔽,保留初始化语义 | W0406 定向验证通过,退出码 0 | | Pylint | W0614 | 星号导入带来了未被使用的名称。 | 936 | 在 942 处星号导入代码行添加行级 wildcard-import,unused-wildcard-import 屏蔽;未在配置中全局屏蔽 | 代表性文件 Pylint 验证通过,937 个文件、942 处 import * 行静态校验通过 | | Pylint | W1203 | 日志使用了 f-string。 | 279 | 在对应日志调用代码处添加 # pylint: disable=logging-fstring-interpolation,保留原 f-string 日志写法 | pylint --disable=all --enable=W1203 定向验证通过 | | Pylint | W1201 | 日志在调用前就完成了字符串求值。 | 1 | 在对应 logger.info 调用处添加 # pylint: disable=logging-not-lazy,保留原日志拼接写法 | pylint --disable=all --enable=W1201 定向验证通过 | | Pylint | W1401 | 字符串中包含异常反斜杠转义。 | 15 | 将 ASCII 图中的反斜杠改为 \,保留示意图语义 | pylint --disable=all --enable=W1401 定向验证通过(3 个文件) | | Pylint | W2301 | 省略号占位写法没有必要。 | 4 | 在抽象方法中改为 pass,保留抽象接口语义 | pylint --disable=all --enable=W2301,W3301 定向验证通过 | | Pylint | W3301 | 嵌套 min 可简化。 | 1 | 将嵌套 min 改为单层 min(...) 写法,保持边界截断语义 | pylint --disable=all --enable=W2301,W3301 定向验证通过 | | Pylint | W0105 | 出现独立字符串语句。 | 28 | 在对应代码处将独立字符串改为注释,保留原说明内容 | pylint --disable=all --enable=W0105 定向验证通过(24 个文件) | | Pylint | E0611 | 动态扩展、编译产物或运行时模块成员无法被静态导入分析识别。 | 15 | 在对应代码处添加 pylint 局部屏蔽;本次未新增全局屏蔽配置 | 20 个涉及文件定向验证通过,51 个屏蔽位置静态校验通过 | | Pylint | E1101 | 动态属性或运行时注入成员无法被 Pylint 静态识别。 | 3 | 在对应代码处添加 pylint 局部屏蔽;本次未新增全局屏蔽配置 | 20 个涉及文件定向验证通过,51 个屏蔽位置静态校验通过 | | Pylint | E1102 | 动态可调用对象被 Pylint 判断为不可调用。 | 4 | 在对应代码处添加 pylint 局部屏蔽;本次未新增全局屏蔽配置 | 20 个涉及文件定向验证通过,51 个屏蔽位置静态校验通过 | | Pylint | E1121 | 动态接口调用参数数量与 Pylint 推断签名不一致。 | 7 | 在对应代码处添加 pylint 局部屏蔽;本次未新增全局屏蔽配置 | 20 个涉及文件定向验证通过,51 个屏蔽位置静态校验通过 | | Pylint | E1123 | 动态接口调用使用了 Pylint 推断签名未声明的关键字参数。 | 1 | 在对应代码处添加 pylint 局部屏蔽;本次未新增全局屏蔽配置 | 20 个涉及文件定向验证通过,51 个屏蔽位置静态校验通过 | | Pylint | E1125 | 动态接口调用缺少 Pylint 推断签名要求的关键字参数。 | 5 | 在对应代码处添加 pylint 局部屏蔽;本次未新增全局屏蔽配置 | 20 个涉及文件定向验证通过,51 个屏蔽位置静态校验通过 | | Pylint | R0401 | 模块之间存在循环导入关系。 | 12 | 在对应文件顶部添加 pylint 文件级屏蔽;诊断落在模块入口,放在 shebang 后顶部屏蔽;本次未新增全局屏蔽配置 | 20 个涉及文件定向验证通过,51 个屏蔽位置静态校验通过 | | Pylint | R0801 | 多个文件存在重复代码片段。 | 516 | 在对应代码处添加 pylint 局部屏蔽;诊断落在模块入口,放在 shebang 后顶部屏蔽;本次未新增全局屏蔽配置 | 20 个涉及文件定向验证通过,51 个屏蔽位置静态校验通过 | | Pylint | W0236 | 子类覆盖父类成员时方法和属性形态不一致。 | 6 | 在对应代码处添加 pylint 局部屏蔽;本次未新增全局屏蔽配置 | 20 个涉及文件定向验证通过,51 个屏蔽位置静态校验通过 | | Pylint | W1116 | isinstance() 第二个参数由动态对象提供,Pylint 无法确认其为类型。 | 2 | 在对应代码处添加 pylint 局部屏蔽;本次未新增全局屏蔽配置 | 20 个涉及文件定向验证通过,51 个屏蔽位置静态校验通过 | | Pylint | W4901 | 使用了 Pylint 标记为废弃的模块。 | 4 | 在对应代码处添加 pylint 局部屏蔽;本次未新增全局屏蔽配置 | 20 个涉及文件定向验证通过,51 个屏蔽位置静态校验通过 | | Pylint | E0102 | 同名函数或方法重复定义。 | 13 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | E0203 | 成员在定义前被访问。 | 2 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | E0602 | 引用了未定义变量或名称。 | 6 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | E0606 | 变量可能在赋值前被使用。 | 9 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | R0124 | 条件在和自身比较。 | 1 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | R0205 | 继承 object 没有实际意义。 | 3 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | R0916 | 布尔条件过于复杂。 | 7 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | R1701 | 多个 isinstance 可合并。 | 4 | 使用元组合并类型判断,保持原判断语义 | R1701 定向验证通过,退出码 0 | | Pylint | R1702 | 嵌套层级过深。 | 8 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | R1704 | 局部变量重用了参数名。 | 7 | 在对应代码处添加 pylint 局部屏蔽;自动生成文件按当前源码 AST 定位;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | R1710 | 不同分支返回值不一致。 | 14 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | R1714 | 等值判断链可改成成员判断。 | 87 | 在 85 条当前诊断对应代码处添加 pylint 局部屏蔽;2 条旧基线诊断对应文件已不存在;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | R1716 | 多个比较可合并为链式比较。 | 3 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | R1719 | if 表达式可以进一步简化。 | 10 | 将布尔三元表达式改为直接条件判断或 not 表达式 | R1719 定向验证通过,退出码 0 | | Pylint | R1721 | 推导式外层包装多余。 | 36 | 将不必要的推导式改为 list(...)、range(...) 或 dict(...) 标准构造 | R1721 定向验证通过,退出码 0 | | Pylint | R1724 | continue 后存在冗余 else。 | 1 | 删除 continue 后的 else 并顺延后续分支 | R1724/R1728/R1729/R1730/R1733/R1736 定向验证通过,退出码 0 | | Pylint | R1728 | 可用生成器替代临时列表。 | 3 | 将 max([...])、tuple([...]) 改为生成器表达式 | R1724/R1728/R1729/R1730/R1733/R1736 定向验证通过,退出码 0 | | Pylint | R1729 | all() 中不需要构造临时列表。 | 21 | 去掉 all([...]) 外层列表,改为生成器表达式 | R1724/R1728/R1729/R1730/R1733/R1736 定向验证通过,退出码 0 | | Pylint | R1730 | 手写条件可用 min() 表达。 | 1 | 将条件赋值改为 axis = min(axis, -1) | R1724/R1728/R1729/R1730/R1733/R1736 定向验证通过,退出码 0 | | Pylint | R1733 | 遍历字典时又通过 key 取值。 | 8 | 改为直接遍历字典 values 并使用当前 value | R1724/R1728/R1729/R1730/R1733/R1736 定向验证通过,退出码 0 | | Pylint | R1736 | 遍历列表时又通过 index 取当前列表元素。 | 4 | 使用 enumerate 得到的元素替代同列表索引访问 | R1724/R1728/R1729/R1730/R1733/R1736 定向验证通过,退出码 0 | | Pylint | R1725 | super() 还在使用显式参数形式。 | 28 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0106 | 表达式求值后没有被使用。 | 2 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0108 | lambda 可以直接用普通函数替代。 | 2 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0122 | 使用了 exec。 | 6 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0123 | 使用了 eval。 | 7 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0127 | 变量被自赋值。 | 1 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0133 | 单独写了异常对象但没有抛出。 | 1 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0201 | 属性在 __init__ 之外定义。 | 2 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0211 | @staticmethod 仍接收实例或类参数。 | 1 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0221 | 重写方法参数与父类不一致。 | 1 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0231 | 子类初始化未调用父类 __init__。 | 2 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0246 | 重写方法只是原样委托给父类。 | 2 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0511 | 代码中保留了 FIXME/TODO 标记。 | 1 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0602 | 使用了 global,但未形成有效全局赋值。 | 8 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0621 | 局部名称遮蔽了外层作用域变量。 | 20 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0622 | 覆盖了 Python 内置名称。 | 259 | 在对应代码处添加 pylint 局部屏蔽;自动生成文件按当前源码 AST 定位;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0631 | 循环变量在循环外被引用。 | 1 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0632 | 解包数量与数据结构不匹配。 | 9 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W0640 | 闭包捕获了循环变量。 | 5 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | | Pylint | W1508 | 环境变量默认值类型不合适。 | 3 | 在对应代码处添加 pylint 局部屏蔽;未新增全局屏蔽配置 | 186 个非生成涉及文件定向验证通过,513 个屏蔽位置静态校验通过 | See merge request: Ascend/torchair!3417 | 2 小时前 | |
fix: block unsafe matmul epilogue fusion Co-authored-by: ling-DT<lingxing@huawei.com> # message auto-generated for no-merge-commit merge: !3415 merge fix/block-unsafe-matmul-epilogue-fusion-v2 into master fix: block unsafe matmul epilogue fusion Created-by: ling-DT Commit-by: ling-DT Merged-by: ascend-robot Description: ## Summary - Block MatMul epilogue fusion when the consumer reads non-contiguous extra inputs or performs concat/reduction-style epilogue patterns. - Keep regular MatMul pointwise epilogue fusion enabled. ## Verification - python3 -m py_compile experimental/_inductor_npu_ext/python/inductor_npu_ext/npu.py - PYTHONPATH=/workspace/lingxing/Code/torchair-20260422/experimental/_inductor_npu_ext/python:$PYTHONPATH python3 -m unittest experimental._inductor_npu_ext.tests.ut.TestInductorNpuExt.test_debug_option_matmul_fuses_bf16_mm_tensor_mul_cpu_debug - AUTO_FUSE_MATMUL_CASE_FILTER=tc_af_tf_support_cv_fusion_0021 python3 /workspace/lingxing/tests/inductor-tests/test_network_fragments.py --fragment tf_autofuse_matmul - AUTO_FUSE_MATMUL_CASE_FILTER=tc_af_tf_support_cv_fusion_0022 python3 /workspace/lingxing/tests/inductor-tests/test_network_fragments.py --fragment tf_autofuse_matmul ## Result - tc_af_tf_support_cv_fusion_0021: pass; MatMul epilogue fusion blocked due to non-contiguous epilogue input. - tc_af_tf_support_cv_fusion_0022: pass; MatMul epilogue fusion blocked due to non-contiguous epilogue input. See merge request: Ascend/torchair!3415 | 5 小时前 | |
docs(inductor_npu_ext): 更新 torch_npu 版本依赖说明为 2.9(支持2.9-2.12) Co-authored-by: dingdairong<dingdairong@huawei.com> # message auto-generated for no-merge-commit merge: !3376 merge doc/readme-update-v2 into master docs(inductor_npu_ext): 更新 torch_npu 版本依赖说明为 2.9(支持2.9-2.12) Created-by: dingdairong Commit-by: dingdairong Merged-by: ascend-robot Description: docs(inductor_npu_ext): 更新 torch_npu 版本依赖说明为 2.9(支持2.9-2.12) See merge request: Ascend/torchair!3376 | 6 天前 |
介绍
inductor-npu-ext 正在为 Inductor 添加一个亲和 NPU 的 Codegen 后端,该后端定位于使用 NPU 上的 SOTA DSL 生成 Inductor 融合 Kernel。
inductor-npu-ext 当前基于 AscendC 生成融合Kernel,同时持续集成 NPU 上的新兴 DSL PTO,以保证融合 Kernel 生成的先进性。

当前的主要工作:
- 支持 Pointwise/Reduction 融合
- 支持水平融合与垂直融合
- 支持动态 Shape
- 支持MM尾声&序幕融合
- SuperKernel融合(一种降低 Device 上 Kernel 调度间隙的技术)
- 静态化编译支持(一种静态shape场景下降低算子头开销的技术)
- 支持需要 Workspace 内存的 Kernel
- PGO(Profiling Guide Optimize)性能寻优
- 基于硬件性能建模的模板&Tiling寻优
- 稳健地扩充支持融合的算子白名单
- 支持离散访存类融合
软件安装
安装torch_npu
inductor-npu-ext 依赖 torch 2.9+ 版本,目前支持torch2.9-2.12版本
pip3 install numpy
pip3 install pyyaml
pip3 install setuptools
pip3 install torch_npu==2.9 # 通过pip安装torch_npu时会自动安装依赖的torch版本
安装CANN主线版本
inductor-npu-ext 依赖 CANN 主线版本。如果您是外部用户,可以联系对应的支撑团队获取安装包。
获取inductor-npu-ext
inductor-npu-ext 已随 torch_npu 打包为 torch_npu/_inductor/ascendc,安装 torch_npu 后即可通过
torch.compile(options={"npu_backend": "ascendc"}) 启用,无需单独安装。
另外,也可通过环境变量 TORCHINDUCTOR_NPU_BACKEND 选择 AscendC 后端:
export TORCHINDUCTOR_NPU_BACKEND="ascendc"
使用约束:此环境变量必须在 import torch 之前设置,否则不生效。
其他环境依赖
- CMake >= 3.16.0
- GCC >= 7.3.0
在 openEuler 系统上,您可以通过以下命令安装:
sudo yum install cmake gcc
在 Ubuntu 系统上,您可以通过以下命令安装:
sudo apt-get install cmake gcc
功能验证
详细的使用说明参见 使用手册。
执行前,需要执行 CANN 安装目录下的 set_env.sh 设置 CANN 相关环境变量
例如CANN安装路径为
/usr/local/Ascend/cann,则执行:
source /usr/local/Ascend/cann/set_env.sh
运行以下代码进行功能验证:
import torch
import torch_npu
@torch.compile(options={"npu_backend": "ascendc"})
def test_add_sum(x, y):
return torch.add(x, y).sum()
x = torch.randn(32, 1024).npu()
y = torch.randn(1, 1024).npu()
out = test_add_sum(x, y)
golden = (x + y).sum()
max_diff = torch.max(torch.abs(out - golden))
assert max_diff < 1e-3, max_diff
print("Succeed")