Merged
docs: add torch.nn.attention.flex_attention.or_masks support status #43375
zhangjiahao-2026Add on Jul 30
docs: add torch.nn.attention.flex_attention.or_masks support status #43375
Merged
Pull Request has been successfully merged by ascend-robot.
(Thank you for zhangjiahao-2026's contribution.)Jul 30 Created pull request, commit 61466a16
Jul 30 Associated issue: 【社区任务】7月社区任务第三期-Ascend for PyTorch API 一致性开发(180)
atomgit-bot
Jul 30 Comments:
Jul 30 Comments:
变更摘要
本次 PR 是一个纯资料更新,为五个版本的中文 API 支持表补齐 torch.nn.attention.flex_attention.or_masks 的支持状态。该接口是 FlexAttention 的 mask 组合工具函数(纯 Python,非计算类 API),用于将多个 mask_mod 组合为逻辑或(union)结果。所有五个版本均标记为"支持",无限制说明,无数据类型要求。
主要改动
- 在
docs/zh/api/native_api/pytorch_2-7-1/torch-nn.md中新增支持条目:添加torch.nn.attention.flex_attention.or_masks行,标记支持为"是",限制与说明和数据类型均为"-" - 在
docs/zh/api/native_api/pytorch_2-9-0/torch-nn.md中新增支持条目:同上,补齐该版本对or_masks的支持状态 - 在
docs/zh/api/native_api/pytorch_2-10-0/torch-nn.md中新增支持条目:同上,补齐该版本的支持信息 - 在
docs/zh/api/native_api/pytorch_2-11-0/torch-nn.md中新增支持条目:同上,补齐该版本的支持信息 - 在
docs/zh/api/native_api/pytorch_2-12-0/torch-nn.md中新增支持条目:同上,补齐该版本的支持信息


Incorrect?
ascend-robot
Jul 30 Comments:
Jul 30 Comments:
atomgit-bot
Jul 30 Comments:
Jul 30 Comments:
663 messages are collapsed here。 See more
Oct 10 Resolved final issue
Oct 10 Closed associated issue
Oct 10 Merged pull request
ascend-robot
Oct 10 Comments:
Oct 10 Comments:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


AtlasAccount
Oct 10 Comments:
Oct 10 Comments:
流水线 pytorch_gitcode_PR_multiVersion-onetrack#315 [ commitID:276060f0 ] 已完成


【合入来源】
关联任务issue: https://gitcode.com/Ascend/pytorch/issues/3293
【修改方案】
在 master 资料中为公开非计算类 API
torch.nn.attention.flex_attention.or_masks补齐支持情况。修改文件:
具体修改内容:
torch.nn.attention.flex_attention.or_masks条目;BlockMask Utilities,并放置在BlockMask之前;本PR仅补充目标API的资料,不批量修改同一文件中其他历史API的资料格式。
【资料变更】
资料检查结果:此前 master 下的原生 API 资料未收录
torch.nn.attention.flex_attention.or_masks,因此需要补充。本次在以下版本目录的
torch-nn-attention.md中新增支持情况:该API为公开非计算类纯Python接口,与张量数据类型无关,不填写数据类型限制。文档条目按照PyTorch官方资料的层级和顺序归入
BlockMask Utilities。【接口变更】
不涉及
【功能验证】
torch.nn.attention.flex_attention.or_masks(*mask_mods)用于组合一个或多个mask_mod,返回一个新的掩码函数,并对所有输入mask的返回结果执行逻辑或。PyTorch官方社区在以下用例中已有
or_masks基本逻辑或语义验证:or_masks为纯Python组合接口,不包含NPU专属kernel或设备分支,不需要修改Torch-NPU功能实现,也不需要新增测试文件或
test_upstreampatch。API功能、社区用例情况、NPU适配分析和各版本验证结果见说明Issue:
https://gitcode.com/Ascend/pytorch/issues/4082
A5硬件验证信息如下。
验证设备:

验证环境:
验证命令:
验证场景:
mask_mod返回True和False;mask_mod执行逻辑或;mask_mod返回位于NPU上的bool标量False;RuntimeError;torch.bool,设备类型为npu。运行截图:

验证结论:
torch.nn.attention.flex_attention.or_masks在上述A5环境中运行正常,单mask、多mask、零mask和异常入参场景均验证通过,返回类型及返回设备符合PyTorch实现。
【CheckList】