torchair:基于 PyTorch 生态的昇腾NPU图模式推理扩展库项目

TorchAir 支持用户基于PyTorch框架和torch_npu插件在昇腾NPU上使用图模式进行推理。

分支23Tags0
文件最后提交记录最后更新时间
docs: 修复claude启动时远端skill下载失败问题 Co-authored-by: stevenaw0<huangguijun@huawei.com> # message auto-generated for no-merge-commit merge: !3109 merge plugin into master docs: 修复claude启动时远端skill下载失败问题 Created-by: stevenaw0 Commit-by: stevenaw0 Merged-by: ascend-robot Description: ## 变更内容 1. **新增 AGENTS.md**:中文项目指引文档,包含项目概述、构建命令、测试方法、架构说明、核心 API 等 2. **新增 .claude/CLAUDE.md**:指向 AGENTS.md 的引导文件 3. **下载远端skill的脚本增加可执行权限**:修复claude启动时自动下载失败问题: 4. **.claude/settings.json增加舱内曾删改查权限** ## Checklist - [x] 代码已通过本地测试 - [x] 提交信息符合规范 - [x] 无敏感信息泄露 See merge request: Ascend/torchair!31095 天前
rename .gitee to .gitcode Co-authored-by: stevenaw0<huangguijun@huawei.com> # message auto-generated for no-merge-commit merge: !3111 merge master into master rename .gitee to .gitcode Created-by: stevenaw0 Commit-by: stevenaw0 Merged-by: ascend-robot Description: rename .gitee to .gitcode See merge request: Ascend/torchair!31115 天前
docs: 修复claude启动时远端skill下载失败问题 Co-authored-by: stevenaw0<huangguijun@huawei.com> # message auto-generated for no-merge-commit merge: !3109 merge plugin into master docs: 修复claude启动时远端skill下载失败问题 Created-by: stevenaw0 Commit-by: stevenaw0 Merged-by: ascend-robot Description: ## 变更内容 1. **新增 AGENTS.md**:中文项目指引文档,包含项目概述、构建命令、测试方法、架构说明、核心 API 等 2. **新增 .claude/CLAUDE.md**:指向 AGENTS.md 的引导文件 3. **下载远端skill的脚本增加可执行权限**:修复claude启动时自动下载失败问题: 4. **.claude/settings.json增加舱内曾删改查权限** ## Checklist - [x] 代码已通过本地测试 - [x] 提交信息符合规范 - [x] 无敏感信息泄露 See merge request: Ascend/torchair!31095 天前
add npu_format_cast_via_cpu + add quantmatmul lite converter # message auto-generated for no-merge-commit merge: !3092 merge master into master add npu_format_cast_via_cpu + add quantmatmul lite converter Created-by: zihan0007 Commit-by: zihan0007 Merged-by: ascend-robot Description: 合入来源: torchair 新增npu_format_cast_via_cpu接口: 新增npu_format_cast_via_cpu接口 支持npuTensor在cpu将数据排布从Nd转为Nz,当前支持int8/uint8 Nd输入转为Fractal_nz输出 ge_pass增加QuantBatchMatmulV3前的Bitcast和Transpose算子互换位置的能力,方便后续Transpose融合 增加lite converter支持QuantBatchMatmulV3 A8W4(int4)场景的converter逻辑 See merge request: Ascend/torchair!30926 天前
pre-commit by rule=trailing-whitespace Co-authored-by: guanlongfeng<guanlongfeng1@huawei.com> # message auto-generated for no-merge-commit merge: !2931 merge clean_code into master pre-commit by rule=trailing-whitespace Created-by: glf2016 Commit-by: guanlongfeng Merged-by: ascend-robot Description: pre-commit-clean-code-rule=trailing-whitespace See merge request: Ascend/torchair!29311 个月前
2.12 debug_dump资料修改 Co-authored-by: wangkai<wangkai579@huawei.com> # message auto-generated for no-merge-commit merge: !3138 merge doc_fix into master 2.12 debug_dump资料修改 Created-by: mihudan Commit-by: wangkai Merged-by: ascend-robot Description: 2.12 debug_dump资料修改 See merge request: Ascend/torchair!313819 小时前
pre-commit by rule=trailing-whitespace Co-authored-by: guanlongfeng<guanlongfeng1@huawei.com> # message auto-generated for no-merge-commit merge: !2931 merge clean_code into master pre-commit by rule=trailing-whitespace Created-by: glf2016 Commit-by: guanlongfeng Merged-by: ascend-robot Description: pre-commit-clean-code-rule=trailing-whitespace See merge request: Ascend/torchair!29311 个月前
[Fix] jit_compile fail with \n Co-authored-by: XDaoHong<xudaohong@huawei.com> # message auto-generated for no-merge-commit merge: !3140 merge fix into master [Fix] jit_compile fail with \n Created-by: XDaoHong Commit-by: XDaoHong Merged-by: ascend-robot Description: [Fix] jit_compile fail with \n See merge request: Ascend/torchair!31401 天前
fix docs bug Co-authored-by: hulida<hulida@huawei.com> Co-authored-by: fu-hao-huawei<fuhao16@huawei.com> Co-authored-by: chenweiheng<chenweiheng1@hisilicon.com> Co-authored-by: SunYaping<sunyaping4@huawei.com> Co-authored-by: Achilles_d<duanchengyuan@huawei.com> Co-authored-by: zhukkk<zhuke11@huawei.com> Co-authored-by: tangjie66<tangjie66@huawei.com> # message auto-generated for no-merge-commit merge: !2811 merge ass into master fix docs bug Created-by: Sunyp01 Commit-by: Sunyp01;Achilles_d;fu-hao-huawei;chenweiheng;hulida;tangjie66;zhukkk;SunYaping Merged-by: ascend-robot Description: fix doc bug See merge request: Ascend/torchair!28112 个月前
完善开启debug后对torchair/ex对输入输出信息的打印 Co-authored-by: weizhaoyang<weizhaoyang1@huawei.com> # message auto-generated for no-merge-commit merge: !3114 merge wzy0528 into master 完善开启debug后对torchair/ex对输入输出信息的打印 Created-by: weizhaoyang Commit-by: weizhaoyang Merged-by: ascend-robot Description: 当TORCH_COMPILE_DEBUG设为1,且开启debug模式时 会打印输入输出信息的min max norm mean See merge request: Ascend/torchair!311416 小时前
add npu_format_cast_via_cpu + add quantmatmul lite converter # message auto-generated for no-merge-commit merge: !3092 merge master into master add npu_format_cast_via_cpu + add quantmatmul lite converter Created-by: zihan0007 Commit-by: zihan0007 Merged-by: ascend-robot Description: 合入来源: torchair 新增npu_format_cast_via_cpu接口: 新增npu_format_cast_via_cpu接口 支持npuTensor在cpu将数据排布从Nd转为Nz,当前支持int8/uint8 Nd输入转为Fractal_nz输出 ge_pass增加QuantBatchMatmulV3前的Bitcast和Transpose算子互换位置的能力,方便后续Transpose融合 增加lite converter支持QuantBatchMatmulV3 A8W4(int4)场景的converter逻辑 See merge request: Ascend/torchair!30926 天前
support hif8 for graph Co-authored-by: huangfei<huangfei32@huawei.com> # message auto-generated for no-merge-commit merge: !2145 merge master into master [Feature] [Feature] support hif8 for graph Created-by: dddxhh Commit-by: huangfei Merged-by: ascend-robot Description: <!-- 请根据您的Pull Request类型,保留以下相应的一个模板部分,并删除其他无关部分 --> <!-- 请根据您的Pull Request类型,在Pull request标题中标记[Feature]\[Bugfix]\[Refactor] --> <!-------------------- 新功能模板 BEGIN --------------------> ### **【新功能提交】** **功能描述** support hif8 for graph **相关Issue** <!-- 如有关联的Issue,请在此处填写,例如: [Fixes issue xxx](链接) --> **Checklist** - [x] 符合编程规范&&代码红线 - [x] 具备UT测试用例看护&&测试用例为有效用例(若无测试用例看护请说明原因) - [ ] 是否涉及对外接口变更 - [ ] 是否涉及官网文档修改 <!-------------------- 新功能模板 END --------------------> See merge request: Ascend/torchair!21456 个月前
mmallreduce add comm_mode Co-authored-by: wangkechen<wangkechen3@huawei.com> # message auto-generated for no-merge-commit merge: !3072 merge mmallreduce_commmode into master mmallreduce add comm_mode Created-by: Kiana1216 Commit-by: wangkechen Merged-by: ascend-robot Description: # 【修改方案】 MatmulAllReduce算子torch_npu接口新增comm_mode入参。目前提供用户自选通信引擎功能,通过comm_mode指定,comm_mode支持“ai_cpu”,“ccu”和空字符串“”入参。空字符串为自适应行为,根据芯片型号自行选择较优的通信引擎。 # 【资料变更】 不涉及,在IDP平台修改资料。 # 【接口变更】 torch_npu.npu_mm_all_reduce_base接口新增一个可选参数comm_mode,默认值为None,类型为字符串。 修改接口已经已通过评审,结论同意新增comm_mode入参 # 【功能验证】 本地出包验证。 ![ScreenShot_20260601113842.PNG](https://raw.gitcode.com/user-images/assets/7964479/132a5d6e-2415-4539-89c7-eb396772abdb/ScreenShot_20260601113842.PNG 'ScreenShot_20260601113842.PNG') See merge request: Ascend/torchair!307216 小时前
完善开启debug后对torchair/ex对输入输出信息的打印 Co-authored-by: weizhaoyang<weizhaoyang1@huawei.com> # message auto-generated for no-merge-commit merge: !3114 merge wzy0528 into master 完善开启debug后对torchair/ex对输入输出信息的打印 Created-by: weizhaoyang Commit-by: weizhaoyang Merged-by: ascend-robot Description: 当TORCH_COMPILE_DEBUG设为1,且开启debug模式时 会打印输入输出信息的min max norm mean See merge request: Ascend/torchair!311416 小时前
feat: AlltoAllMatmul AICPU适配 新增通信引擎参数comm_mode Co-authored-by: tangjn<tangjianing@huawei.com> # message auto-generated for no-merge-commit merge: !3118 merge master into master feat: AlltoAllMatmul AICPU适配 新增通信引擎参数comm_mode Created-by: tangjn Commit-by: tangjn Merged-by: ascend-robot Description: feat: 新增通信引擎参数 为了在AlltoAllMatmul和AlltoAllQuantMatmul算子中,支持用户指定HCCL通信引擎(AICPU或CCU),为算子PTA接口新增一个可选入参comm_mode。 [#2777](https://gitcode.com/cann/ops-transformer/issues/2777) See merge request: Ascend/torchair!31184 天前
[feature]npugraph_ex support dead lock check Co-authored-by: chenweiheng<chenweiheng1@hisilicon.com> # message auto-generated for no-merge-commit merge: !2782 merge master into master [feature]npugraph_ex support dead lock check Created-by: chenweiheng Commit-by: chenweiheng Merged-by: ascend-robot Description: [feature]npugraph_ex support dead lock check See merge request: Ascend/torchair!27822 个月前
add npu_format_cast_via_cpu + add quantmatmul lite converter # message auto-generated for no-merge-commit merge: !3092 merge master into master add npu_format_cast_via_cpu + add quantmatmul lite converter Created-by: zihan0007 Commit-by: zihan0007 Merged-by: ascend-robot Description: 合入来源: torchair 新增npu_format_cast_via_cpu接口: 新增npu_format_cast_via_cpu接口 支持npuTensor在cpu将数据排布从Nd转为Nz,当前支持int8/uint8 Nd输入转为Fractal_nz输出 ge_pass增加QuantBatchMatmulV3前的Bitcast和Transpose算子互换位置的能力,方便后续Transpose融合 增加lite converter支持QuantBatchMatmulV3 A8W4(int4)场景的converter逻辑 See merge request: Ascend/torchair!30926 天前
pre-commit by rule=trailing-whitespace Co-authored-by: guanlongfeng<guanlongfeng1@huawei.com> # message auto-generated for no-merge-commit merge: !2931 merge clean_code into master pre-commit by rule=trailing-whitespace Created-by: glf2016 Commit-by: guanlongfeng Merged-by: ascend-robot Description: pre-commit-clean-code-rule=trailing-whitespace See merge request: Ascend/torchair!29311 个月前
feat: add opencode startup plugin Co-authored-by: stevenaw0<huangguijun@huawei.com> # message auto-generated for no-merge-commit merge: !3103 merge plugin into master feat: add opencode startup plugin Created-by: stevenaw0 Commit-by: stevenaw0 Merged-by: ascend-robot Description: ## 变更描述 添加 opencode 启动插件,支持自动安装默认 skills。 ## 变更文件 - .gitignore - 新增忽略项 - .opencode/plugins/install-default-skills.ts - 新增插件实现 ## Checklist - [x] 代码已自测 - [x] 代码符合项目规范 See merge request: Ascend/torchair!31036 天前
update .gitmodules info Co-authored-by: SunYaping<sunyaping4@huawei.com> # message auto-generated for no-merge-commit merge: !2861 merge 0407 into master update .gitmodules info Created-by: Sunyp01 Commit-by: Sunyp01;SunYaping Merged-by: ascend-robot Description: update .gitmodules info See merge request: Ascend/torchair!286126 天前
add npu_format_cast_via_cpu + add quantmatmul lite converter # message auto-generated for no-merge-commit merge: !3092 merge master into master add npu_format_cast_via_cpu + add quantmatmul lite converter Created-by: zihan0007 Commit-by: zihan0007 Merged-by: ascend-robot Description: 合入来源: torchair 新增npu_format_cast_via_cpu接口: 新增npu_format_cast_via_cpu接口 支持npuTensor在cpu将数据排布从Nd转为Nz,当前支持int8/uint8 Nd输入转为Fractal_nz输出 ge_pass增加QuantBatchMatmulV3前的Bitcast和Transpose算子互换位置的能力,方便后续Transpose融合 增加lite converter支持QuantBatchMatmulV3 A8W4(int4)场景的converter逻辑 See merge request: Ascend/torchair!30926 天前
docs: 补充项目概述中 npugraph_ex ACL 图执行路径的描述 Co-authored-by: stevenaw0<huangguijun@huawei.com> # message auto-generated for no-merge-commit merge: !3123 merge add_npugraph_ex into master docs: 补充项目概述中 npugraph_ex ACL 图执行路径的描述 Created-by: stevenaw0 Commit-by: stevenaw0 Merged-by: ascend-robot Description: ## 变更说明 更新 AGENTS.md 项目概述,补充 npugraph_ex 提供的 ACL Graph 捕获执行路径描述,使文档完整反映 TorchAir 的两条图编译后端(GE 全图编译 + ACL 捕获执行)。 ## 变更内容 - 修改 AGENTS.md 第 5 行项目概述,增加 ACL Graph 捕获执行路径说明 See merge request: Ascend/torchair!31233 天前
add npu_format_cast_via_cpu + add quantmatmul lite converter # message auto-generated for no-merge-commit merge: !3092 merge master into master add npu_format_cast_via_cpu + add quantmatmul lite converter Created-by: zihan0007 Commit-by: zihan0007 Merged-by: ascend-robot Description: 合入来源: torchair 新增npu_format_cast_via_cpu接口: 新增npu_format_cast_via_cpu接口 支持npuTensor在cpu将数据排布从Nd转为Nz,当前支持int8/uint8 Nd输入转为Fractal_nz输出 ge_pass增加QuantBatchMatmulV3前的Bitcast和Transpose算子互换位置的能力,方便后续Transpose融合 增加lite converter支持QuantBatchMatmulV3 A8W4(int4)场景的converter逻辑 See merge request: Ascend/torchair!30926 天前
【社区任务】定向文档捉虫 Co-authored-by: gcw_W4lZIdpv<2057260095@qq.com> # message auto-generated for no-merge-commit merge: !2914 merge master into master 【社区任务】定向文档捉虫 Created-by: gcw_W4lZIdpv Commit-by: gcw_W4lZIdpv Merged-by: ascend-robot Description: 【社区任务】定向文档捉虫 See merge request: Ascend/torchair!29141 个月前
pre-commit by rule=trailing-whitespace Co-authored-by: guanlongfeng<guanlongfeng1@huawei.com> # message auto-generated for no-merge-commit merge: !2931 merge clean_code into master pre-commit by rule=trailing-whitespace Created-by: glf2016 Commit-by: guanlongfeng Merged-by: ascend-robot Description: pre-commit-clean-code-rule=trailing-whitespace See merge request: Ascend/torchair!29311 个月前
pre-commit by rule=trailing-whitespace Co-authored-by: guanlongfeng<guanlongfeng1@huawei.com> # message auto-generated for no-merge-commit merge: !2931 merge clean_code into master pre-commit by rule=trailing-whitespace Created-by: glf2016 Commit-by: guanlongfeng Merged-by: ascend-robot Description: pre-commit-clean-code-rule=trailing-whitespace See merge request: Ascend/torchair!29311 个月前
fix docs bug Co-authored-by: hulida<hulida@huawei.com> Co-authored-by: fu-hao-huawei<fuhao16@huawei.com> Co-authored-by: chenweiheng<chenweiheng1@hisilicon.com> Co-authored-by: SunYaping<sunyaping4@huawei.com> Co-authored-by: Achilles_d<duanchengyuan@huawei.com> Co-authored-by: zhukkk<zhuke11@huawei.com> Co-authored-by: tangjie66<tangjie66@huawei.com> # message auto-generated for no-merge-commit merge: !2811 merge ass into master fix docs bug Created-by: Sunyp01 Commit-by: Sunyp01;Achilles_d;fu-hao-huawei;chenweiheng;hulida;tangjie66;zhukkk;SunYaping Merged-by: ascend-robot Description: fix doc bug See merge request: Ascend/torchair!28112 个月前
支持的产品型号添加A5,子功能冗余说明删除 Co-authored-by: wangkai<wangkai579@huawei.com> # message auto-generated for no-merge-commit merge: !3099 merge doc_fix into master 支持的产品型号添加A5,子功能冗余说明删除 Created-by: mihudan Commit-by: wangkai Merged-by: ascend-robot Description: 支持的产品型号添加A5,子功能冗余说明删除 See merge request: Ascend/torchair!30995 天前
torch air framework supported now 2 年前
fix docs bug Co-authored-by: hulida<hulida@huawei.com> Co-authored-by: fu-hao-huawei<fuhao16@huawei.com> Co-authored-by: chenweiheng<chenweiheng1@hisilicon.com> Co-authored-by: SunYaping<sunyaping4@huawei.com> Co-authored-by: Achilles_d<duanchengyuan@huawei.com> Co-authored-by: zhukkk<zhuke11@huawei.com> Co-authored-by: tangjie66<tangjie66@huawei.com> # message auto-generated for no-merge-commit merge: !2811 merge ass into master fix docs bug Created-by: Sunyp01 Commit-by: Sunyp01;Achilles_d;fu-hao-huawei;chenweiheng;hulida;tangjie66;zhukkk;SunYaping Merged-by: ascend-robot Description: fix doc bug See merge request: Ascend/torchair!28112 个月前
!1520 update open source Merge pull request !1520 from 关龙锋/config 1 年前
support all existed asc ops Co-authored-by: medivh<xuepeng4@huawei.com> # message auto-generated for no-merge-commit merge: !2592 merge master into master support all existed asc ops Created-by: medivh-x Commit-by: medivh Merged-by: ascend-robot Description: 按 pyascir.h REGISTERED_OPS / ascir_builtin_ops.cpp 把当前 ascir 已暴露的 pointwise / reduce 算子在 asc_ops.py 补齐 wrapper,覆盖 65 个 op: - unary:三角函数、对数 / 指数族、isnan/isfinite/relu/gelu/leaky_relu、 bitwise_not / logical_not、nop - unary 类型转换:floor_to_int / ceil_to_int / round_to_int / trunc_to_int - binary:minimum / atan2 / copysign / hypot / fmod / mod / remainder / floordiv / truncdiv / axpy / bitwise_or/xor / xor / logical_and/or/xor / lshift / rshift(+ 别名) - ternary:fma / select / clip_by_value 补齐后 NPUOverrides 中 ir.tanh / ir.cos / ir.atan2 等不再走 __getattr__ 回退到 _unsupported_op,能真实落到 ascir。 lowering 白名单同步放开:aten.log1p / aten.relu / aten.sgn / aten.sign。 其中 sgn 在实数路径下 inductor 把它 decompose 成 ops.sign,所以两个都要放行。 _finetune_decompose 白名单从单 _to_copy 扩成额外保留 aten.silu / aten.sgn 两个 OpOverloadPacket 的全部 overload —— inductor 没给这两个 op 注册直接 lowering,必须靠 decomposition 拆成 NPUOverrides 支持的原子 op: - silu(x) = x / (1 + (-x).exp()) → neg/exp/add/div - sgn(x) → sign(x)(实数路径) 否则 cpu 模式(不带 'decompose' / 'lowering' flag)下整个 op 进 lowering 找不到实现,会 fallback 回 aten。 不含 Gather / Concat / IndexExpr —— 这几个 ascir 当前实现有问题,留给 _unsupported 回退或上层自定义 lowering。 See merge request: Ascend/torchair!25925 天前
optimize torchair and pta ci time Co-authored-by: guanlongfeng<guanlongfeng1@huawei.com> # message auto-generated for no-merge-commit merge: !2987 merge ci_times into master optimize torchair and pta ci time Created-by: glf2016 Commit-by: guanlongfeng Merged-by: ascend-robot Description: optimize torchair and pta ci time See merge request: Ascend/torchair!29871 个月前
add release/ut/st ci build and coverage generate 2 年前
pre-commit by rule=trailing-whitespace Co-authored-by: guanlongfeng<guanlongfeng1@huawei.com> # message auto-generated for no-merge-commit merge: !2931 merge clean_code into master pre-commit by rule=trailing-whitespace Created-by: glf2016 Commit-by: guanlongfeng Merged-by: ascend-robot Description: pre-commit-clean-code-rule=trailing-whitespace See merge request: Ascend/torchair!29311 个月前
optimize torchair and pta ci time Co-authored-by: guanlongfeng<guanlongfeng1@huawei.com> # message auto-generated for no-merge-commit merge: !2987 merge ci_times into master optimize torchair and pta ci time Created-by: glf2016 Commit-by: guanlongfeng Merged-by: ascend-robot Description: optimize torchair and pta ci time See merge request: Ascend/torchair!29871 个月前
!1153 固定使用third party下的头文件 & 解决本地UT内存占用过大被kill问题 Merge pull request !1153 from 薛鹏/master 1 年前
fix docs bug Co-authored-by: hulida<hulida@huawei.com> Co-authored-by: fu-hao-huawei<fuhao16@huawei.com> Co-authored-by: chenweiheng<chenweiheng1@hisilicon.com> Co-authored-by: SunYaping<sunyaping4@huawei.com> Co-authored-by: Achilles_d<duanchengyuan@huawei.com> Co-authored-by: zhukkk<zhuke11@huawei.com> Co-authored-by: tangjie66<tangjie66@huawei.com> # message auto-generated for no-merge-commit merge: !2811 merge ass into master fix docs bug Created-by: Sunyp01 Commit-by: Sunyp01;Achilles_d;fu-hao-huawei;chenweiheng;hulida;tangjie66;zhukkk;SunYaping Merged-by: ascend-robot Description: fix doc bug See merge request: Ascend/torchair!28112 个月前

简介

本项目开发了名为TorchAir(Torch Ascend Intermediate Representation)的扩展库,支持用户基于PyTorch框架和torch_npu插件在昇腾NPU上使用图模式进行推理。 TorchAir继承自PyTorch框架Dynamo模式,将PyTorch的FX图转换为GE计算图,并提供了GE计算图在昇腾NPU的编译与执行的能力。

  • 如果您想了解如何使用TorchAir,可以优先通过访问TorchAir图模式使用指南,了解关于TorchAir的更多信息。
  • 如果您计划为TorchAir贡献代码,请参考README内容。

安装与卸载

1.安装

  • 安装依赖

在安装TorchAir之前,请参考版本配套表支持型号说明,确保您的硬件能够使用TorchAir,并安装最新昇腾软件栈。

  • 编译准备

克隆TorchAir代码仓

git clone https://gitcode.com/ascend/torchair.git

下载依赖三方库

cd torchair
git submodule update --init --recursive

配置编译环境,执行配置命令

配置只需要进行一次,用于获取pytorch的编译选项(如当前的torch是否开启ABI)及Ascend sdk的安装路径(如果需要在本地CPU上进行调试)。

cd ./torchair
bash ./configure

默认情况下,执行上述命会弹出如下的交互式会话窗口

您的会话可能有所不同。

Please specify the location of python with available torch 2.1.x installed. [Default is /usr/bin/python3]
(You can make this quiet by set env [TARGET_PYTHON_PATH]):

此时,要求您输入安装了 Torch 2.1 版本的python解释器路径,如果默认路径是正确的,直接回车,否则请输入正确的 python 解释器路径。

您可以通过设置 TARGET_PYTHON_PATH 环境变量,来抑制交互式窗口弹出,但是要确保路径是有效的,否则,仍然会要求您输入正确的 python 解释器路径。

键入后,会耗费几秒钟以确保您的输入是有效的,接着,会弹出下面的交互式窗口

Specify the location of ascend sdk for debug on localhost or leave empty.
(You can make this quiet by set env [ASCEND_SDK_PATH]):

如果您不需要在本地CPU模拟执行,可以直接回车跳过。否则,需要输入昇腾处理器开发套件的安装路径(默认安装路径通常为~/Ascend/ascend-toolkit/latest/)。

您可以通过设置 ASCEND_SDK_PATH 环境变量指定 SDK 目录 或 设置 NO_ASCEND_SDK 环境变量指定不需要 SDK 来抑制交互式窗口弹出。

键入后,等待配置完成。

  • 编译

执行以下命令,编译生成TorchAir安装包:

mkdir build
cd build
cmake ..
make torchair -j8
  • 安装

编译完成后,会在build/dist/dist/目录下生成名为torchair-{version}-py3-none-any.whl的安装包文件。

您可以直接使用pip安装该安装包,或者使用make命令安装至您configure时指定的python环境中。

make install_torchair

2.卸载

torchair的卸载只需要执行命令:

pip3 uninstall torchair

如需要保存卸载日志,可在pip3 uninstall命令后面加上参数--log <PATH>,并对您指定的目录<PATH>做好权限管控。

快速上手

如果您在配置时未指定Ascend sdk的安装路径,则无法执行CPU上的调试,需要在NPU环境上进行测试。

CPU调试时,需要设置LD_LIBRARY_PATH到生成的fake so文件目录以及sdk目录

tools/env.sh会根据配置生成对应的LD_LIBRARY_PATH(如果您在配置时指定了Ascend sdk安装路径)

source tools/env.sh

执行以下python脚本快速验证TorchAir基本功能

import torch
import torchair

config = torchair.CompilerConfig()
npu_backend = torchair.get_npu_backend(compiler_config=config)

class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x, y):
        return torch.add(x, y)

model = Model()
model = torch.compile(model, backend=npu_backend, dynamic=False)
x = torch.randn(2, 2)
y = torch.randn(2, 2)
model(x, y)

特性介绍

TorchAir常用特性如下,全量特性介绍请访问docs获取详细教程。

特性功能 功能介绍
日志功能 日志功能
graph dump功能 图dump功能
dynamo export功能 air格式图导出功能
data dump功能 精度数据dump功能
graph fusion功能 用户自定义关闭/开启部分融合算子功能
experimental性能提升功能 试验性质功能,不同功能适用于特定场景,详见参考资料
converter功能拓展 用户自行扩展模型中缺失的converter功能
支持的aten API清单 支持的aten API清单

版本配套表

本项目与PyTorch、torch_npu、CANN以及Python的版本匹配详情如下:

TorchAir版本 PyTorch版本 torch_npu版本 CANN版本 Python版本
master(主线) 2.6.0 + 在研版本 在研版本 Python3.9.x / Python3.10.x / Python3.11.x / Python3.12.x
7.3.0 2.6.0 / 2.7.1 / 2.8.0 7.3.0 8.5.0 Python3.9.x / Python3.10.x / Python3.11.x
7.3.0 2.9.0 7.3.0 8.5.0 Python3.9.x / Python3.10.x / Python3.11.x / Python3.12.x
7.2.0 2.1.0 7.2.0 8.3.RC1 Python3.8.x / Python3.9.x / Python3.10.x / Python3.11.x
7.2.0 2.6.0 / 2.7.1 / 2.8.0 7.2.0 8.3.RC1 Python3.9.x / Python3.10.x / Python3.11.x
7.1.0 2.1.0 7.1.0 8.2.RC1 Python3.8.x / Python3.9.x / Python3.10.x / Python3.11.x
7.1.0 2.5.1 / 2.6.0 7.1.0 8.2.RC1 Python3.9.x / Python3.10.x / Python3.11.x
7.0.0 2.1.0 / 2.3.1 / 2.4.0 7.0.0 8.1.RC1 Python3.8.x / Python3.9.x / Python3.10.x / Python3.11.x
7.0.0 2.5.1 7.0.0 8.1.RC1 Python3.9.x / Python3.10.x / Python3.11.x

支持的型号

  • Ascend 950PR/Ascend 950DT
  • Atlas A3 训练系列产品/Atlas A3 推理系列产品
  • Atlas A2 训练系列产品/Atlas A2 推理系列产品

贡献

如果您计划为TorchAir做出贡献,请参考CONTRIBUTING

联系我们

安全声明

TorchAir安全声明参考SECURITY_README文件。

许可证

TorchAir插件使用BSD许可证。详见LICENSE文件。


免责声明

致TorchAir使用者

  1. TorchAir提供的模型仅供您用于非商业目的。
  2. 对于各模型,TorchAir平台仅提示性地向您建议可用于训练的数据集,华为不提供任何数据集,如您使用这些数据集进行训练,请您特别注意应遵守对应数据集的License,如您因使用数据集而产生侵权纠纷,华为不承担任何责任。
  3. 如您在使用TorchAir模型过程中,发现任何问题(包括但不限于功能问题、合规问题),请在GitCode提交issue,我们将及时审视并解决。

致数据集所有者

如果您不希望您的数据集在TorchAir中的模型被提及,或希望更新TorchAir中的模型关于您的数据集的描述,请在GitCode提交issue,我们将根据您的issue要求删除或更新您的数据集描述。衷心感谢您对TorchAir的理解和贡献。

项目介绍

TorchAir 支持用户基于PyTorch框架和torch_npu插件在昇腾NPU上使用图模式进行推理。

定制我的领域

下载使用量

0

项目总下载次数(含Clone、Pull、 zip 包及 release 下载),每日凌晨更新

语言类型

Python95.67%
C++3.8%
CMake0.34%
Shell0.12%
TypeScript0.06%