已关闭
[Usage]:对yolov5进行推理时,报错AssertionError: Guard check failed: 5/0: tensor '___from_numpy(x)' dispatch key set mismatch. expected DispatchKeySet(CPU, BackendSelect, ADInplaceOrView), actual DispatchKeySet #451
明韫创建于  4月24日关闭于  6月25日
明韫
明韫
4月24日 创建

在提交问题之前,请通过搜索现有和历史问题确保该问题尚未被提出并解决。

您的环境信息

-- CANN 版本: 8.5.0  
-- Pytorch/Torch_npu 版本 : 2.8.0
-- Python 版本 : 3.11.15
-- 操作系统版本: ubuntu 20.04

您希望如何在昇腾(Ascend)上使用 TorchAir?

我想使用Torchair的图模式实现小模型(例如 yolov5等)在昇腾NPU上的在线推理加速,但是我不知道如何使用。

感谢您的贡献 🎉!

likedislike
ascend-robotascend-robot成员
4月24日 添加了label:usage
gleaming-spark成员
4月24日 评论:

模型在eager模式下执行是否ok?

likedislike
rich
rich成员
4月25日 评论:

用户你好,可以参考使用示例npugraph_ex/quick_start.md
先确保使用eager模式(不使用torch.compile)能正常执行,再使用torch.compile 进行图编译

likedislike
明韫
明韫
5月7日 评论:

模型在eager模式下执行是否ok?

@gleaming-spark
eager模式下是可以正常执行的

likedislike
明韫
明韫
5月7日 评论:

用户你好,可以参考使用示例npugraph_ex/quick_start.md
先确保使用eager模式(不使用torch.compile)能正常执行,再使用torch.compile 进行图编译

@rich9527

参考了给定案例,配置了 npugraph_ex 仍然不行
确定在eager模型下是能正常执行的,但是使用torch.complie进行图编译就会报错

likedislike
SunYapingSunYaping成员
5月30日 将 gleaming-spark 设为负责人
SunYapingSunYaping成员
5月30日 将 rich9527 设为负责人
rich
rich成员
5月30日 评论:

用户您好,这个错误是 torch dynamo guard check 阶段,torch.from_numpy(x) 生成的 tensor 的 dispatch key 与预期不匹配。
Dynamo/Compile 模式:首次 trace 时会记录每个 tensor 的 dispatch key set 作为 guard。后续 replay 时如果同一个 from_numpy(x) 产生的 tensor dispatch key 与 trace 时不一致(比如 trace 时是 CPU,replay 时变成了 NPU),guard check 就会失败抛出 AssertionError。

可以保持其他配置不变,设置backend="aot_eager",例: torch.compile(backend="aot_eager")。进一步定界问题。

likedislike
SunYapingSunYaping成员
6月25日 issue状态由 TODO 改变为 DONE
SunYapingSunYaping成员
6月25日 关闭了 issue
ascend-robotascend-robot成员
6月25日 添加了label:resolved