Pull Request已成功合入, 合并人@ascend-robot
(感谢 zzzyh22 的贡献)Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/op-plugin | ✅ yang-binrong, daifu1234567 (2/2) | ✅ yang-binrong (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)


问题/功能描述
本次PR旨在优化两个稀疏注意力算子(LightningIndexer和SparseFlashAttention)的内存使用效率。核心问题是,在不需要某些输出(如sparse_values_out、softmax_lse)时,原有的算子逻辑仍会为其分配全尺寸的内存空间,造成了不必要的内存浪费。
修改方案描述
本次修改的核心方案是引入条件判断,根据运行时参数动态决定是否分配输出张量的存储空间。具体包括:1)在LightningIndexer算子中,新增return_value参数,当其为false时,sparse_values_out张量将分配一个空张量而非全尺寸张量。2)在SparseFlashAttention算子中,将softmax_max和softmax_sum中间张量的分配逻辑改为依赖return_softmax_lse参数,同样在不需要时分配空张量。此外,为提高代码可读性,引入了常量定义。


/lgtm


/approve


Review Guide
This pull-request passes review.
Committers who wrote a comment of /approve are: yang-binrong.
Reviewers who wrote a comment of /lgtm are: yang-binrong, daifu1234567.


【合入来源】
【修改方案】
【资料变更】
【接口变更】
【功能验证】
【CheckList】