已开启
[Feature]: add NPU AMP autocast dispatch and HOP integration for flex attention #3824
liuyutong创建于  8月7日
liuyutong
liuyutong成员
8月7日 创建

提交提案之前,请先检索仓库内是否已有相同的提案,如已有请在同一提案中进行讨论。

💻 需求背景、当前现状、期望实现的功能内容、具体的设计方案、以及测试方案

FlexAttention 在 NPU 上无法使用 torch.autocast 混合精度

现象

torch.nn.attention.flex_attention 在 NPU 设备上,当 torch.autocast(device_type="npu", dtype=torch.bfloat16) 激活时,抛出:

RuntimeError: could not find kernel for HigherOrderOperator flex_attention
at dispatch key DispatchKey.AutocastPrivateUse1

根因

  1. PyTorch 仅为 AutocastCUDA / AutocastCPU 注册 flex_attention HOP 的 autocast kernel,AutocastPrivateUse1(NPU)未注册
  2. _validate_device 为空实现,未对 NPU 设备做校验

修复

  • 注册 AutocastPrivateUse1 HOP kernel
  • 补全 device validation
  • 新增eager模式和autocast验收测试

影响

NPU 上大模型可在eager模式和GPU行为保持一致,然后eager和inductor模式都能正常使用混合精度训练/推理。

替代方案

补充说明

欢迎加入社区,感谢您对社区的贡献 🎉!

likedislike
liuyutongliuyutong成员
8月7日 关联了看板:FrameworkPTAdapter 版本issue看板
ascend-robotascend-robot成员
8月7日 添加了label:feature
liuyutongliuyutong成员
8月7日 关联了pull request:feat: add NPU AMP autocast dispatch and HOP integration for flex attention
TorchNPU-BotTorchNPU-Bot成员
8月7日 添加了label:bot-triaged
TorchNPU-Bot
TorchNPU-Bot成员
8月7日 评论:

检测到当前 issue 已关联 PR,自动添加标签:bot-triaged

likedislike
liuyutongliuyutong成员
29 天前 关联了pull request:feat: add autocast registration for flex_attention both eager and inductor
liuyutongliuyutong成员
27 天前 修改了issue 的描述
liuyutongliuyutong成员
26 天前 关联了pull request:feat: add autocast registration for flex_attention both eager and inductor
liuyutongliuyutong成员
26 天前 关联了pull request:feat: add autocast registration for flex_attention both eager and inductor
liuyutongliuyutong成员
26 天前 关联了pull request:feat: add autocast registration for flex_attention both eager and inductor
liuyutongliuyutong成员
6 天前 关联了pull request:feat(flex_attention): autocast registration + device validation via PatchManager
liuyutongliuyutong成员
6 天前 关联了pull request:feat(flex_attention): autocast registration + device validation via PatchManager