在提交新问题之前,请确保您已经在社区中搜索过相关问题,并使用了社区中提供的资源/工具后,仍未找到满意的解决方式。
torch.npu.is_available()
True
unset TORCH_DEVICE_BACKEND_AUTOLOAD
本次按照 torch.compile 体验 TorchAir-GE。实际验证中,下面几种情况的行为不同:
torch.compile
python -c "import torchair"
ModuleNotFoundError: No module named 'torchair'
set_env.sh
torchair
torch
torch_npu
torchair.get_npu_backend()
因此,当前证据不能说明 TorchAir-GE 功能存在确定性缺陷,但说明使用者不容易从入口文档判断以下前提:
TORCH_DEVICE_BACKEND_AUTOLOAD
ModuleNotFoundError
cd "/workspace/pytorch-ecosystem/01_tasks/2026/torch_npu_public_beta/Aimermo/任务2-torch.compile体验与实践" source /workspace/torch312/bin/activate source /usr/local/Ascend/cann-9.1.0/set_env.sh unset TORCH_DEVICE_BACKEND_AUTOLOAD python --version python -c "import torch; print('torch:', torch.__version__); print('npu available:', torch.npu.is_available())" python -c "import torch_npu; print('torch_npu:', torch_npu.__version__)" python -c "import torchair; print('torchair entry:', torchair)"
然后在同一环境中执行推荐入口检查:
python - <<'PY' import torch import torch_npu import torchair print("torch:", torch.__version__) print("torch_npu:", torch_npu.__version__) print("npu available:", torch.npu.is_available()) print("torchair entry:", torchair) print("TorchAir-GE backend:", torchair.get_npu_backend()) PY
import torch import torch_npu import torchair print("torch:", torch.__version__) print("torch_npu:", torch_npu.__version__) print("npu available:", torch.npu.is_available()) print("torchair entry:", torchair) print("TorchAir-GE backend:", torchair.get_npu_backend())
单独导入入口时,实际出现过:
Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'torchair'
先导入 torch、torch_npu,再导入 torchair 后,实际输出过:
torch: 2.12.0+cu130 torch_npu: 2.12.0 npu available: True torchair entry: <torch_npu.dynamo._LazyTorchair object at ...> TorchAir-GE backend: functools.partial(...)
之后的端到端测试实际输出过:
Test: TorchAir-GE Model: torch_multimodal_clip Backend: TorchAir-GE PyTorch: 2.12.0+cu130 TorchNPU: 2.12.0 Device: npu:0 Eager average time: 0.000303 s First compiled call time: 3.649342 s Compiled average time: 0.000919 s Correctness: PASS (max_abs_diff=8.941e-08) Performance: PASS
文档应给出一组经过验证的完整命令,明确说明:
建议在 TorchAir-GE 快速开始文档中增加如下可直接复制的检查步骤,并解释每一步的作用:
source <CANN安装目录>/set_env.sh source <Python虚拟环境>/bin/activate unset TORCH_DEVICE_BACKEND_AUTOLOAD python - <<'PY' import torch import torch_npu import torchair assert torch.npu.is_available() backend = torchair.get_npu_backend() print("TorchAir-GE backend:", backend) PY
同时建议补充入口提供关系、导入顺序和各类错误的排查表。
欢迎加入社区,感谢您对社区的贡献 🎉!
检测到社区任务相关 issue,自动添加标签:help-wanted
help-wanted
在提交新问题之前,请确保您已经在社区中搜索过相关问题,并使用了社区中提供的资源/工具后,仍未找到满意的解决方式。
环境信息
环境信息
torch.npu.is_available()返回Trueunset TORCH_DEVICE_BACKEND_AUTOLOAD使用场景及问题
问题描述
本次按照
torch.compile体验 TorchAir-GE。实际验证中,下面几种情况的行为不同:python -c "import torchair"时得到ModuleNotFoundError: No module named 'torchair';set_env.sh后,单独导入torchair仍然不能完成检查;torch、torch_npu,再导入torchair,并执行torchair.get_npu_backend()后,入口可以工作;因此,当前证据不能说明 TorchAir-GE 功能存在确定性缺陷,但说明使用者不容易从入口文档判断以下前提:
torchair是独立安装包,还是torch_npu提供的顶层延迟加载入口;set_env.sh;torch_npu,再导入torchair;TORCH_DEVICE_BACKEND_AUTOLOAD是否需要取消设置;ModuleNotFoundError时,应该先检查哪一层环境。独立复现步骤
cd "/workspace/pytorch-ecosystem/01_tasks/2026/torch_npu_public_beta/Aimermo/任务2-torch.compile体验与实践" source /workspace/torch312/bin/activate source /usr/local/Ascend/cann-9.1.0/set_env.sh unset TORCH_DEVICE_BACKEND_AUTOLOAD python --version python -c "import torch; print('torch:', torch.__version__); print('npu available:', torch.npu.is_available())" python -c "import torch_npu; print('torch_npu:', torch_npu.__version__)" python -c "import torchair; print('torchair entry:', torchair)"然后在同一环境中执行推荐入口检查:
python - <<'PY' import torch import torch_npu import torchair print("torch:", torch.__version__) print("torch_npu:", torch_npu.__version__) print("npu available:", torch.npu.is_available()) print("torchair entry:", torchair) print("TorchAir-GE backend:", torchair.get_npu_backend()) PY最小复现代码
import torch import torch_npu import torchair print("torch:", torch.__version__) print("torch_npu:", torch_npu.__version__) print("npu available:", torch.npu.is_available()) print("torchair entry:", torchair) print("TorchAir-GE backend:", torchair.get_npu_backend())实际输出
单独导入入口时,实际出现过:
先导入
torch、torch_npu,再导入torchair后,实际输出过:之后的端到端测试实际输出过:
预期结果
文档应给出一组经过验证的完整命令,明确说明:
torch、torch_npu、torchair的推荐导入顺序;torchair.get_npu_backend()的入口来源和适用版本;TORCH_DEVICE_BACKEND_AUTOLOAD是否需要设置或取消;建议
建议在 TorchAir-GE 快速开始文档中增加如下可直接复制的检查步骤,并解释每一步的作用:
source <CANN安装目录>/set_env.sh source <Python虚拟环境>/bin/activate unset TORCH_DEVICE_BACKEND_AUTOLOAD python - <<'PY' import torch import torch_npu import torchair assert torch.npu.is_available() backend = torchair.get_npu_backend() print("TorchAir-GE backend:", backend) PY同时建议补充入口提供关系、导入顺序和各类错误的排查表。
欢迎加入社区,感谢您对社区的贡献 🎉!