已合并
remove extra transpose in bmm by restore the stride(0) of input whose batch size is 1 #5288
XianglongZeng创建于 6月27日
remove extra transpose in bmm by restore the stride(0) of input whose batch size is 1 #5288
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 XianglongZeng 的贡献)6月27日 创建了 pull request,commit fb2790bb
ascend-robot
6月27日 评论:
6月27日 评论:
6月27日 添加了label:ascend-cla/yes
6月27日 添加了label:needs-issue
ascend-robot
6月27日 评论:
6月27日 评论:
此处折叠了53条消息 查看更多
6月30日 合入了pull request
ascend-robot
6月30日 评论:
6月30日 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


ascend-robot
6月30日 评论:
6月30日 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


ascend-robot
6月30日 评论:
6月30日 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


ascend-robot
6月30日 评论:
6月30日 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


【合入来源】
【修改方案】
对于>=3D@>=3D、2D@>=3D 、>=3D@2D 且3D 输入前n-1维不连续(比如由转置得到)时,走进 bmm。进一步地,bmm内对输入固定会有对前n-2维的reshape操作,若reshape后 batch维为1 (2D 输入恒为 batch=1,≥3D 输入要求前 n-2 维全为 1)且reshape的tensor是由转置得到,则由于size(0)==1 时 stride(0) 任意值都"合法",torch 会取巧设为 stride(1)*size(1) ,此时该tensor会变成对cann来说非标准的转置tensor,所以引入了额外的transpose。比如对与a[16, 12].T @ b [1,14384,16].T ,转置后的b会被reshape 成 [1,16,14384] 。虽然 shape 没变,但 reshape 仍会重新计算 stride——对 size(0)==1 的维度,把 stride(0) 规范化为 stride(1)*size(1)=1*16=16 ,而不是保留原始的 229344,最后stride变成[16,1,16]。
对于这种情况,在bmm适配层对 size(0)==1 且矩阵维转置布局( stride(1)==1 && stride(2)==size(1) )且 stride(0) != size(1)*size(2) 的张量,用 as_strided 把 stride(0) 规范化为 size(1)*size(2) ,还原为cann所接受的标准转置tensor,从而消除transpose。
【资料变更】
不涉及
【接口变更】
不涉及
【功能验证】
单算子验证脚本:
修改前:




修改后:
新增ut用例的执行结果:
【CheckList】