已开启
[Bug]: 使用 transfer_to_npu 时 torch.Stream.record_event 报错 "expected event to be a torch.Event object" #4433
wuyouqi1创建于 11 天前
11 天前 添加了label:bug
11 天前 添加了label:triage-review
TorchNPU-Bot
11 天前 评论:
11 天前 评论:
issue待分派,添加triage-review标签


11 天前 将 wuyouqi1 设为负责人
11 天前 添加了label:bot-triaged;删除了label:triage-review
TorchNPU-Bot
11 天前 评论:
11 天前 评论:
检测到当前 issue 已关联 PR,自动添加标签:bot-triaged


在提交新问题之前,请确保您已经在社区中搜索过相关问题,并使用了社区中提供的资源/工具后,仍未找到满意的解决方式。
⚠️ 安全信息提醒:请仔细检查提供的文本内容,确保其不包含敏感数据信息,包括但不限于:
在分享配置信息或代码示例时,请将敏感信息脱敏处理,或使用
<TOKEN>等占位符替代原有内容。环境信息
🐛 问题描述
import torch
from torch_npu.contrib import transfer_to_npu
e = torch.Event()
s = torch.Stream(torch.device("npu"))
s.record_event(e)
报错:
RuntimeError: expected event to be a torch.Event object
根因:torch 2.13 新增的 torch.Stream.record_event 在 C++ 侧以精确类型匹配校验入参(Py_TYPE(event) == THPEventClass,torch/csrc/Stream.cpp),拒绝子类实例;而 transfer_to_npu 将 torch.Event 替换为子类代理 _EventProxy(用于改写 device='cuda'→'npu'),导致校验失败。
期望行为:torch.Event() 创建的事件可正常传入 record_event。不使用 transfer_to_npu 时同样代码可正常执行。
欢迎加入社区,感谢您对社区的贡献 🎉!