Merged
feat(mhc_pre_sinkhorn_backward): 确定性路径支持TND(3D)格式输入 #9519
feat(mhc_pre_sinkhorn_backward): 确定性路径支持TND(3D)格式输入 #9519
Merged
liangtongxueAdd on Aug 3
Total: 14 files changed+1202-379
@@ -164,14 +164,27 @@
164 164 
165## 约束说明165## 约束说明
166 166 
167-sumOut的shape记为(2*sk_iter_count,B,S,N)167+输入支持两种维度格式:BSND(4维)和TND(3维)。其中T = B × S,表示所有Batch序列长度的累加和。各输入/输出在两种格式下的shape对应关系如下:
168-x的shape记为(B,S,N,C)168+ 
169-gradHRes的shape记为(B,S,N*N)或(B,S,N,N)169+| 参数 | BSND(4维) | TND(3维) |
170-phi和gradPhi的shape记为(2N+N^2, N*C)170+| :--- | :--- | :--- |
171+| gradHin | (B,S,C) | (T,C) |
172+| gradHPost | (B,S,N) | (T,N) |
173+| gradHRes | (B,S,N*N) | (T,N*N) |
174+| x | (B,S,N,C) | (T,N,C) |
175+| hPre | (B,S,N) | (T,N) |
176+| hcBeforeNorm | (B,S,N*N+2*N) | (T,N*N+2*N) |
177+| invRms | (B,S,1) | (T,1) |
178+| sumOut | (2*sk_iter_count,B,S,N) | (2*sk_iter_count,T,N) |
179+| normOut | (2*sk_iter_count,B,S,N,N) | (2*sk_iter_count,T,N,N) |
180+| gradX | (B,S,N,C) | (T,N,C) |
181+ 
182+phi和gradPhi的shape记为(2N+N^2,N*C),不受维度格式影响。
171 183 
172- `sk_iter_count`当前仅支持`20`。184- `sk_iter_count`当前仅支持`20`。
173-- `N`当前仅支持`4`。185+- `N`当前支持大于0且不超过`8`。
174-- `C`大于0小于100000且可以被128整除。186+- `C`大于0、小于100000且可以被128整除。
187+- 所有带B/S维度的输入需保持维度格式一致(同为4维BSND或同为3维TND)。
175 188 
176## 调用说明189## 调用说明
177 190 
@@ -61,7 +61,7 @@
61 61 
62 - **输出组合梯度计算**:62 - **输出组合梯度计算**:
63 63 
64- - **正向计算公式**:其中 $\mathbf{x}$ 为输入参数(前向输入x),$\mathbf{hPre}$ 为输入参数(前向保存的中间结果h_pre),$N$ 为输入Tensor中N维度的大小(支持不超过8)。64+ - **正向计算公式**:其中 $\mathbf{x}$ 为输入参数(前向输入x),$\mathbf{hPre}$ 为输入参数(前向保存的中间结果h_pre),$N$ 为输入Tensor中N维度的大小(支持大于0且不超过8)。
65 65 
66 $$66 $$
67 \mathbf{HIn} = \sum_{i=1}^{N} \mathbf{x}[B, S, i, :] \cdot \mathbf{hPre}[B, S, i]67 \mathbf{HIn} = \sum_{i=1}^{N} \mathbf{x}[B, S, i, :] \cdot \mathbf{hPre}[B, S, i]
@@ -325,7 +325,7 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
325 <td>支持空Tensor。</td>325 <td>支持空Tensor。</td>
326 <td>FLOAT16、BFLOAT16</td>326 <td>FLOAT16、BFLOAT16</td>
327 <td>ND</td>327 <td>ND</td>
328- <td>(B,S,C)</td>328+ <td>(B,S,C)或(T,C)</td>
329 <td>√</td>329 <td>√</td>
330 </tr>330 </tr>
331 <tr>331 <tr>
@@ -335,7 +335,7 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
335 <td>支持空Tensor。</td>335 <td>支持空Tensor。</td>
336 <td>FLOAT32 </td>336 <td>FLOAT32 </td>
337 <td>ND</td>337 <td>ND</td>
338- <td>(B,S,N)</td>338+ <td>(B,S,N)或(T,N)</td>
339 <td>√</td>339 <td>√</td>
340 </tr>340 </tr>
341 <tr>341 <tr>
@@ -345,7 +345,7 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
345 <td>支持空Tensor。</td>345 <td>支持空Tensor。</td>
346 <td>FLOAT32 </td>346 <td>FLOAT32 </td>
347 <td>ND</td>347 <td>ND</td>
348- <td>(B,S,N*N)或(B,S,N,N)</td>348+ <td>(B,S,N*N)或(T,N*N)</td>
349 <td>√</td>349 <td>√</td>
350 </tr>350 </tr>
351 <tr>351 <tr>
@@ -355,14 +355,14 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
355 <td>支持空Tensor。</td>355 <td>支持空Tensor。</td>
356 <td>FLOAT16、BFLOAT16</td>356 <td>FLOAT16、BFLOAT16</td>
357 <td>ND</td>357 <td>ND</td>
358- <td>(B,S,N,C)</td>358+ <td>(B,S,N,C)或(T,N,C)</td>
359 <td>√</td>359 <td>√</td>
360 </tr>360 </tr>
361 <tr>361 <tr>
362 <td>phi(aclTensor *)</td>362 <td>phi(aclTensor *)</td>
363 <td>输入</td>363 <td>输入</td>
364 <td>前向参数phi。</td>364 <td>前向参数phi。</td>
365- <td>支持空Tensor。</td>365+ <td>不支持空Tensor。</td>
366 <td>FLOAT32 </td>366 <td>FLOAT32 </td>
367 <td>ND</td>367 <td>ND</td>
368 <td>(2N+N^2, N*C)</td>368 <td>(2N+N^2, N*C)</td>
@@ -372,7 +372,7 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
372 <td>alpha(aclTensor *)</td>372 <td>alpha(aclTensor *)</td>
373 <td>输入</td>373 <td>输入</td>
374 <td>前向参数alpha。</td>374 <td>前向参数alpha。</td>
375- <td>支持空Tensor。</td>375+ <td>不支持空Tensor。</td>
376 <td>FLOAT32 </td>376 <td>FLOAT32 </td>
377 <td>ND</td>377 <td>ND</td>
378 <td>(3)</td>378 <td>(3)</td>
@@ -382,7 +382,7 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
382 <td>bias(aclTensor *)</td>382 <td>bias(aclTensor *)</td>
383 <td>输入</td>383 <td>输入</td>
384 <td>前向参数bias。</td>384 <td>前向参数bias。</td>
385- <td>支持空Tensor。</td>385+ <td>不支持空Tensor。</td>
386 <td>FLOAT32 </td>386 <td>FLOAT32 </td>
387 <td>ND</td>387 <td>ND</td>
388 <td>(2N+N^2)</td>388 <td>(2N+N^2)</td>
@@ -395,7 +395,7 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
395 <td>支持空Tensor。</td>395 <td>支持空Tensor。</td>
396 <td>FLOAT32 </td>396 <td>FLOAT32 </td>
397 <td>ND</td>397 <td>ND</td>
398- <td>(B,S,N)</td>398+ <td>(B,S,N)或(T,N)</td>
399 <td>√</td>399 <td>√</td>
400 </tr>400 </tr>
401 <tr>401 <tr>
@@ -405,7 +405,7 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
405 <td>支持空Tensor。</td>405 <td>支持空Tensor。</td>
406 <td>FLOAT32 </td>406 <td>FLOAT32 </td>
407 <td>ND</td>407 <td>ND</td>
408- <td>(B,S,N*N+2*N)</td>408+ <td>(B,S,N*N+2*N)或(T,N*N+2*N)</td>
409 <td>√</td>409 <td>√</td>
410 </tr>410 </tr>
411 <tr>411 <tr>
@@ -415,7 +415,7 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
415 <td>支持空Tensor。</td>415 <td>支持空Tensor。</td>
416 <td>FLOAT32 </td>416 <td>FLOAT32 </td>
417 <td>ND</td>417 <td>ND</td>
418- <td>(B,S,1)</td>418+ <td>(B,S,1)或(T,1)</td>
419 <td>√</td>419 <td>√</td>
420 </tr>420 </tr>
421 <tr>421 <tr>
@@ -425,7 +425,7 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
425 <td>支持空Tensor。</td>425 <td>支持空Tensor。</td>
426 <td>FLOAT32 </td>426 <td>FLOAT32 </td>
427 <td>ND</td>427 <td>ND</td>
428- <td>(2*sk_iter_count,B,S,N)</td>428+ <td>(2*sk_iter_count,B,S,N)或(2*sk_iter_count,T,N)</td>
429 <td>√</td>429 <td>√</td>
430 </tr>430 </tr>
431 <tr>431 <tr>
@@ -435,7 +435,7 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
435 <td>支持空Tensor。</td>435 <td>支持空Tensor。</td>
436 <td>FLOAT32 </td>436 <td>FLOAT32 </td>
437 <td>ND</td>437 <td>ND</td>
438- <td>(2*sk_iter_count,B,S,N,N)</td>438+ <td>(2*sk_iter_count,B,S,N,N)或(2*sk_iter_count,T,N,N)</td>
439 <td>√</td>439 <td>√</td>
440 </tr>440 </tr>
441 <tr>441 <tr>
@@ -455,7 +455,7 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
455 <td>-</td>455 <td>-</td>
456 <td>FLOAT16、BFLOAT16</td>456 <td>FLOAT16、BFLOAT16</td>
457 <td>ND</td>457 <td>ND</td>
458- <td>(B,S,N,C)</td>458+ <td>(B,S,N,C)或(T,N,C)</td>
459 <td>-</td>459 <td>-</td>
460 </tr>460 </tr>
461 <tr>461 <tr>
@@ -541,7 +541,7 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
541 <tr>541 <tr>
542 <td rowspan="4">ACLNN_ERR_INNER_TILING_ERROR</td>542 <td rowspan="4">ACLNN_ERR_INNER_TILING_ERROR</td>
543 <td rowspan="4">561002</td>543 <td rowspan="4">561002</td>
544- <td>N大于8。</td>544+ <td>N大于8或小于等于0。</td>
545 </tr>545 </tr>
546 <tr>546 <tr>
547 <td>输入或输出tensor的维度(shape)与参数说明不符。</td>547 <td>输入或输出tensor的维度(shape)与参数说明不符。</td>
@@ -600,14 +600,28 @@ aclnnStatus aclnnMhcPreSinkhornBackward(
600 600 
601## 约束说明601## 约束说明
602 602 
603+- **维度格式约束**
604+ 
605+ 输入支持两种维度格式:BSND(4维)和TND(3维)。其中T = B × S,表示所有Batch序列长度的累加和。所有带B/S维度的输入需保持维度格式一致(同为4维BSND或同为3维TND)。
606+ 
603- **规格约束**607- **规格约束**
604 608 
605 | 规格项 | 规格 | 规格说明 |609 | 规格项 | 规格 | 规格说明 |
606 | :--- | :--- | :--- |610 | :--- | :--- | :--- |
607 | sk_iter_count | 20 | Sinkhorn迭代次数当前仅支持20。 |611 | sk_iter_count | 20 | Sinkhorn迭代次数当前仅支持20。 |
608- | N | ≤8 | N维度支持不超过8。 |612+ | N | >0且≤8 | N维度支持大于0且不超过8。 |
609 | C | - | 大于0、小于100000且可以被128整除。 |613 | C | - | 大于0、小于100000且可以被128整除。 |
610 614 
615+- 确定性计算
616+ 
617+ <!-- npu="950" id7 -->
618+ - <term>Ascend 950PR/Ascend 950DT</term>:默认采用确定性实现,相同输入多次调用结果一致。
619+ <!-- end id7 -->
620+ 
621+ <!-- npu="A3,910b" id8 -->
622+ - <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>、<term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term>:默认非确定性实现,支持通过`aclrtCtxSetSysParamOpt`开启确定性。
623+ <!-- end id8 -->
624+ 
611## 调用示例625## 调用示例
612 626 
613示例代码如下,仅供参考,具体编译和执行过程请参考[编译与运行样例](../../../docs/zh/context/compile_and_run_sample.md)。627示例代码如下,仅供参考,具体编译和执行过程请参考[编译与运行样例](../../../docs/zh/context/compile_and_run_sample.md)。
@@ -27,6 +27,12 @@
27 27 
28using namespace op;28using namespace op;
29 29 
30+constexpr size_t DIM_NUM_1D = 1;
31+constexpr size_t DIM_NUM_2D = 2;
32+constexpr size_t DIM_NUM_3D = 3;
33+constexpr size_t DIM_NUM_4D = 4;
34+constexpr size_t DIM_NUM_5D = 5;
35+ 
30#ifdef __cplusplus36#ifdef __cplusplus
31extern "C" {37extern "C" {
32#endif38#endif
@@ -165,18 +171,35 @@ static bool CheckDimNum(const aclTensor *tensor, size_t expected, const char *na
165 171 
166static bool CheckInputDims(const AclnnMhcPreSinkhornBackwardParams &params)172static bool CheckInputDims(const AclnnMhcPreSinkhornBackwardParams &params)
167{173{
168- return CheckDimNum(params.gradHin, 3, "gradHin") && CheckDimNum(params.gradHPost, 3, "gradHPost") &&174+ bool is3D = params.x->GetViewShape().GetDimNum() == DIM_NUM_3D;
169- CheckDimNum(params.gradHRes, 4, "gradHRes", true, 3) && CheckDimNum(params.x, 4, "x") &&175+ if (is3D) {
170- CheckDimNum(params.phi, 2, "phi") && CheckDimNum(params.alpha, 1, "alpha") &&176+ return CheckDimNum(params.gradHin, DIM_NUM_2D, "gradHin") &&
171- CheckDimNum(params.bias, 1, "bias") && CheckDimNum(params.hPre, 3, "hPre") &&177+ CheckDimNum(params.gradHPost, DIM_NUM_2D, "gradHPost") &&
172- CheckDimNum(params.hcBeforeNorm, 3, "hcBeforeNorm") && CheckDimNum(params.invRms, 3, "invRms") &&178+ CheckDimNum(params.gradHRes, DIM_NUM_3D, "gradHRes", true, DIM_NUM_2D) &&
173- CheckDimNum(params.sumOut, 4, "sumOut") && CheckDimNum(params.normOut, 5, "normOut");179+ CheckDimNum(params.x, DIM_NUM_3D, "x") && CheckDimNum(params.phi, DIM_NUM_2D, "phi") &&
180+ CheckDimNum(params.alpha, DIM_NUM_1D, "alpha") && CheckDimNum(params.bias, DIM_NUM_1D, "bias") &&
181+ CheckDimNum(params.hPre, DIM_NUM_2D, "hPre") &&
182+ CheckDimNum(params.hcBeforeNorm, DIM_NUM_2D, "hcBeforeNorm") &&
183+ CheckDimNum(params.invRms, DIM_NUM_2D, "invRms") &&
184+ CheckDimNum(params.sumOut, DIM_NUM_3D, "sumOut") && CheckDimNum(params.normOut, DIM_NUM_4D, "normOut");
185+ }
186+ return CheckDimNum(params.gradHin, DIM_NUM_3D, "gradHin") && CheckDimNum(params.gradHPost, DIM_NUM_3D, "gradHPost") &&
187+ CheckDimNum(params.gradHRes, DIM_NUM_4D, "gradHRes", true, DIM_NUM_3D) &&
188+ CheckDimNum(params.x, DIM_NUM_4D, "x") && CheckDimNum(params.phi, DIM_NUM_2D, "phi") &&
189+ CheckDimNum(params.alpha, DIM_NUM_1D, "alpha") && CheckDimNum(params.bias, DIM_NUM_1D, "bias") &&
190+ CheckDimNum(params.hPre, DIM_NUM_3D, "hPre") &&
191+ CheckDimNum(params.hcBeforeNorm, DIM_NUM_3D, "hcBeforeNorm") &&
192+ CheckDimNum(params.invRms, DIM_NUM_3D, "invRms") &&
193+ CheckDimNum(params.sumOut, DIM_NUM_4D, "sumOut") && CheckDimNum(params.normOut, DIM_NUM_5D, "normOut");
174}194}
175 195 
176static bool CheckOutputDims(const AclnnMhcPreSinkhornBackwardParams &params)196static bool CheckOutputDims(const AclnnMhcPreSinkhornBackwardParams &params)
177{197{
178- return CheckDimNum(params.gradX, 4, "gradX") && CheckDimNum(params.gradPhi, 2, "gradPhi") &&198+ bool is3D = params.x->GetViewShape().GetDimNum() == DIM_NUM_3D;
179- CheckDimNum(params.gradAlpha, 1, "gradAlpha") && CheckDimNum(params.gradBias, 1, "gradBias");199+ size_t gradXExpected = is3D ? DIM_NUM_3D : DIM_NUM_4D;
200+ return CheckDimNum(params.gradX, gradXExpected, "gradX") && CheckDimNum(params.gradPhi, DIM_NUM_2D, "gradPhi") &&
201+ CheckDimNum(params.gradAlpha, DIM_NUM_1D, "gradAlpha") &&
202+ CheckDimNum(params.gradBias, DIM_NUM_1D, "gradBias");
180}203}
181 204 
182static bool CheckInputOutDims(const AclnnMhcPreSinkhornBackwardParams &params)205static bool CheckInputOutDims(const AclnnMhcPreSinkhornBackwardParams &params)
@@ -194,14 +217,127 @@ static bool CheckShapeDim(const gert::Shape &shape, uint64_t index, uint64_t exp
194 return true;217 return true;
195}218}
196 219 
220+static bool CheckShape3D(const AclnnMhcPreSinkhornBackwardParams &params)
221+{
222+ auto &xShape = params.x->GetViewShape();
223+ auto &gradHInShape = params.gradHin->GetViewShape();
224+ uint64_t batch = gradHInShape.GetDim(0);
225+ uint64_t numsResidual = xShape.GetDim(1);
226+ uint64_t dimen = xShape.GetDim(2);
227+ 
228+ if (!CheckShapeDim(xShape, 0, batch, "x tensor shape must be [T, N, C]") ||
229+ !CheckShapeDim(xShape, 1, numsResidual, "x tensor shape must be [T, N, C]") ||
230+ !CheckShapeDim(xShape, 2, dimen, "x tensor shape must be [T, N, C]")) {
231+ return false;
232+ }
233+ 
234+ uint64_t nD = numsResidual * dimen;
235+ auto &phiShape = params.phi->GetViewShape();
236+ uint64_t fusionSize = phiShape.GetDim(0);
237+ if (!CheckShapeDim(phiShape, 1, nD, "phi tensor second dim must be N*C")) {
238+ return false;
239+ }
240+ 
241+ auto &gradHPostShape = params.gradHPost->GetViewShape();
242+ if (!CheckShapeDim(gradHPostShape, 0, batch, "gradHPost shape must be [T, N]") ||
243+ !CheckShapeDim(gradHPostShape, 1, numsResidual, "gradHPost shape must be [T, N]")) {
244+ return false;
245+ }
246+ 
247+ auto &gradHResShape = params.gradHRes->GetViewShape();
248+ if (!CheckShapeDim(gradHResShape, 0, batch, "gradHRes shape must be [T, N, N] or [T, N*N]")) {
249+ return false;
250+ }
251+ if (gradHResShape.GetDimNum() == 3) {
252+ if (!CheckShapeDim(gradHResShape, 1, numsResidual, "gradHRes shape must be [T, N, N]") ||
253+ !CheckShapeDim(gradHResShape, 2, numsResidual, "gradHRes shape must be [T, N, N]")) {
254+ return false;
255+ }
256+ } else {
257+ if (!CheckShapeDim(gradHResShape, 1, numsResidual * numsResidual, "gradHRes shape must be [T, N*N]")) {
258+ return false;
259+ }
260+ }
261+ 
262+ auto &alphaShape = params.alpha->GetViewShape();
263+ if (!CheckShapeDim(alphaShape, 0, 3, "alpha tensor shape must be (3)")) {
264+ return false;
265+ }
266+ 
267+ auto &biasShape = params.bias->GetViewShape();
268+ if (!CheckShapeDim(biasShape, 0, fusionSize, "bias tensor shape must be (2N+N^2)")) {
269+ return false;
270+ }
271+ 
272+ auto &hPreShape = params.hPre->GetViewShape();
273+ if (!CheckShapeDim(hPreShape, 0, batch, "hPre shape must be [T, N]") ||
274+ !CheckShapeDim(hPreShape, 1, numsResidual, "hPre shape must be [T, N]")) {
275+ return false;
276+ }
277+ 
278+ auto &hcBeforeNormShape = params.hcBeforeNorm->GetViewShape();
279+ if (!CheckShapeDim(hcBeforeNormShape, 0, batch, "hcBeforeNorm shape must be [T, 2N+N^2]") ||
280+ !CheckShapeDim(hcBeforeNormShape, 1, fusionSize, "hcBeforeNorm shape must be [T, 2N+N^2]")) {
281+ return false;
282+ }
283+ 
284+ auto &invRmsShape = params.invRms->GetViewShape();
285+ if (!CheckShapeDim(invRmsShape, 0, batch, "invRms shape must be [T, 1]") ||
286+ !CheckShapeDim(invRmsShape, 1, 1, "invRms shape must be [T, 1]")) {
287+ return false;
288+ }
289+ 
290+ auto &sumOutShape = params.sumOut->GetViewShape();
291+ if (!CheckShapeDim(sumOutShape, 1, batch, "sumOut shape must be [2*sk_iter_count, T, N]") ||
292+ !CheckShapeDim(sumOutShape, 2, numsResidual, "sumOut shape must be [2*sk_iter_count, T, N]")) {
293+ return false;
294+ }
295+ 
296+ auto &normOutShape = params.normOut->GetViewShape();
297+ if (!CheckShapeDim(normOutShape, 1, batch, "normOut shape must be [2*sk_iter_count, T, N, N]") ||
298+ !CheckShapeDim(normOutShape, 2, numsResidual, "normOut shape must be [2*sk_iter_count, T, N, N]") ||
299+ !CheckShapeDim(normOutShape, 3, numsResidual, "normOut shape must be [2*sk_iter_count, T, N, N]")) {
300+ return false;
301+ }
302+ 
303+ auto &gradXShape = params.gradX->GetViewShape();
304+ if (!CheckShapeDim(gradXShape, 0, batch, "gradX shape must be [T, N, C]") ||
305+ !CheckShapeDim(gradXShape, 1, numsResidual, "gradX shape must be [T, N, C]") ||
306+ !CheckShapeDim(gradXShape, 2, dimen, "gradX shape must be [T, N, C]")) {
307+ return false;
308+ }
309+ 
310+ auto &gradPhiShape = params.gradPhi->GetViewShape();
311+ if (!CheckShapeDim(gradPhiShape, 0, fusionSize, "gradPhi shape must be [2N+N^2, N*C]") ||
312+ !CheckShapeDim(gradPhiShape, 1, nD, "gradPhi shape must be [2N+N^2, N*C]")) {
313+ return false;
314+ }
315+ 
316+ auto &gradAlphaShape = params.gradAlpha->GetViewShape();
317+ if (!CheckShapeDim(gradAlphaShape, 0, 3, "gradAlpha shape must be (3)")) {
318+ return false;
319+ }
320+ 
321+ auto &gradBiasShape = params.gradBias->GetViewShape();
322+ if (!CheckShapeDim(gradBiasShape, 0, fusionSize, "gradBias shape must be (2N+N^2)")) {
323+ return false;
324+ }
325+ 
326+ return true;
327+}
328+ 
197static bool CheckShape(const AclnnMhcPreSinkhornBackwardParams &params)329static bool CheckShape(const AclnnMhcPreSinkhornBackwardParams &params)
198{330{
331+ auto &xShape = params.x->GetViewShape();
332+ if (xShape.GetDimNum() == 3) {
333+ return CheckShape3D(params);
334+ }
335+ 
199 auto &gradHInShape = params.gradHin->GetViewShape();336 auto &gradHInShape = params.gradHin->GetViewShape();
200 uint64_t batch = gradHInShape.GetDim(0);337 uint64_t batch = gradHInShape.GetDim(0);
201 uint64_t sequence = gradHInShape.GetDim(1);338 uint64_t sequence = gradHInShape.GetDim(1);
202 uint64_t dimen = gradHInShape.GetDim(2);339 uint64_t dimen = gradHInShape.GetDim(2);
203 340 
204- auto &xShape = params.x->GetViewShape();
205 if (!CheckShapeDim(xShape, 0, batch, "x tensor shape must be [B, S, N, C]") ||341 if (!CheckShapeDim(xShape, 0, batch, "x tensor shape must be [B, S, N, C]") ||
206 !CheckShapeDim(xShape, 1, sequence, "x tensor shape must be [B, S, N, C]")) {342 !CheckShapeDim(xShape, 1, sequence, "x tensor shape must be [B, S, N, C]")) {
207 return false;343 return false;
@@ -371,6 +507,21 @@ static aclnnStatus CheckParams(const AclnnMhcPreSinkhornBackwardParams &params)
371 // 4. 检查输入的数据类型是否在支持的数据类型范围之内507 // 4. 检查输入的数据类型是否在支持的数据类型范围之内
372 CHECK_RET(CheckDtypeValid(params), ACLNN_ERR_PARAM_INVALID);508 CHECK_RET(CheckDtypeValid(params), ACLNN_ERR_PARAM_INVALID);
373 509 
510+ // 5. 校验N、C取值范围(需在IsEmpty检查之前,避免C=0/N=0被误判为空tensor)
511+ auto &xShape = params.x->GetViewShape();
512+ bool is3D = xShape.GetDimNum() == 3;
513+ int64_t nVal = is3D ? xShape.GetDim(1) : xShape.GetDim(2);
514+ int64_t cVal = is3D ? xShape.GetDim(2) : xShape.GetDim(3);
515+ if (nVal <= 0 || nVal > 8) {
516+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "N must be > 0 and <= 8, but got %ld", nVal);
517+ return ACLNN_ERR_PARAM_INVALID;
518+ }
519+ if (cVal <= 0 || cVal >= 100000 || cVal % 128 != 0) {
520+ OP_LOGE(ACLNN_ERR_PARAM_INVALID,
521+ "C must be > 0, < 100000 and divisible by 128, but got %ld", cVal);
522+ return ACLNN_ERR_PARAM_INVALID;
523+ }
524+ 
374 return ACLNN_SUCCESS;525 return ACLNN_SUCCESS;
375}526}
376 527 
@@ -449,6 +600,8 @@ aclnnStatus aclnnMhcPreSinkhornBackwardGetWorkspaceSize(
449 DFX_IN(gradHin, gradHPost, gradHRes, x, phi, alpha, bias, hPre, hcBeforeNorm, invRms, sumOut, normOut),600 DFX_IN(gradHin, gradHPost, gradHRes, x, phi, alpha, bias, hPre, hcBeforeNorm, invRms, sumOut, normOut),
450 DFX_OUT(gradX, gradPhi, gradAlpha, gradBias));601 DFX_OUT(gradX, gradPhi, gradAlpha, gradBias));
451 auto uniqueExecutor = CREATE_EXECUTOR();602 auto uniqueExecutor = CREATE_EXECUTOR();
603+ CHECK_RET(uniqueExecutor.get() != nullptr, ACLNN_ERR_INNER_CREATE_EXECUTOR);
604+ 
452 AclnnMhcPreSinkhornBackwardParams params = AclnnMhcPreSinkhornBackward::Create()605 AclnnMhcPreSinkhornBackwardParams params = AclnnMhcPreSinkhornBackward::Create()
453 .SetGradInput(gradHin, gradHPost, gradHRes)606 .SetGradInput(gradHin, gradHPost, gradHRes)
454 .SetInput(x, phi, alpha, bias)607 .SetInput(x, phi, alpha, bias)
@@ -456,7 +609,21 @@ aclnnStatus aclnnMhcPreSinkhornBackwardGetWorkspaceSize(
456 .SetAttr(hcEps)609 .SetAttr(hcEps)
457 .SetOutput(gradX, gradPhi, gradAlpha, gradBias)610 .SetOutput(gradX, gradPhi, gradAlpha, gradBias)
458 .Build();611 .Build();
459- auto ret = mhcPreSinkhornBackwardCommonProcess(params, uniqueExecutor.get());612+ 
613+ auto ret = CheckParams(params);
614+ CHECK_RET(ret == ACLNN_SUCCESS, ret);
615+ 
616+ // Check if input tensors are empty
617+ if (gradHin->IsEmpty() || gradHPost->IsEmpty() || gradHRes->IsEmpty() || x->IsEmpty() ||
618+ hPre->IsEmpty() || hcBeforeNorm->IsEmpty() || invRms->IsEmpty() || sumOut->IsEmpty() ||
619+ normOut->IsEmpty()) {
620+ OP_LOGW("[aclnnMhcPreSinkhornBackward] Input tensor is empty, skip computation and return success.");
621+ *workspaceSize = 0;
622+ uniqueExecutor.ReleaseTo(executor);
623+ return ACLNN_SUCCESS;
624+ }
625+ 
626+ ret = mhcPreSinkhornBackwardCommonProcess(params, uniqueExecutor.get());
460 CHECK_RET(ret == ACLNN_SUCCESS, ret);627 CHECK_RET(ret == ACLNN_SUCCESS, ret);
461 *workspaceSize = uniqueExecutor->GetWorkspaceSize();628 *workspaceSize = uniqueExecutor->GetWorkspaceSize();
462 uniqueExecutor.ReleaseTo(executor);629 uniqueExecutor.ReleaseTo(executor);
@@ -18,10 +18,64 @@
18#include "tiling/platform/platform_ascendc.h"18#include "tiling/platform/platform_ascendc.h"
19#include "mhc_pre_sinkhorn_backward_arch35_tiling_base.h"19#include "mhc_pre_sinkhorn_backward_arch35_tiling_base.h"
20#include "log/log.h"20#include "log/log.h"
21+#include <initializer_list>
21 22 
22using namespace AscendC;23using namespace AscendC;
23namespace optiling {24namespace optiling {
24 25 
26+namespace {
27+const gert::StorageShape *GetInputShapeChecked(gert::TilingContext *context, const char *opName,
28+ const char *tensorName, uint8_t idx)
29+{
30+ const gert::StorageShape *ptr = context->GetInputShape(idx);
31+ OP_CHECK_IF(ptr == nullptr,
32+ OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, %s shape is nullptr", tensorName),
33+ return nullptr);
34+ return ptr;
35+}
36+ 
37+const gert::StorageShape *GetOutputShapeChecked(gert::TilingContext *context, const char *opName,
38+ const char *tensorName, uint8_t idx)
39+{
40+ const gert::StorageShape *ptr = context->GetOutputShape(idx);
41+ OP_CHECK_IF(ptr == nullptr,
42+ OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, %s shape is nullptr", tensorName),
43+ return nullptr);
44+ return ptr;
45+}
46+ 
47+ge::graphStatus VerifyShape(const char *opName, const char *tensorName, const gert::StorageShape *shapePtr,
48+ const int64_t *batchDims, size_t batchDimCount,
49+ std::initializer_list<int64_t> suffixDims, size_t startDim = 0)
50+{
51+ const gert::Shape &shape = shapePtr->GetStorageShape();
52+ size_t expectedDimNum = startDim + batchDimCount + suffixDims.size();
53+ OP_CHECK_IF(shape.GetDimNum() != expectedDimNum,
54+ OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, %s must be %luD, but got %lu dims",
55+ tensorName, expectedDimNum, shape.GetDimNum()),
56+ return ge::GRAPH_FAILED);
57+ 
58+ size_t dimIdx = startDim;
59+ for (size_t i = 0; i < batchDimCount; i++) {
60+ OP_CHECK_IF(shape.GetDim(dimIdx) != batchDims[i],
61+ OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify %s dim[%lu] failed: expected %ld, got %ld",
62+ tensorName, dimIdx, batchDims[i], shape.GetDim(dimIdx)),
63+ return ge::GRAPH_FAILED);
64+ dimIdx++;
65+ }
66+ 
67+ for (auto expected : suffixDims) {
68+ OP_CHECK_IF(shape.GetDim(dimIdx) != expected,
69+ OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify %s dim[%lu] failed: expected %ld, got %ld",
70+ tensorName, dimIdx, expected, shape.GetDim(dimIdx)),
71+ return ge::GRAPH_FAILED);
72+ dimIdx++;
73+ }
74+ 
75+ return ge::GRAPH_SUCCESS;
76+}
77+} // anonymous namespace
78+ 
25constexpr uint8_t GRAD_HIN_IDX = 0;79constexpr uint8_t GRAD_HIN_IDX = 0;
26constexpr uint8_t GRAD_H_POST_IDX = 1;80constexpr uint8_t GRAD_H_POST_IDX = 1;
27constexpr uint8_t GRAD_H_RES_IDX = 2;81constexpr uint8_t GRAD_H_RES_IDX = 2;
@@ -48,6 +102,11 @@ constexpr int64_t DOUBLE_BUFFER = 2;
48constexpr uint8_t BF16_BYTE_SIZE = 2;102constexpr uint8_t BF16_BYTE_SIZE = 2;
49constexpr int64_t ALPHA_SIZE_3 = 3;103constexpr int64_t ALPHA_SIZE_3 = 3;
50constexpr int64_t N_SIZE_4 = 4;104constexpr int64_t N_SIZE_4 = 4;
105+constexpr int64_t MAX_N = 8;
106+constexpr int64_t EXPECTED_SK_ITER_COUNT = 20;
107+constexpr int64_t MAX_C_VALUE = 100000;
108+constexpr int64_t C_ALIGNMENT = 128;
109+constexpr int64_t ITER_COUNT_DIVISOR = 2;
51constexpr int64_t C0_SIZE = 64;110constexpr int64_t C0_SIZE = 64;
52constexpr int64_t TILE_UPPER_BOUND = 64;111constexpr int64_t TILE_UPPER_BOUND = 64;
53constexpr double UB_USAGE_RATIO = 0.95;112constexpr double UB_USAGE_RATIO = 0.95;
@@ -114,271 +173,180 @@ ge::graphStatus MhcPreSinkhornBackwardArch35Tiling::GetShapeAttrsInfo()
114 seqLength_ = xShape.GetDim(SEQ_LENGTH_DIM_IDX);173 seqLength_ = xShape.GetDim(SEQ_LENGTH_DIM_IDX);
115 n_ = xShape.GetDim(N_DIM_IDX);174 n_ = xShape.GetDim(N_DIM_IDX);
116 c_ = xShape.GetDim(C_DIM_IDX);175 c_ = xShape.GetDim(C_DIM_IDX);
117- skIterCount_ = skSumShape.GetDim(ITER_COUNT_IDX) / 2;176+ skIterCount_ = skSumShape.GetDim(ITER_COUNT_IDX) / ITER_COUNT_DIVISOR;
118 OP_CHECK_IF(CheckShape(batchSize_, seqLength_, n_, c_) != ge::GRAPH_SUCCESS,177 OP_CHECK_IF(CheckShape(batchSize_, seqLength_, n_, c_) != ge::GRAPH_SUCCESS,
119 OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "CheckShape failed"), return ge::GRAPH_FAILED);178 OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "CheckShape failed"), return ge::GRAPH_FAILED);
120 OP_CHECK_IF(179 OP_CHECK_IF(
121- skIterCount_ != 20,180+ skIterCount_ != EXPECTED_SK_ITER_COUNT,
122- OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "sk_iter_count must be 20, but got %ld", skIterCount_),181+ OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "sk_iter_count must be %ld, but got %ld",
182+ EXPECTED_SK_ITER_COUNT, skIterCount_),
123 return ge::GRAPH_FAILED);183 return ge::GRAPH_FAILED);
124 184 
125- OP_CHECK_IF(c_ <= 0 || c_ >= 100000 || c_ % 128 != 0,185+ OP_CHECK_IF(c_ <= 0 || c_ >= MAX_C_VALUE || c_ % C_ALIGNMENT != 0,
126 OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(),186 OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(),
127- "c must be > 0, < 100000 and divisible by 128, but got %ld", c_),187+ "c must be > 0, < %ld and divisible by %ld, but got %ld", MAX_C_VALUE,
188+ C_ALIGNMENT, c_),
128 return ge::GRAPH_FAILED);189 return ge::GRAPH_FAILED);
129 190 
130 return ge::GRAPH_SUCCESS;191 return ge::GRAPH_SUCCESS;
131}192}
132 193 
133ge::graphStatus MhcPreSinkhornBackwardArch35Tiling::CheckShapeBase(int64_t batchSize, int64_t seqLength, int64_t n,194ge::graphStatus MhcPreSinkhornBackwardArch35Tiling::CheckShapeBase(int64_t batchSize, int64_t seqLength, int64_t n,
134- int64_t c)195+ int64_t c, bool is3D)
135{196{
136 auto opName = context_->GetNodeName();197 auto opName = context_->GetNodeName();
198+ int64_t bs = batchSize * seqLength;
199+ int64_t hcMix = n * n + 2 * n;
137 200 
138- auto gradHinShapePtr = context_->GetInputShape(GRAD_HIN_IDX);201+ int64_t batchPrefix[2] = {0, 0};
139- OP_CHECK_IF(gradHinShapePtr == nullptr,202+ size_t batchDimCount;
140- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, gradHin shape is nullptr"),203+ if (is3D) {
141- return ge::GRAPH_FAILED);204+ batchPrefix[0] = bs;
142- auto gradHinShape = gradHinShapePtr->GetStorageShape();205+ batchDimCount = 1;
143- OP_CHECK_IF(gradHinShape.GetDimNum() != 3,
144- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, gradHin must be 3D, but got %lu dims",
145- gradHinShape.GetDimNum()),
146- return ge::GRAPH_FAILED);
147- OP_CHECK_IF(
148- gradHinShape.GetDim(0) != batchSize || gradHinShape.GetDim(1) != seqLength || gradHinShape.GetDim(2) != c,
149- OPS_REPORT_VECTOR_INNER_ERR(
150- opName, "ShapeVerify gradHin failed, expected (B=%ld, S=%ld, C=%ld), but got (%ld, %ld, %ld)", batchSize,
151- seqLength, c, gradHinShape.GetDim(0), gradHinShape.GetDim(1), gradHinShape.GetDim(2)),
152- return ge::GRAPH_FAILED);
153- 
154- auto gradHPostShapePtr = context_->GetInputShape(GRAD_H_POST_IDX);
155- OP_CHECK_IF(gradHPostShapePtr == nullptr,
156- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, gradHPost shape is nullptr"),
157- return ge::GRAPH_FAILED);
158- auto gradHPostShape = gradHPostShapePtr->GetStorageShape();
159- OP_CHECK_IF(gradHPostShape.GetDimNum() != 3,
160- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, gradHPost must be 3D, but got %lu dims",
161- gradHPostShape.GetDimNum()),
162- return ge::GRAPH_FAILED);
163- OP_CHECK_IF(
164- gradHPostShape.GetDim(0) != batchSize || gradHPostShape.GetDim(1) != seqLength || gradHPostShape.GetDim(2) != n,
165- OPS_REPORT_VECTOR_INNER_ERR(
166- opName, "ShapeVerify gradHPost failed, expected (B=%ld, S=%ld, N=%ld), but got (%ld, %ld, %ld)", batchSize,
167- seqLength, n, gradHPostShape.GetDim(0), gradHPostShape.GetDim(1), gradHPostShape.GetDim(2)),
168- return ge::GRAPH_FAILED);
169- 
170- auto gradHResShapePtr = context_->GetInputShape(GRAD_H_RES_IDX);
171- OP_CHECK_IF(gradHResShapePtr == nullptr,
172- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, gradHRes shape is nullptr"),
173- return ge::GRAPH_FAILED);
174- auto gradHResShape = gradHResShapePtr->GetStorageShape();
175- auto gradHResDimNum = gradHResShape.GetDimNum();
176- OP_CHECK_IF((gradHResDimNum != 3 && gradHResDimNum != 4),
177- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, gradHRes must be 3D or 4D, but got %lu dims",
178- gradHResDimNum),
179- return ge::GRAPH_FAILED);
180- if (gradHResDimNum == 3) {
181- OP_CHECK_IF(
182- gradHResShape.GetDim(0) != batchSize || gradHResShape.GetDim(1) != seqLength ||
183- gradHResShape.GetDim(2) != n * n,
184- OPS_REPORT_VECTOR_INNER_ERR(
185- opName, "ShapeVerify gradHRes failed, expected (B=%ld, S=%ld, N*N=%ld), but got (%ld, %ld, %ld)",
186- batchSize, seqLength, n * n, gradHResShape.GetDim(0), gradHResShape.GetDim(1), gradHResShape.GetDim(2)),
187- return ge::GRAPH_FAILED);
188 } else {206 } else {
189- OP_CHECK_IF(207+ batchPrefix[0] = batchSize;
190- gradHResShape.GetDim(0) != batchSize || gradHResShape.GetDim(1) != seqLength ||208+ batchPrefix[1] = seqLength;
191- gradHResShape.GetDim(2) != n || gradHResShape.GetDim(3) != n,209+ batchDimCount = 2;
192- OPS_REPORT_VECTOR_INNER_ERR(opName,
193- "ShapeVerify gradHRes failed, expected (B=%ld, S=%ld, N=%ld, N=%ld), "
194- "but got (%ld, %ld, %ld, %ld)",
195- batchSize, seqLength, n, n, gradHResShape.GetDim(0), gradHResShape.GetDim(1),
196- gradHResShape.GetDim(2), gradHResShape.GetDim(3)),
197- return ge::GRAPH_FAILED);
198 }210 }
199 211 
200- auto phiShapePtr = context_->GetInputShape(PHI_IDX);212+ auto gradHin = GetInputShapeChecked(context_, opName, "gradHin", GRAD_HIN_IDX);
201- OP_CHECK_IF(phiShapePtr == nullptr, OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, phi shape is nullptr"),213+ if (!gradHin) {
202- return ge::GRAPH_FAILED);214+ return ge::GRAPH_FAILED;
203- auto phiShape = phiShapePtr->GetStorageShape();215+ }
204- OP_CHECK_IF(phiShape.GetDimNum() != 2,216+ if (VerifyShape(opName, "gradHin", gradHin, batchPrefix, batchDimCount, {c}) != ge::GRAPH_SUCCESS) {
205- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, phi must be 2D, but got %lu dims",217+ return ge::GRAPH_FAILED;
206- phiShape.GetDimNum()),218+ }
207- return ge::GRAPH_FAILED);219+ 
208- OP_CHECK_IF(phiShape.GetDim(0) != n * n + 2 * n || phiShape.GetDim(1) != n * c,220+ auto gradHPost = GetInputShapeChecked(context_, opName, "gradHPost", GRAD_H_POST_IDX);
209- OPS_REPORT_VECTOR_INNER_ERR(221+ if (!gradHPost) {
210- opName, "ShapeVerify phi failed, expected (2N+N^2=%ld, N*C=%ld), but got (%ld, %ld)", n * n + 2 * n,222+ return ge::GRAPH_FAILED;
211- n * c, phiShape.GetDim(0), phiShape.GetDim(1)),223+ }
224+ if (VerifyShape(opName, "gradHPost", gradHPost, batchPrefix, batchDimCount, {n}) != ge::GRAPH_SUCCESS) {
225+ return ge::GRAPH_FAILED;
226+ }
227+ 
228+ auto gradHRes = GetInputShapeChecked(context_, opName, "gradHRes", GRAD_H_RES_IDX);
229+ if (!gradHRes) {
230+ return ge::GRAPH_FAILED;
231+ }
232+ auto gradHResDimNum = gradHRes->GetStorageShape().GetDimNum();
233+ if (gradHResDimNum == batchDimCount + 1) {
234+ if (VerifyShape(opName, "gradHRes", gradHRes, batchPrefix, batchDimCount, {n * n}) != ge::GRAPH_SUCCESS) {
235+ return ge::GRAPH_FAILED;
236+ }
237+ } else if (gradHResDimNum == batchDimCount + 2) {
238+ if (VerifyShape(opName, "gradHRes", gradHRes, batchPrefix, batchDimCount, {n, n}) != ge::GRAPH_SUCCESS) {
239+ return ge::GRAPH_FAILED;
240+ }
241+ } else {
242+ OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, gradHRes must be %luD or %luD, but got %lu dims",
243+ batchDimCount + 1, batchDimCount + 2, gradHResDimNum);
244+ return ge::GRAPH_FAILED;
245+ }
246+ 
247+ auto phi = GetInputShapeChecked(context_, opName, "phi", PHI_IDX);
248+ if (!phi) {
249+ return ge::GRAPH_FAILED;
250+ }
251+ if (VerifyShape(opName, "phi", phi, nullptr, 0, {hcMix, n * c}) != ge::GRAPH_SUCCESS) {
252+ return ge::GRAPH_FAILED;
253+ }
254+ 
255+ auto alpha = GetInputShapeChecked(context_, opName, "alpha", ALPHA_IDX);
256+ if (!alpha) {
257+ return ge::GRAPH_FAILED;
258+ }
259+ if (VerifyShape(opName, "alpha", alpha, nullptr, 0, {(int64_t)ALPHA_SIZE_3}) != ge::GRAPH_SUCCESS) {
260+ return ge::GRAPH_FAILED;
261+ }
262+ 
263+ auto bias = GetInputShapeChecked(context_, opName, "bias", BIAS_IDX);
264+ if (!bias) {
265+ return ge::GRAPH_FAILED;
266+ }
267+ if (VerifyShape(opName, "bias", bias, nullptr, 0, {hcMix}) != ge::GRAPH_SUCCESS) {
268+ return ge::GRAPH_FAILED;
269+ }
270+ 
271+ auto hPre = GetInputShapeChecked(context_, opName, "hPre", H_PRE_IDX);
272+ if (!hPre) {
273+ return ge::GRAPH_FAILED;
274+ }
275+ if (VerifyShape(opName, "hPre", hPre, batchPrefix, batchDimCount, {n}) != ge::GRAPH_SUCCESS) {
276+ return ge::GRAPH_FAILED;
277+ }
278+ 
279+ auto hcBeforeNorm = GetInputShapeChecked(context_, opName, "hcBeforeNorm", HC_BEFORE_NORM_IDX);
280+ if (!hcBeforeNorm) {
281+ return ge::GRAPH_FAILED;
282+ }
283+ if (VerifyShape(opName, "hcBeforeNorm", hcBeforeNorm, batchPrefix, batchDimCount, {hcMix}) != ge::GRAPH_SUCCESS) {
284+ return ge::GRAPH_FAILED;
285+ }
286+ 
287+ auto invRms = GetInputShapeChecked(context_, opName, "invRms", INV_RMS_IDX);
288+ if (!invRms) {
289+ return ge::GRAPH_FAILED;
290+ }
291+ if (VerifyShape(opName, "invRms", invRms, batchPrefix, batchDimCount, {(int64_t)1}) != ge::GRAPH_SUCCESS) {
292+ return ge::GRAPH_FAILED;
293+ }
294+ 
295+ auto sumOut = GetInputShapeChecked(context_, opName, "sumOut", SUM_OUT_IDX);
296+ if (!sumOut) {
297+ return ge::GRAPH_FAILED;
298+ }
299+ if (VerifyShape(opName, "sumOut", sumOut, batchPrefix, batchDimCount, {n}, 1) != ge::GRAPH_SUCCESS) {
300+ return ge::GRAPH_FAILED;
301+ }
302+ OP_CHECK_IF(sumOut->GetStorageShape().GetDim(0) % ITER_COUNT_DIVISOR != 0,
303+ OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify sumOut failed, dim0 must be even, but got %ld",
304+ sumOut->GetStorageShape().GetDim(0)),
212 return ge::GRAPH_FAILED);305 return ge::GRAPH_FAILED);
213 306 
214- auto alphaShapePtr = context_->GetInputShape(ALPHA_IDX);307+ auto normOut = GetInputShapeChecked(context_, opName, "normOut", NORM_OUT_IDX);
215- OP_CHECK_IF(alphaShapePtr == nullptr,308+ if (!normOut) {
216- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, alpha shape is nullptr"),309+ return ge::GRAPH_FAILED;
217- return ge::GRAPH_FAILED);310+ }
218- auto alphaShape = alphaShapePtr->GetStorageShape();311+ if (VerifyShape(opName, "normOut", normOut, batchPrefix, batchDimCount, {n, n}, 1) != ge::GRAPH_SUCCESS) {
219- OP_CHECK_IF(alphaShape.GetDimNum() != 1 || alphaShape.GetDim(0) != ALPHA_SIZE_3,312+ return ge::GRAPH_FAILED;
220- OPS_REPORT_VECTOR_INNER_ERR(313+ }
221- opName, "ShapeVerify alpha failed, expected (3), but got shape with %lu dims, dim0=%ld",314+ OP_CHECK_IF(normOut->GetStorageShape().GetDim(0) != sumOut->GetStorageShape().GetDim(0),
222- alphaShape.GetDimNum(), alphaShape.GetDim(0)),
223- return ge::GRAPH_FAILED);
224- 
225- auto biasShapePtr = context_->GetInputShape(BIAS_IDX);
226- OP_CHECK_IF(biasShapePtr == nullptr,
227- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, bias shape is nullptr"),
228- return ge::GRAPH_FAILED);
229- auto biasShape = biasShapePtr->GetStorageShape();
230- OP_CHECK_IF(biasShape.GetDimNum() != 1 || biasShape.GetDim(0) != n * n + 2 * n,
231- OPS_REPORT_VECTOR_INNER_ERR(
232- opName, "ShapeVerify bias failed, expected (2N+N^2=%ld), but got shape with %lu dims, dim0=%ld",
233- n * n + 2 * n, biasShape.GetDimNum(), biasShape.GetDim(0)),
234- return ge::GRAPH_FAILED);
235- 
236- auto hPreShapePtr = context_->GetInputShape(H_PRE_IDX);
237- OP_CHECK_IF(hPreShapePtr == nullptr,
238- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, hPre shape is nullptr"),
239- return ge::GRAPH_FAILED);
240- auto hPreShape = hPreShapePtr->GetStorageShape();
241- OP_CHECK_IF(hPreShape.GetDimNum() != 3,
242- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, hPre must be 3D, but got %lu dims",
243- hPreShape.GetDimNum()),
244- return ge::GRAPH_FAILED);
245- OP_CHECK_IF(hPreShape.GetDim(0) != batchSize || hPreShape.GetDim(1) != seqLength || hPreShape.GetDim(2) != n,
246- OPS_REPORT_VECTOR_INNER_ERR(
247- opName, "ShapeVerify hPre failed, expected (B=%ld, S=%ld, N=%ld), but got (%ld, %ld, %ld)",
248- batchSize, seqLength, n, hPreShape.GetDim(0), hPreShape.GetDim(1), hPreShape.GetDim(2)),
249- return ge::GRAPH_FAILED);
250- 
251- auto hcBeforeNormShapePtr = context_->GetInputShape(HC_BEFORE_NORM_IDX);
252- OP_CHECK_IF(hcBeforeNormShapePtr == nullptr,
253- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, hcBeforeNorm shape is nullptr"),
254- return ge::GRAPH_FAILED);
255- auto hcBeforeNormShape = hcBeforeNormShapePtr->GetStorageShape();
256- OP_CHECK_IF(hcBeforeNormShape.GetDimNum() != 3,
257- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, hcBeforeNorm must be 3D, but got %lu dims",
258- hcBeforeNormShape.GetDimNum()),
259- return ge::GRAPH_FAILED);
260- OP_CHECK_IF(
261- hcBeforeNormShape.GetDim(0) != batchSize || hcBeforeNormShape.GetDim(1) != seqLength ||
262- hcBeforeNormShape.GetDim(2) != n * n + 2 * n,
263- OPS_REPORT_VECTOR_INNER_ERR(
264- opName, "ShapeVerify hcBeforeNorm failed, expected (B=%ld, S=%ld, N^2+2N=%ld), but got (%ld, %ld, %ld)",
265- batchSize, seqLength, n * n + 2 * n, hcBeforeNormShape.GetDim(0), hcBeforeNormShape.GetDim(1),
266- hcBeforeNormShape.GetDim(2)),
267- return ge::GRAPH_FAILED);
268- 
269- auto invRmsShapePtr = context_->GetInputShape(INV_RMS_IDX);
270- OP_CHECK_IF(invRmsShapePtr == nullptr,
271- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, invRms shape is nullptr"),
272- return ge::GRAPH_FAILED);
273- auto invRmsShape = invRmsShapePtr->GetStorageShape();
274- OP_CHECK_IF(invRmsShape.GetDimNum() != 3,
275- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, invRms must be 3D, but got %lu dims",
276- invRmsShape.GetDimNum()),
277- return ge::GRAPH_FAILED);
278- OP_CHECK_IF(invRmsShape.GetDim(0) != batchSize || invRmsShape.GetDim(1) != seqLength || invRmsShape.GetDim(2) != 1,
279- OPS_REPORT_VECTOR_INNER_ERR(
280- opName, "ShapeVerify invRms failed, expected (B=%ld, S=%ld, 1), but got (%ld, %ld, %ld)", batchSize,
281- seqLength, invRmsShape.GetDim(0), invRmsShape.GetDim(1), invRmsShape.GetDim(2)),
282- return ge::GRAPH_FAILED);
283- 
284- auto sumOutShapePtr = context_->GetInputShape(SUM_OUT_IDX);
285- OP_CHECK_IF(sumOutShapePtr == nullptr,
286- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, sumOut shape is nullptr"),
287- return ge::GRAPH_FAILED);
288- auto sumOutShape = sumOutShapePtr->GetStorageShape();
289- OP_CHECK_IF(sumOutShape.GetDimNum() != 4,
290- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, sumOut must be 4D, but got %lu dims",
291- sumOutShape.GetDimNum()),
292- return ge::GRAPH_FAILED);
293- OP_CHECK_IF(
294- sumOutShape.GetDim(1) != batchSize || sumOutShape.GetDim(2) != seqLength || sumOutShape.GetDim(3) != n,
295- OPS_REPORT_VECTOR_INNER_ERR(
296- opName, "ShapeVerify sumOut failed, expected (2*iter, B=%ld, S=%ld, N=%ld), but got (%ld, %ld, %ld, %ld)",
297- batchSize, seqLength, n, sumOutShape.GetDim(0), sumOutShape.GetDim(1), sumOutShape.GetDim(2),
298- sumOutShape.GetDim(3)),
299- return ge::GRAPH_FAILED);
300- OP_CHECK_IF(
301- sumOutShape.GetDim(0) % 2 != 0,
302- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify sumOut failed, dim0 must be even (2*iter_count), but got %ld",
303- sumOutShape.GetDim(0)),
304- return ge::GRAPH_FAILED);
305- 
306- auto normOutShapePtr = context_->GetInputShape(NORM_OUT_IDX);
307- OP_CHECK_IF(normOutShapePtr == nullptr,
308- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, normOut shape is nullptr"),
309- return ge::GRAPH_FAILED);
310- auto normOutShape = normOutShapePtr->GetStorageShape();
311- OP_CHECK_IF(normOutShape.GetDimNum() != 5,
312- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, normOut must be 5D, but got %lu dims",
313- normOutShape.GetDimNum()),
314- return ge::GRAPH_FAILED);
315- OP_CHECK_IF(normOutShape.GetDim(1) != batchSize || normOutShape.GetDim(2) != seqLength ||
316- normOutShape.GetDim(3) != n || normOutShape.GetDim(4) != n,
317- OPS_REPORT_VECTOR_INNER_ERR(opName,
318- "ShapeVerify normOut failed, expected (2*iter, B=%ld, S=%ld, N=%ld, "
319- "N=%ld), but got (%ld, %ld, %ld, %ld, %ld)",
320- batchSize, seqLength, n, n, normOutShape.GetDim(0), normOutShape.GetDim(1),
321- normOutShape.GetDim(2), normOutShape.GetDim(3), normOutShape.GetDim(4)),
322- return ge::GRAPH_FAILED);
323- OP_CHECK_IF(normOutShape.GetDim(0) != sumOutShape.GetDim(0),
324 OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify normOut dim0(%ld) must equal sumOut dim0(%ld)",315 OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify normOut dim0(%ld) must equal sumOut dim0(%ld)",
325- normOutShape.GetDim(0), sumOutShape.GetDim(0)),316+ normOut->GetStorageShape().GetDim(0), sumOut->GetStorageShape().GetDim(0)),
326 return ge::GRAPH_FAILED);317 return ge::GRAPH_FAILED);
327 318 
328- auto gradXShapePtr = context_->GetOutputShape(GRAD_X_IDX);319+ auto gradX = GetOutputShapeChecked(context_, opName, "gradX", GRAD_X_IDX);
329- OP_CHECK_IF(gradXShapePtr == nullptr,320+ if (!gradX) {
330- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, gradX shape is nullptr"),321+ return ge::GRAPH_FAILED;
331- return ge::GRAPH_FAILED);322+ }
332- auto gradXShape = gradXShapePtr->GetStorageShape();323+ if (VerifyShape(opName, "gradX", gradX, batchPrefix, batchDimCount, {n, c}) != ge::GRAPH_SUCCESS) {
333- OP_CHECK_IF(gradXShape.GetDimNum() != 4,324+ return ge::GRAPH_FAILED;
334- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, gradX must be 4D, but got %lu dims",325+ }
335- gradXShape.GetDimNum()),
336- return ge::GRAPH_FAILED);
337- OP_CHECK_IF(
338- gradXShape.GetDim(0) != batchSize || gradXShape.GetDim(1) != seqLength || gradXShape.GetDim(2) != n ||
339- gradXShape.GetDim(3) != c,
340- OPS_REPORT_VECTOR_INNER_ERR(
341- opName, "ShapeVerify gradX failed, expected (B=%ld, S=%ld, N=%ld, C=%ld), but got (%ld, %ld, %ld, %ld)",
342- batchSize, seqLength, n, c, gradXShape.GetDim(0), gradXShape.GetDim(1), gradXShape.GetDim(2),
343- gradXShape.GetDim(3)),
344- return ge::GRAPH_FAILED);
345 326 
346- auto gradPhiShapePtr = context_->GetOutputShape(GRAD_PHI_IDX);327+ auto gradPhi = GetOutputShapeChecked(context_, opName, "gradPhi", GRAD_PHI_IDX);
347- OP_CHECK_IF(gradPhiShapePtr == nullptr,328+ if (!gradPhi) {
348- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, gradPhi shape is nullptr"),329+ return ge::GRAPH_FAILED;
349- return ge::GRAPH_FAILED);330+ }
350- auto gradPhiShape = gradPhiShapePtr->GetStorageShape();331+ if (VerifyShape(opName, "gradPhi", gradPhi, nullptr, 0, {hcMix, n * c}) != ge::GRAPH_SUCCESS) {
351- OP_CHECK_IF(gradPhiShape.GetDimNum() != 2,332+ return ge::GRAPH_FAILED;
352- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, gradPhi must be 2D, but got %lu dims",333+ }
353- gradPhiShape.GetDimNum()),
354- return ge::GRAPH_FAILED);
355- OP_CHECK_IF(gradPhiShape.GetDim(0) != n * n + 2 * n || gradPhiShape.GetDim(1) != n * c,
356- OPS_REPORT_VECTOR_INNER_ERR(
357- opName, "ShapeVerify gradPhi failed, expected (2N+N^2=%ld, N*C=%ld), but got (%ld, %ld)",
358- n * n + 2 * n, n * c, gradPhiShape.GetDim(0), gradPhiShape.GetDim(1)),
359- return ge::GRAPH_FAILED);
360 334 
361- auto gradAlphaShapePtr = context_->GetOutputShape(GRAD_ALPHA_IDX);335+ auto gradAlpha = GetOutputShapeChecked(context_, opName, "gradAlpha", GRAD_ALPHA_IDX);
362- OP_CHECK_IF(gradAlphaShapePtr == nullptr,336+ if (!gradAlpha) {
363- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, gradAlpha shape is nullptr"),337+ return ge::GRAPH_FAILED;
364- return ge::GRAPH_FAILED);338+ }
365- auto gradAlphaShape = gradAlphaShapePtr->GetStorageShape();339+ if (VerifyShape(opName, "gradAlpha", gradAlpha, nullptr, 0, {(int64_t)ALPHA_SIZE_3}) != ge::GRAPH_SUCCESS) {
366- OP_CHECK_IF(gradAlphaShape.GetDimNum() != 1 || gradAlphaShape.GetDim(0) != ALPHA_SIZE_3,340+ return ge::GRAPH_FAILED;
367- OPS_REPORT_VECTOR_INNER_ERR(341+ }
368- opName, "ShapeVerify gradAlpha failed, expected (3), but got shape with %lu dims, dim0=%ld",
369- gradAlphaShape.GetDimNum(), gradAlphaShape.GetDim(0)),
370- return ge::GRAPH_FAILED);
371 342 
372- auto gradBiasShapePtr = context_->GetOutputShape(GRAD_BIAS_IDX);343+ auto gradBias = GetOutputShapeChecked(context_, opName, "gradBias", GRAD_BIAS_IDX);
373- OP_CHECK_IF(gradBiasShapePtr == nullptr,344+ if (!gradBias) {
374- OPS_REPORT_VECTOR_INNER_ERR(opName, "ShapeVerify failed, gradBias shape is nullptr"),345+ return ge::GRAPH_FAILED;
375- return ge::GRAPH_FAILED);346+ }
376- auto gradBiasShape = gradBiasShapePtr->GetStorageShape();347+ if (VerifyShape(opName, "gradBias", gradBias, nullptr, 0, {hcMix}) != ge::GRAPH_SUCCESS) {
377- OP_CHECK_IF(gradBiasShape.GetDimNum() != 1 || gradBiasShape.GetDim(0) != n * n + 2 * n,348+ return ge::GRAPH_FAILED;
378- OPS_REPORT_VECTOR_INNER_ERR(349+ }
379- opName, "ShapeVerify gradBias failed, expected (2N+N^2=%ld), but got shape with %lu dims, dim0=%ld",
380- n * n + 2 * n, gradBiasShape.GetDimNum(), gradBiasShape.GetDim(0)),
381- return ge::GRAPH_FAILED);
382 350 
383 return ge::GRAPH_SUCCESS;351 return ge::GRAPH_SUCCESS;
384}352}
@@ -29,7 +29,9 @@ using namespace Ops::Transformer::OpTiling;
29 29 
30class MhcPreSinkhornBackwardArch35Tiling : public TilingBaseClass {30class MhcPreSinkhornBackwardArch35Tiling : public TilingBaseClass {
31public:31public:
32- explicit MhcPreSinkhornBackwardArch35Tiling(gert::TilingContext *context) : TilingBaseClass(context) {}32+ explicit MhcPreSinkhornBackwardArch35Tiling(gert::TilingContext *context)
33+ : TilingBaseClass(context)
34+ {}
33 35 
34protected:36protected:
35 bool IsCapable() override;37 bool IsCapable() override;
@@ -43,7 +45,7 @@ protected:
43 ge::graphStatus DoLibApiTiling() override;45 ge::graphStatus DoLibApiTiling() override;
44 46 
45protected:47protected:
46- ge::graphStatus CheckShapeBase(int64_t batchSize, int64_t seqLength, int64_t n, int64_t c);48+ ge::graphStatus CheckShapeBase(int64_t batchSize, int64_t seqLength, int64_t n, int64_t c, bool is3D = false);
47 49 
48private:50private:
49 ge::graphStatus CheckShape(int64_t batchSize, int64_t seqLength, int64_t n, int64_t c);51 ge::graphStatus CheckShape(int64_t batchSize, int64_t seqLength, int64_t n, int64_t c);
@@ -51,10 +51,20 @@ constexpr int64_t DOUBLE_BUFFER = 2;
51constexpr uint8_t BF16_BYTE_SIZE = 2;51constexpr uint8_t BF16_BYTE_SIZE = 2;
52constexpr int64_t ALPHA_SIZE_3 = 3;52constexpr int64_t ALPHA_SIZE_3 = 3;
53constexpr int64_t N_SIZE_4 = 4;53constexpr int64_t N_SIZE_4 = 4;
54+constexpr int64_t MAX_N = 8;
55+constexpr int64_t EXPECTED_SK_ITER_COUNT = 20;
56+constexpr int64_t MAX_C_VALUE = 100000;
57+constexpr int64_t C_ALIGNMENT = 128;
58+constexpr int64_t ITER_COUNT_DIVISOR = 2;
54constexpr int64_t ALIGN_32 = 32;59constexpr int64_t ALIGN_32 = 32;
55constexpr int64_t FP32_BYTE_SIZE = 4;60constexpr int64_t FP32_BYTE_SIZE = 4;
56constexpr uint64_t UB_RESERVE_SIZE = 256;61constexpr uint64_t UB_RESERVE_SIZE = 256;
57constexpr int64_t WS_BUFFER_INTERVAL = 1024;62constexpr int64_t WS_BUFFER_INTERVAL = 1024;
63+constexpr int64_t GRAD_X_FROM_BUF_COUNT = 3;
64+constexpr int64_t GRAD_ALPHA_BUF_COUNT = 3;
65+constexpr int64_t N_SQUARE_GRAD_BUF_COUNT = 5;
66+constexpr int64_t N_SQUARE_FINAL_BUF_COUNT = 4;
67+constexpr int64_t N_SQUARE_TAIL_BUF_COUNT = 4;
58 68 
59template <typename T>69template <typename T>
60constexpr T AlignUp(T value, T align)70constexpr T AlignUp(T value, T align)
@@ -82,9 +92,10 @@ ge::graphStatus MhcPreSinkhornBackwardArch35DeterminiticTiling::GetShapeAttrsInf
82 return ge::GRAPH_FAILED;92 return ge::GRAPH_FAILED;
83 }93 }
84 auto xShape = xShapePtr->GetStorageShape();94 auto xShape = xShapePtr->GetStorageShape();
85- OP_CHECK_IF(xShape.GetDimNum() != 4,95+ auto xDimNum = xShape.GetDimNum();
96+ OP_CHECK_IF(xDimNum != 3 && xDimNum != 4,
86 OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(),97 OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(),
87- "xShape verify failed, x must be 4D, but got %lu dims", xShape.GetDimNum()),98+ "xShape verify failed, x must be 3D or 4D, but got %lu dims", xDimNum),
88 return ge::GRAPH_FAILED);99 return ge::GRAPH_FAILED);
89 auto skSumShape = skSumPtr->GetStorageShape();100 auto skSumShape = skSumPtr->GetStorageShape();
90 101 
@@ -96,25 +107,38 @@ ge::graphStatus MhcPreSinkhornBackwardArch35DeterminiticTiling::GetShapeAttrsInf
96 auto epsPtr = attrsPtr->GetAttrPointer<float>(0);107 auto epsPtr = attrsPtr->GetAttrPointer<float>(0);
97 hcEps_ = (epsPtr != nullptr) ? static_cast<float>(*epsPtr) : DEFAULT_EPS;108 hcEps_ = (epsPtr != nullptr) ? static_cast<float>(*epsPtr) : DEFAULT_EPS;
98 109 
99- batchSize_ = xShape.GetDim(BATCH_SIZE_DIM_IDX);110+ if (xDimNum == 3) {
guankarl
guankarlguankarlAug 11

魔鬼数字

likedislike
100- seqLength_ = xShape.GetDim(SEQ_LENGTH_DIM_IDX);111+ bs_ = xShape.GetDim(0);
101- n_ = xShape.GetDim(N_DIM_IDX);112+ n_ = xShape.GetDim(1);
102- c_ = xShape.GetDim(C_DIM_IDX);113+ c_ = xShape.GetDim(2);
103- skIterCount_ = skSumShape.GetDim(ITER_COUNT_IDX) / 2;114+ OP_CHECK_IF(CheckShapeBase(bs_, 1, n_, c_, true) != ge::GRAPH_SUCCESS,
115+ OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "CheckShape3D failed"),
116+ return ge::GRAPH_FAILED);
117+ } else {
118+ int64_t batchSize = xShape.GetDim(BATCH_SIZE_DIM_IDX);
119+ int64_t seqLength = xShape.GetDim(SEQ_LENGTH_DIM_IDX);
120+ bs_ = batchSize * seqLength;
121+ n_ = xShape.GetDim(N_DIM_IDX);
122+ c_ = xShape.GetDim(C_DIM_IDX);
123+ OP_CHECK_IF(CheckShapeBase(batchSize, seqLength, n_, c_) != ge::GRAPH_SUCCESS,
124+ OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "CheckShape failed"),
125+ return ge::GRAPH_FAILED);
126+ }
127+ skIterCount_ = skSumShape.GetDim(ITER_COUNT_IDX) / ITER_COUNT_DIVISOR;
104 128 
105- OP_CHECK_IF(n_ > 8,129+ OP_CHECK_IF(n_ <= 0 || n_ > MAX_N,
106- OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "n must be less than or equal 8, but got %ld", n_),130+ OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "n must be > 0 and <= %ld, but got %ld", MAX_N, n_),
107 return ge::GRAPH_FAILED);131 return ge::GRAPH_FAILED);
108- OP_CHECK_IF(CheckShapeBase(batchSize_, seqLength_, n_, c_) != ge::GRAPH_SUCCESS,
109- OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "CheckShape failed"), return ge::GRAPH_FAILED);
110 OP_CHECK_IF(132 OP_CHECK_IF(
111- skIterCount_ != 20,133+ skIterCount_ != EXPECTED_SK_ITER_COUNT,
112- OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "sk_iter_count must be 20, but got %ld", skIterCount_),134+ OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "sk_iter_count must be %ld, but got %ld",
135+ EXPECTED_SK_ITER_COUNT, skIterCount_),
113 return ge::GRAPH_FAILED);136 return ge::GRAPH_FAILED);
114 137 
115- OP_CHECK_IF(c_ <= 0 || c_ >= 100000 || c_ % 128 != 0,138+ OP_CHECK_IF(c_ <= 0 || c_ >= MAX_C_VALUE || c_ % C_ALIGNMENT != 0,
116 OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(),139 OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(),
117- "c must be > 0, < 100000 and divisible by 128, but got %ld", c_),140+ "c must be > 0, < %ld and divisible by %ld, but got %ld", MAX_C_VALUE,
141+ C_ALIGNMENT, c_),
118 return ge::GRAPH_FAILED);142 return ge::GRAPH_FAILED);
119 143 
120 return ge::GRAPH_SUCCESS;144 return ge::GRAPH_SUCCESS;
@@ -130,12 +154,13 @@ ge::graphStatus MhcPreSinkhornBackwardArch35DeterminiticTiling::SetTilingData()
130 154 
131 auto floatDataType = matmul_tiling::DataType::DT_FLOAT;155 auto floatDataType = matmul_tiling::DataType::DT_FLOAT;
132 156 
133- mm1K_ = n_ * n_ + 2 * n_;157+ int64_t hcMix = n_ * n_ + 2 * n_;
134- mm1M_ = batchSize_ * seqLength_;158+ mm1K_ = hcMix;
159+ mm1M_ = bs_;
135 mm1N_ = n_ * c_;160 mm1N_ = n_ * c_;
136 161 
137- mm2K_ = batchSize_ * seqLength_;162+ mm2K_ = bs_;
138- mm2M_ = n_ * n_ + 2 * n_;163+ mm2M_ = hcMix;
139 mm2N_ = n_ * c_;164 mm2N_ = n_ * c_;
140 165 
141 matmul_tiling::MatmulApiTiling mm1Tiling(ascendPlatformInfo);166 matmul_tiling::MatmulApiTiling mm1Tiling(ascendPlatformInfo);
@@ -165,8 +190,7 @@ ge::graphStatus MhcPreSinkhornBackwardArch35DeterminiticTiling::SetTilingData()
165 return ge::GRAPH_FAILED;190 return ge::GRAPH_FAILED;
166 }191 }
167 192 
168- tilingData->batchSize = batchSize_;193+ tilingData->bs = bs_;
169- tilingData->seqLength = seqLength_;
170 tilingData->c = c_;194 tilingData->c = c_;
171 tilingData->n = n_;195 tilingData->n = n_;
172 tilingData->usedAivNum = usedAivNum_;196 tilingData->usedAivNum = usedAivNum_;
@@ -189,7 +213,7 @@ ge::graphStatus MhcPreSinkhornBackwardArch35DeterminiticTiling::SetTilingData()
189 213 
190void MhcPreSinkhornBackwardArch35DeterminiticTiling::DoUbTiling()214void MhcPreSinkhornBackwardArch35DeterminiticTiling::DoUbTiling()
191{215{
192- int64_t totalBs = batchSize_ * seqLength_;216+ int64_t totalBs = bs_;
193 bsTaskCount_ = Ops::Base::CeilDiv(totalBs, static_cast<int64_t>(coreNumAiv_));217 bsTaskCount_ = Ops::Base::CeilDiv(totalBs, static_cast<int64_t>(coreNumAiv_));
194 usedAivNum_ = Ops::Base::CeilDiv(totalBs, bsTaskCount_);218 usedAivNum_ = Ops::Base::CeilDiv(totalBs, bsTaskCount_);
195 tailBsTaskCount_ = totalBs - bsTaskCount_ * (usedAivNum_ - 1);219 tailBsTaskCount_ = totalBs - bsTaskCount_ * (usedAivNum_ - 1);
@@ -198,6 +222,7 @@ void MhcPreSinkhornBackwardArch35DeterminiticTiling::DoUbTiling()
198 ubBlock_ = static_cast<int64_t>(Ops::Base::GetUbBlockSize(context_));222 ubBlock_ = static_cast<int64_t>(Ops::Base::GetUbBlockSize(context_));
199 ubSize_ = ubSize_ - UB_RESERVE_SIZE;223 ubSize_ = ubSize_ - UB_RESERVE_SIZE;
200 auto restSize = static_cast<int64_t>(-1);224 auto restSize = static_cast<int64_t>(-1);
225+ int64_t hcMix = n_ * n_ + 2 * n_;
201 226 
202 /* UB分布:x、h_pre And grad_h_pre、grad_h_in、hc_before_norm、inv_rms、227 /* UB分布:x、h_pre And grad_h_pre、grad_h_in、hc_before_norm、inv_rms、
203 grad_h_res、xFP32、grad_x_from_in、grad_alpha And grad_bias、228 grad_h_res、xFP32、grad_x_from_in、grad_alpha And grad_bias、
@@ -217,15 +242,16 @@ void MhcPreSinkhornBackwardArch35DeterminiticTiling::DoUbTiling()
217 Ops::Base::CeilAlign(n_ * n_ * FP32_BYTE_SIZE, ubBlock_) + ubBlock_ +242 Ops::Base::CeilAlign(n_ * n_ * FP32_BYTE_SIZE, ubBlock_) + ubBlock_ +
218 Ops::Base::CeilAlign(bsLoopDataLen_ * n_ * FP32_BYTE_SIZE, ubBlock_) +243 Ops::Base::CeilAlign(bsLoopDataLen_ * n_ * FP32_BYTE_SIZE, ubBlock_) +
219 Ops::Base::CeilAlign(bsLoopDataLen_ * n_ * n_ * FP32_BYTE_SIZE, ubBlock_) +244 Ops::Base::CeilAlign(bsLoopDataLen_ * n_ * n_ * FP32_BYTE_SIZE, ubBlock_) +
220- Ops::Base::CeilAlign((2 * n_ + n_ * n_) * FP32_BYTE_SIZE, ubBlock_) +245+ Ops::Base::CeilAlign(hcMix * FP32_BYTE_SIZE, ubBlock_) +
221 Ops::Base::CeilAlign(bsLoopDataLen_ * n_ * n_ * FP32_BYTE_SIZE, ubBlock_) +246 Ops::Base::CeilAlign(bsLoopDataLen_ * n_ * n_ * FP32_BYTE_SIZE, ubBlock_) +
222 Ops::Base::CeilAlign(bsLoopDataLen_ * n_ * n_ * FP32_BYTE_SIZE, ubBlock_) +247 Ops::Base::CeilAlign(bsLoopDataLen_ * n_ * n_ * FP32_BYTE_SIZE, ubBlock_) +
223- Ops::Base::CeilAlign((2 * n_ + n_ * n_) * FP32_BYTE_SIZE, ubBlock_) +248+ Ops::Base::CeilAlign(hcMix * FP32_BYTE_SIZE, ubBlock_) +
224- Ops::Base::CeilAlign((2 * n_ + n_ * n_) * FP32_BYTE_SIZE, ubBlock_) +249+ Ops::Base::CeilAlign(hcMix * FP32_BYTE_SIZE, ubBlock_) +
225- 5 * Ops::Base::CeilAlign(bsLoopDataLen_ * n_ * n_ * FP32_BYTE_SIZE, ubBlock_) +250+ N_SQUARE_GRAD_BUF_COUNT * Ops::Base::CeilAlign(bsLoopDataLen_ * n_ * n_ * FP32_BYTE_SIZE, ubBlock_) +
226- DOUBLE_BUFFER * 2 * skIterCount_ * bsLoopDataLen_ * Ops::Base::CeilAlign(n_ * FP32_BYTE_SIZE, ubBlock_) +251+ DOUBLE_BUFFER * ITER_COUNT_DIVISOR * skIterCount_ * bsLoopDataLen_ *
252+ Ops::Base::CeilAlign(n_ * FP32_BYTE_SIZE, ubBlock_) +
227 DOUBLE_BUFFER * skIterCount_ * bsLoopDataLen_ * Ops::Base::CeilAlign(n_ * n_ * FP32_BYTE_SIZE, ubBlock_) +253 DOUBLE_BUFFER * skIterCount_ * bsLoopDataLen_ * Ops::Base::CeilAlign(n_ * n_ * FP32_BYTE_SIZE, ubBlock_) +
228- 4 * bsLoopDataLen_ * Ops::Base::CeilAlign(n_ * n_ * FP32_BYTE_SIZE, ubBlock_);254+ N_SQUARE_TAIL_BUF_COUNT * bsLoopDataLen_ * Ops::Base::CeilAlign(n_ * n_ * FP32_BYTE_SIZE, ubBlock_);
229 255 
230 restSize = ubSize_ - occupy;256 restSize = ubSize_ - occupy;
231 if (restSize <= 0 && bsLoopDataLen_ > 1) {257 if (restSize <= 0 && bsLoopDataLen_ > 1) {
@@ -243,11 +269,11 @@ void MhcPreSinkhornBackwardArch35DeterminiticTiling::DoUbTiling()
243 cBlockTailCount_ = tailBsncTaskCount_;269 cBlockTailCount_ = tailBsncTaskCount_;
244 restSize = static_cast<int64_t>(-1);270 restSize = static_cast<int64_t>(-1);
245 while (restSize <= 0) {271 while (restSize <= 0) {
246- int64_t occupy = 4 * DOUBLE_BUFFER * Ops::Base::CeilAlign(cBlockCount_ * FP32_BYTE_SIZE, ubBlock_) +272+ int64_t occupy = N_SQUARE_FINAL_BUF_COUNT * DOUBLE_BUFFER * Ops::Base::CeilAlign(cBlockCount_ * FP32_BYTE_SIZE, ubBlock_) +
247 DOUBLE_BUFFER * Ops::Base::CeilAlign(usedAivNum_ * FP32_BYTE_SIZE, ubBlock_) + ubBlock_ +273 DOUBLE_BUFFER * Ops::Base::CeilAlign(usedAivNum_ * FP32_BYTE_SIZE, ubBlock_) + ubBlock_ +
248 usedAivNum_ * Ops::Base::CeilAlign(n_ * n_ * FP32_BYTE_SIZE, ubBlock_) +274 usedAivNum_ * Ops::Base::CeilAlign(n_ * n_ * FP32_BYTE_SIZE, ubBlock_) +
249- 2 * Ops::Base::CeilAlign((2 * n_ + n_ * n_) * FP32_BYTE_SIZE, ubBlock_) +275+ ITER_COUNT_DIVISOR * Ops::Base::CeilAlign(hcMix * FP32_BYTE_SIZE, ubBlock_) +
250- 2 * DOUBLE_BUFFER * Ops::Base::CeilAlign(cLoopDataLen_ * FP32_BYTE_SIZE, ubBlock_);276+ ITER_COUNT_DIVISOR * DOUBLE_BUFFER * Ops::Base::CeilAlign(cLoopDataLen_ * FP32_BYTE_SIZE, ubBlock_);
251 restSize = ubSize_ - occupy;277 restSize = ubSize_ - occupy;
252 if (restSize <= 0 && cBlockCount_ > 1) {278 if (restSize <= 0 && cBlockCount_ > 1) {
253 cBlockCount_--;279 cBlockCount_--;
@@ -284,13 +310,15 @@ ge::graphStatus MhcPreSinkhornBackwardArch35DeterminiticTiling::GetWorkspaceSize
284 auto platformInfo = context_->GetPlatformInfo();310 auto platformInfo = context_->GetPlatformInfo();
285 OP_CHECK_IF(platformInfo == nullptr, OP_LOGE(opName, "fail to get platform info"), return ge::GRAPH_FAILED);311 OP_CHECK_IF(platformInfo == nullptr, OP_LOGE(opName, "fail to get platform info"), return ge::GRAPH_FAILED);
286 auto ascendPlatformInfo = platform_ascendc::PlatformAscendC(platformInfo);312 auto ascendPlatformInfo = platform_ascendc::PlatformAscendC(platformInfo);
313+ int64_t hcMix = n_ * n_ + 2 * n_;
287 size_t userWorkspaceSize =314 size_t userWorkspaceSize =
288- batchSize_ * seqLength_ * n_ * c_ * FP32_BYTE_SIZE + WS_BUFFER_INTERVAL + // xFP32315+ bs_ * n_ * c_ * FP32_BYTE_SIZE + WS_BUFFER_INTERVAL + // xFP32
289- 3 * usedAivNum_ * FP32_BYTE_SIZE + WS_BUFFER_INTERVAL + // gradAlpha316+ GRAD_ALPHA_BUF_COUNT * usedAivNum_ * FP32_BYTE_SIZE + WS_BUFFER_INTERVAL + // gradAlpha
290- (2 * usedAivNum_ * n_ + usedAivNum_ * n_ * n_) * FP32_BYTE_SIZE + WS_BUFFER_INTERVAL + // gradBias317+ usedAivNum_ * hcMix * FP32_BYTE_SIZE + WS_BUFFER_INTERVAL + // gradBias
291- batchSize_ * seqLength_ * n_ * c_ * FP32_BYTE_SIZE * 3 + 3 * WS_BUFFER_INTERVAL + // gradXFrom318+ bs_ * n_ * c_ * FP32_BYTE_SIZE * GRAD_X_FROM_BUF_COUNT +
292- batchSize_ * seqLength_ * (2 * n_ + n_ * n_) * FP32_BYTE_SIZE + WS_BUFFER_INTERVAL + // grad_hc_before_norm319+ GRAD_X_FROM_BUF_COUNT * WS_BUFFER_INTERVAL + // gradXFrom
293- batchSize_ * seqLength_ * (2 * n_ + n_ * n_) * FP32_BYTE_SIZE + WS_BUFFER_INTERVAL; // grad_norm_out320+ bs_ * hcMix * FP32_BYTE_SIZE + WS_BUFFER_INTERVAL + // grad_hc_before_norm
321+ bs_ * hcMix * FP32_BYTE_SIZE + WS_BUFFER_INTERVAL; // grad_norm_out
294 322 
295 size_t systemWorkspaceSize = ascendPlatformInfo.GetLibApiWorkSpaceSize();323 size_t systemWorkspaceSize = ascendPlatformInfo.GetLibApiWorkSpaceSize();
296 size_t *currentWorkspace = context_->GetWorkspaceSizes(1);324 size_t *currentWorkspace = context_->GetWorkspaceSizes(1);
@@ -303,8 +331,7 @@ ge::graphStatus MhcPreSinkhornBackwardArch35DeterminiticTiling::GetWorkspaceSize
303void MhcPreSinkhornBackwardArch35DeterminiticTiling::DumpTilingInfo()331void MhcPreSinkhornBackwardArch35DeterminiticTiling::DumpTilingInfo()
304{332{
305 std::ostringstream info;333 std::ostringstream info;
306- info << "batchSize: " << batchSize_ << std::endl;334+ info << "bs: " << bs_ << std::endl;
307- info << "seqLength: " << seqLength_ << std::endl;
308 info << "c: " << c_ << std::endl;335 info << "c: " << c_ << std::endl;
309 info << "n: " << n_ << std::endl;336 info << "n: " << n_ << std::endl;
310 info << "aivNum: " << coreNumAiv_ << std::endl;337 info << "aivNum: " << coreNumAiv_ << std::endl;
@@ -49,6 +49,7 @@ private:
49 void DoUbTiling();49 void DoUbTiling();
50 50 
51private:51private:
52+ int64_t bs_{0};
52 int64_t bsTaskCount_{0};53 int64_t bsTaskCount_{0};
53 int64_t tailBsTaskCount_{0};54 int64_t tailBsTaskCount_{0};
54 int64_t bsLoopDataLen_{0};55 int64_t bsLoopDataLen_{0};
@@ -38,8 +38,7 @@ struct MhcPreSinkhornBackwardArch35TilingData {
38};38};
39 39 
40struct MhcPreSinkhornBackwardArch35DeterminiticTilingData {40struct MhcPreSinkhornBackwardArch35DeterminiticTilingData {
41- int64_t batchSize = 0;41+ int64_t bs = 0;
42- int64_t seqLength = 0;
43 int64_t c = 0;42 int64_t c = 0;
44 int64_t n = 0;43 int64_t n = 0;
45 int64_t usedAivNum = 0;44 int64_t usedAivNum = 0;
@@ -49,11 +48,11 @@ struct MhcPreSinkhornBackwardArch35DeterminiticTilingData {
49 int64_t skIterCount = 0;48 int64_t skIterCount = 0;
50 int64_t bsTaskCount = 0;49 int64_t bsTaskCount = 0;
51 int64_t tailBsTaskCount = 0;50 int64_t tailBsTaskCount = 0;
52- //reset后51+ // reset后
53- int64_t cBlockLoops = 0; // B*S*N*C,切核,总循环次数52+ int64_t cBlockLoops = 0; // B*S*N*C,切核,总循环次数
54- int64_t cBlockTailLoops = 0; // B*S*N*C,切核,尾核循环次数53+ int64_t cBlockTailLoops = 0; // B*S*N*C,切核,尾核循环次数
55- int64_t cBlockCount = 0; // B*S*N*C,切核,普通核尾循环处理元素个数54+ int64_t cBlockCount = 0; // B*S*N*C,切核,普通核尾循环处理元素个数
56- int64_t cBlockTailCount = 0; // B*S*N*C,切核,普通核尾核循环次数55+ int64_t cBlockTailCount = 0; // B*S*N*C,切核,普通核尾核循环次数
57 int64_t cBlockTailTailCount = 0; // B*S*N*C,切核,尾核尾循环处理个数56 int64_t cBlockTailTailCount = 0; // B*S*N*C,切核,尾核尾循环处理个数
58 int64_t finalUsedAivNum = 0;57 int64_t finalUsedAivNum = 0;
59 float eps = 0;58 float eps = 0;
@@ -229,8 +229,6 @@ private:
229 TQue<QuePosition::VECIN, DOUBLE_BUFFER> normOutQue_;229 TQue<QuePosition::VECIN, DOUBLE_BUFFER> normOutQue_;
230 230 
231 int64_t usedAivNum_ = 0;231 int64_t usedAivNum_ = 0;
232- int64_t batchSize_ = 0;
233- int64_t seqLength_ = 0;
234 int64_t bsCount_ = 0;232 int64_t bsCount_ = 0;
235 uint16_t n_ = 0;233 uint16_t n_ = 0;
236 uint16_t nn_ = 0;234 uint16_t nn_ = 0;
@@ -294,11 +292,9 @@ __aicore__ inline void MhcPreSinkhornBackwardDeterministic<X_T, GRADHIN_T, U>::I
294{292{
295 tilingData_ = tilingData;293 tilingData_ = tilingData;
296 pipe_ = pipe;294 pipe_ = pipe;
297- batchSize_ = tilingData->batchSize;295+ bsCount_ = tilingData->bs;
298- seqLength_ = tilingData->seqLength;
299 n_ = static_cast<uint16_t>(tilingData->n);296 n_ = static_cast<uint16_t>(tilingData->n);
300 nn_ = n_ * n_;297 nn_ = n_ * n_;
301- bsCount_ = batchSize_ * seqLength_;
302 c_ = tilingData->c;298 c_ = tilingData->c;
303 cLoopDataLen_ = tilingData->cLoopDataLen;299 cLoopDataLen_ = tilingData->cLoopDataLen;
304 bsLoopDataLen_ = tilingData->bsLoopDataLen;300 bsLoopDataLen_ = tilingData->bsLoopDataLen;
@@ -337,18 +333,18 @@ __aicore__ inline void MhcPreSinkhornBackwardDeterministic<X_T, GRADHIN_T, U>::I
337 phiGm_.SetGlobalBuffer(reinterpret_cast<__gm__ U *>(phi));333 phiGm_.SetGlobalBuffer(reinterpret_cast<__gm__ U *>(phi));
338 gradPhiGm_.SetGlobalBuffer(reinterpret_cast<__gm__ U *>(gradPhi));334 gradPhiGm_.SetGlobalBuffer(reinterpret_cast<__gm__ U *>(gradPhi));
339 constexpr int64_t FP32_BYTE_SIZE = sizeof(U);335 constexpr int64_t FP32_BYTE_SIZE = sizeof(U);
340- int64_t gradAlphaOffset = batchSize_ * seqLength_ * c_ * n_ + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;336+ int64_t gradAlphaOffset = bsCount_ * c_ * n_ + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;
341 int64_t gradBiasOffset = gradAlphaOffset + 3 * usedAivNum_ + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;337 int64_t gradBiasOffset = gradAlphaOffset + 3 * usedAivNum_ + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;
342 int64_t gradXFromHinOffset =338 int64_t gradXFromHinOffset =
343 gradBiasOffset + (2 * usedAivNum_ * n_ + usedAivNum_ * n_ * n_) + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;339 gradBiasOffset + (2 * usedAivNum_ * n_ + usedAivNum_ * n_ * n_) + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;
344 int64_t gradXFromRmsOffset =340 int64_t gradXFromRmsOffset =
345- gradXFromHinOffset + batchSize_ * seqLength_ * n_ * c_ + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;341+ gradXFromHinOffset + bsCount_ * n_ * c_ + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;
346 int64_t gradXFromMatmulOffset =342 int64_t gradXFromMatmulOffset =
347- gradXFromRmsOffset + batchSize_ * seqLength_ * n_ * c_ + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;343+ gradXFromRmsOffset + bsCount_ * n_ * c_ + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;
348 int64_t gradHcBeforeNormOffset =344 int64_t gradHcBeforeNormOffset =
349- gradXFromMatmulOffset + batchSize_ * seqLength_ * n_ * c_ + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;345+ gradXFromMatmulOffset + bsCount_ * n_ * c_ + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;
350 int64_t gradNormOutOffset =346 int64_t gradNormOutOffset =
351- gradHcBeforeNormOffset + batchSize_ * seqLength_ * (2 * n_ + n_ * n_) + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;347+ gradHcBeforeNormOffset + bsCount_ * (2 * n_ + n_ * n_) + WS_BUFFER_INTERVAL / FP32_BYTE_SIZE;
352 348 
353 xFp32Ws_.SetGlobalBuffer(reinterpret_cast<__gm__ U *>(workspace));349 xFp32Ws_.SetGlobalBuffer(reinterpret_cast<__gm__ U *>(workspace));
354 gradAlphaWs_.SetGlobalBuffer(reinterpret_cast<__gm__ U *>(workspace) + gradAlphaOffset);350 gradAlphaWs_.SetGlobalBuffer(reinterpret_cast<__gm__ U *>(workspace) + gradAlphaOffset);
@@ -421,10 +417,10 @@ __aicore__ inline void MhcPreSinkhornBackwardDeterministic<X_T, GRADHIN_T, U>::I
421 417 
422 if ASCEND_IS_AIC {418 if ASCEND_IS_AIC {
423 mm1K_ = n_ * n_ + 2 * n_;419 mm1K_ = n_ * n_ + 2 * n_;
424- mm1M_ = batchSize_ * seqLength_;420+ mm1M_ = bsCount_;
425 mm1N_ = n_ * c_;421 mm1N_ = n_ * c_;
426 422 
427- mm2K_ = batchSize_ * seqLength_;423+ mm2K_ = bsCount_;
428 mm2M_ = n_ * n_ + 2 * n_;424 mm2M_ = n_ * n_ + 2 * n_;
429 mm2N_ = n_ * c_;425 mm2N_ = n_ * c_;
430 }426 }
@@ -784,7 +780,7 @@ __aicore__ inline void MhcPreSinkhornBackwardDeterministic<X_T, GRADHIN_T, U>::C
784 AscendC::MicroAPI::DataCopy<X_T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(xReg, xAddrStart);780 AscendC::MicroAPI::DataCopy<X_T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(xReg, xAddrStart);
785 AscendC::MicroAPI::Cast<U, X_T, castTrait16ToFloat>(xCastReg, xReg, valueMaskReg);781 AscendC::MicroAPI::Cast<U, X_T, castTrait16ToFloat>(xCastReg, xReg, valueMaskReg);
786 AscendC::MicroAPI::Muls(gradXFromHinReg, gradHInCastReg, hPre,782 AscendC::MicroAPI::Muls(gradXFromHinReg, gradHInCastReg, hPre,
787- valueMaskReg); // grad_h_in_f32 * h_pre783+ valueMaskReg); // grad_h_in_f32 * h_pre
788 AscendC::MicroAPI::Mul(gradHPreReg, xCastReg, gradHInCastReg, valueMaskReg); // x_f32 *784 AscendC::MicroAPI::Mul(gradHPreReg, xCastReg, gradHInCastReg, valueMaskReg); // x_f32 *
789 // grad_h_in_f32785 // grad_h_in_f32
790 AscendC::MicroAPI::Reduce<MicroAPI::ReduceType::SUM, U, U>(gradHPreReg, gradHPreReg,786 AscendC::MicroAPI::Reduce<MicroAPI::ReduceType::SUM, U, U>(gradHPreReg, gradHPreReg,
@@ -1457,7 +1453,7 @@ __aicore__ inline void MhcPreSinkhornBackwardDeterministic<X_T, GRADHIN_T, U>::P
1457 // === Phase D: AIC Matmul ===1453 // === Phase D: AIC Matmul ===
1458 if ASCEND_IS_AIC {1454 if ASCEND_IS_AIC {
1459 CrossCoreWaitFlag<AIV_AIC_MODE>(PIPE_MTE3_FLAG);1455 CrossCoreWaitFlag<AIV_AIC_MODE>(PIPE_MTE3_FLAG);
1460- int64_t totalSize = batchSize_ * seqLength_;1456+ int64_t totalSize = bsCount_;
1461 int64_t taskNumPerCore = Ops::Base::CeilDiv(totalSize, aicNum_);1457 int64_t taskNumPerCore = Ops::Base::CeilDiv(totalSize, aicNum_);
1462 int64_t taskOffset = blockIdx_ * taskNumPerCore;1458 int64_t taskOffset = blockIdx_ * taskNumPerCore;
1463 taskNumPerCore = MinValue(taskNumPerCore, totalSize - blockIdx_ * taskNumPerCore);1459 taskNumPerCore = MinValue(taskNumPerCore, totalSize - blockIdx_ * taskNumPerCore);
@@ -59,7 +59,30 @@ MhcPreSinkhornBackward 算子 Golden实现
59================================================================================59================================================================================
60"""60"""
61 61 
62+import numpy as np
62import torch63import torch
64+from ml_dtypes import bfloat16 as np_bfloat16
65+ 
66+ 
67+def _torch_to_numpy(t):
68+ """torch.Tensor -> numpy.ndarray,支持 bf16(通过 view(int16) 桥接)"""
69+ if t is None:
70+ return None
71+ if t.dtype == torch.bfloat16:
72+ return t.view(torch.int16).numpy().view(np_bfloat16)
73+ return t.numpy()
74+ 
75+ 
76+def _numpy_to_torch(t, dtype=torch.float32):
77+ """numpy.ndarray -> torch.Tensor,支持 bf16 输入(先 view int16 读出再转目标 dtype)"""
78+ if t is None:
79+ return None
80+ if isinstance(t, np.ndarray) and t.dtype == np_bfloat16:
81+ return torch.from_numpy(t.view(np.int16).copy()).view(torch.bfloat16).to(dtype)
82+ if hasattr(t, "numpy"):
83+ return t.to(dtype)
84+ return torch.from_numpy(t).to(dtype)
85+ 
63 86 
64__golden__ = {87__golden__ = {
65 "kernel": {"mhc_pre_sinkhorn_backward": "mhc_pre_sinkhorn_backward_golden"},88 "kernel": {"mhc_pre_sinkhorn_backward": "mhc_pre_sinkhorn_backward_golden"},
@@ -129,25 +152,30 @@ def mhc_pre_sinkhorn_backward_golden(
129 所有输入均为 numpy.ndarray,返回 numpy.ndarray。152 所有输入均为 numpy.ndarray,返回 numpy.ndarray。
130 """153 """
131 154 
132- def _to_torch(t, dtype=torch.float32):155+ grad_hin_t = _numpy_to_torch(grad_hin)
133- if t is None:156+ grad_h_post_t = _numpy_to_torch(grad_h_post)
134- return None157+ grad_h_res_t = _numpy_to_torch(grad_h_res)
135- if hasattr(t, "numpy"):158+ x_t = _numpy_to_torch(x)
136- return t.to(dtype)159+ phi_t = _numpy_to_torch(phi)
137- return torch.from_numpy(t).to(dtype)160+ alpha_t = _numpy_to_torch(alpha)
161+ bias_t = _numpy_to_torch(bias)
162+ h_pre_t = _numpy_to_torch(h_pre)
163+ hc_before_norm_t = _numpy_to_torch(hc_before_norm)
164+ inv_rms_t = _numpy_to_torch(inv_rms)
165+ sum_out_t = _numpy_to_torch(sum_out)
166+ norm_out_t = _numpy_to_torch(norm_out)
138 167 
139- grad_hin_t = _to_torch(grad_hin)168+ is_3d = x_t.dim() == 3
140- grad_h_post_t = _to_torch(grad_h_post)169+ if is_3d:
141- grad_h_res_t = _to_torch(grad_h_res)170+ x_t = x_t.unsqueeze(0)
142- x_t = _to_torch(x)171+ grad_hin_t = grad_hin_t.unsqueeze(0)
143- phi_t = _to_torch(phi)172+ grad_h_post_t = grad_h_post_t.unsqueeze(0)
144- alpha_t = _to_torch(alpha)173+ grad_h_res_t = grad_h_res_t.unsqueeze(0)
145- bias_t = _to_torch(bias)174+ h_pre_t = h_pre_t.unsqueeze(0)
146- h_pre_t = _to_torch(h_pre)175+ hc_before_norm_t = hc_before_norm_t.unsqueeze(0)
147- hc_before_norm_t = _to_torch(hc_before_norm)176+ inv_rms_t = inv_rms_t.unsqueeze(0)
148- inv_rms_t = _to_torch(inv_rms)177+ sum_out_t = sum_out_t.unsqueeze(1)
149- sum_out_t = _to_torch(sum_out)178+ norm_out_t = norm_out_t.unsqueeze(1)
150- norm_out_t = _to_torch(norm_out)
151 179 
152 B, S, n, d = x_t.shape180 B, S, n, d = x_t.shape
153 181 
@@ -195,9 +223,17 @@ def mhc_pre_sinkhorn_backward_golden(
195 grad_x_from_hin.view(x_t.shape)223 grad_x_from_hin.view(x_t.shape)
196 + grad_x_from_rms.view(x_t.shape)224 + grad_x_from_rms.view(x_t.shape)
197 + grad_x_from_matmul.view(x_t.shape)225 + grad_x_from_matmul.view(x_t.shape)
198- ).to(x.dtype if torch.is_tensor(x) else torch.float32)226+ )
199 227 
200- grad_x_np = grad_x.numpy()228+ if is_3d:
229+ grad_x = grad_x.view(-1, n, d)
230+ 
231+ is_bf16 = isinstance(x, np.ndarray) and x.dtype == np_bfloat16
232+ if is_bf16:
233+ grad_x = grad_x.to(torch.bfloat16)
234+ grad_x_np = _torch_to_numpy(grad_x)
235+ else:
236+ grad_x_np = grad_x.numpy()
201 grad_phi_np = grad_phi.numpy()237 grad_phi_np = grad_phi.numpy()
202 grad_alpha_np = grad_alpha.numpy()238 grad_alpha_np = grad_alpha.numpy()
203 grad_bias_np = grad_bias.numpy()239 grad_bias_np = grad_bias.numpy()
@@ -240,29 +276,39 @@ def aclnn_mhc_pre_sinkhorn_backward_golden(
240 Output tensors: gradX, gradPhi, gradAlpha, gradBias276 Output tensors: gradX, gradPhi, gradAlpha, gradBias
241 """277 """
242 278 
243- def _to_numpy(t):279+ if isinstance(x, torch.Tensor):
244- if t is None:280+ x_dtype = x.dtype
245- return None281+ elif isinstance(x, np.ndarray) and x.dtype == np_bfloat16:
246- if hasattr(t, "numpy"):282+ x_dtype = torch.bfloat16
247- if t.dtype == torch.bfloat16:283+ elif isinstance(x, np.ndarray):
248- return t.float().numpy()284+ x_dtype = None
249- return t.numpy()285+ else:
250- return t286+ x_dtype = None
251 287 
252- x_dtype = x.dtype if isinstance(x, torch.Tensor) else None288+ grad_hin_np = (
253- 289+ _torch_to_numpy(gradHin) if isinstance(gradHin, torch.Tensor) else gradHin
254- grad_hin_np = _to_numpy(gradHin)290+ )
255- grad_h_post_np = _to_numpy(gradHPost)291+ grad_h_post_np = (
256- grad_h_res_np = _to_numpy(gradHRes)292+ _torch_to_numpy(gradHPost) if isinstance(gradHPost, torch.Tensor) else gradHPost
257- x_np = _to_numpy(x)293+ )
258- phi_np = _to_numpy(phi)294+ grad_h_res_np = (
259- alpha_np = _to_numpy(alpha)295+ _torch_to_numpy(gradHRes) if isinstance(gradHRes, torch.Tensor) else gradHRes
260- bias_np = _to_numpy(bias)296+ )
261- h_pre_np = _to_numpy(hPre)297+ x_np = _torch_to_numpy(x) if isinstance(x, torch.Tensor) else x
262- hc_before_norm_np = _to_numpy(hcBeforeNorm)298+ phi_np = _torch_to_numpy(phi) if isinstance(phi, torch.Tensor) else phi
263- inv_rms_np = _to_numpy(invRms)299+ alpha_np = _torch_to_numpy(alpha) if isinstance(alpha, torch.Tensor) else alpha
264- sum_out_np = _to_numpy(sumOut)300+ bias_np = _torch_to_numpy(bias) if isinstance(bias, torch.Tensor) else bias
265- norm_out_np = _to_numpy(normOut)301+ h_pre_np = _torch_to_numpy(hPre) if isinstance(hPre, torch.Tensor) else hPre
302+ hc_before_norm_np = (
303+ _torch_to_numpy(hcBeforeNorm)
304+ if isinstance(hcBeforeNorm, torch.Tensor)
305+ else hcBeforeNorm
306+ )
307+ inv_rms_np = _torch_to_numpy(invRms) if isinstance(invRms, torch.Tensor) else invRms
308+ sum_out_np = _torch_to_numpy(sumOut) if isinstance(sumOut, torch.Tensor) else sumOut
309+ norm_out_np = (
310+ _torch_to_numpy(normOut) if isinstance(normOut, torch.Tensor) else normOut
311+ )
266 312 
267 hc_eps_val = float(hcEps) if hcEps is not None else 1e-6313 hc_eps_val = float(hcEps) if hcEps is not None else 1e-6
268 314 
@@ -284,10 +330,10 @@ def aclnn_mhc_pre_sinkhorn_backward_golden(
284 )330 )
285 )331 )
286 332 
287- grad_x_tensor = torch.from_numpy(grad_x_np)333+ grad_x_tensor = _numpy_to_torch(grad_x_np)
288- grad_phi_tensor = torch.from_numpy(grad_phi_np)334+ grad_phi_tensor = _numpy_to_torch(grad_phi_np)
289- grad_alpha_tensor = torch.from_numpy(grad_alpha_np)335+ grad_alpha_tensor = _numpy_to_torch(grad_alpha_np)
290- grad_bias_tensor = torch.from_numpy(grad_bias_np)336+ grad_bias_tensor = _numpy_to_torch(grad_bias_np)
291 337 
292 if x_dtype == torch.bfloat16:338 if x_dtype == torch.bfloat16:
293 grad_x_tensor = grad_x_tensor.to(torch.bfloat16)339 grad_x_tensor = grad_x_tensor.to(torch.bfloat16)
@@ -0,0 +1,208 @@
1+# -----------------------------------------------------------------------------------------------------------
2+# Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+# CANN Open Software License Agreement Version 2.0 (the "License").
5+# Please refer to the License for details. You may not use this file except in compliance with the License.
6+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+# See LICENSE in the root of the software repository for the full text of the License.
9+# -----------------------------------------------------------------------------------------------------------
10+ 
11+import torch
12+ 
13+__input__ = {
14+ "aclnn": {"aclnnMhcPreSinkhornBackward": "mhc_pre_sinkhorn_backward_input"},
15+}
16+ 
17+ 
18+def _sigmoid_grad(z, dy, is_pre=False, hc_eps=1e-6):
19+ y = torch.sigmoid(z)
20+ sigma = y - hc_eps if is_pre else y
21+ return dy * sigma * (1 - sigma)
22+ 
23+ 
24+def _rms_norm_grad(x, inv_rms, grad_inv_rms):
25+ nc = x.size(-1)
26+ return -(inv_rms**3) * x * grad_inv_rms / float(nc)
27+ 
28+ 
29+def _exp_grad(x, y_grad):
30+ nd = x.size(-1)
31+ x_max, idx = x.max(dim=-1, keepdim=True)
32+ arange_idx = torch.arange(nd, device=x.device)[None, :]
33+ is_max = idx == arange_idx
34+ y = (x - x_max).exp()
35+ sum_all = (y * y_grad).sum(dim=-1, keepdim=True)
36+ return y * y_grad - is_max * sum_all
37+ 
38+ 
39+def _sinkhorn_grad(grad_h_res, sum_out, norm_out):
40+ bs, seq_len, n, _ = grad_h_res.shape
41+ x_grad = grad_h_res
42+ it2, B_, S_, n_ = sum_out.shape
43+ iters = it2 // 2
44+ sum_out = sum_out.reshape(iters, 2, B_, S_, n_)
45+ norm_out = norm_out.reshape(iters, 2, B_, S_, n_, n_)
46+ for i in reversed(range(iters)):
47+ row_sum = sum_out[i][0].view(bs, seq_len, n, 1)
48+ col_sum = sum_out[i][1].view(bs, seq_len, 1, n)
49+ xrn = norm_out[i][0].view(bs, seq_len, n, n)
50+ gxrn = x_grad / col_sum - (x_grad * xrn / (col_sum**2)).sum(
51+ dim=-2, keepdim=True
52+ )
53+ x_grad = gxrn / row_sum - (gxrn * xrn / row_sum).sum(dim=-1, keepdim=True)
54+ return x_grad
55+ 
56+ 
57+def mhc_pre_sinkhorn_backward_input(
58+ grad_hin,
59+ grad_h_post,
60+ grad_h_res,
61+ x,
62+ phi,
63+ alpha,
64+ bias,
65+ h_pre,
66+ hc_before_norm,
67+ inv_rms,
68+ sum_out,
69+ norm_out,
70+ hc_eps,
71+ grad_x_out,
72+ grad_phi_out,
73+ grad_alpha_out,
74+ grad_bias_out,
75+ **kwargs,
76+):
77+ is_3d = x.dim() == 3
78+ n = x.shape[-2]
79+ c = x.shape[-1]
80+ sinkhorn_iters = int(sum_out.shape[0] // 2)
81+ hc_eps_val = float(hc_eps)
82+ hm = n * n + 2 * n
83+ 
84+ x.copy_(torch.randn_like(x))
85+ phi.copy_(torch.randn(phi.shape, dtype=torch.float32, device=x.device))
86+ alpha.copy_(torch.randn(3, dtype=torch.float32, device=x.device) * 0.1)
87+ bias.copy_(torch.randn(hm, dtype=torch.float32, device=x.device))
88+ 
89+ x_fp32 = x.float()
90+ x_flat = x_fp32.reshape(*x_fp32.shape[:-2], -1)
91+ 
92+ hcbn = torch.nn.functional.linear(x_flat, phi) + bias
93+ inv_rms_val = torch.rsqrt(x_flat.square().mean(-1, keepdim=True) + hc_eps_val)
94+ nf = hcbn * inv_rms_val
95+ 
96+ z_pre = nf[..., :n] * alpha[0] + bias[:n]
97+ z_post = nf[..., n : 2 * n] * alpha[1] + bias[n : 2 * n]
98+ z_res = nf[..., 2 * n :] * alpha[2] + bias[2 * n :]
99+ 
100+ h_pre_val = torch.sigmoid(z_pre + hc_eps_val)
101+ h_post = 2 * torch.sigmoid(z_post)
102+ 
103+ comb = z_res.reshape(*z_res.shape[:-1], n, n)
104+ comb = torch.exp(comb - comb.max(dim=-1, keepdim=True).values)
105+ 
106+ sum_out_list = []
107+ norm_out_list = []
108+ for _ in range(sinkhorn_iters):
109+ row_sum = comb.sum(dim=-1, keepdim=True)
110+ comb = comb / (row_sum + hc_eps_val)
111+ norm_out_list.append(comb)
112+ sum_out_list.append(row_sum.squeeze(-1) + hc_eps_val)
113+ col_sum = comb.sum(dim=-2, keepdim=True)
114+ comb = comb / (col_sum + hc_eps_val)
115+ sum_out_list.append(col_sum.squeeze(-2) + hc_eps_val)
116+ norm_out_list.append(comb)
117+ 
118+ sum_out_val = torch.stack(sum_out_list, dim=0)
119+ norm_out_val = torch.stack(norm_out_list, dim=0)
120+ hin = (h_pre_val.unsqueeze(-1) * x_fp32).sum(-2).to(x.dtype)
121+ 
122+ h_pre.copy_(h_pre_val.detach())
123+ hc_before_norm.copy_(hcbn.detach())
124+ inv_rms.copy_(inv_rms_val.detach())
125+ sum_out.copy_(sum_out_val.detach())
126+ norm_out.copy_(norm_out_val.detach())
127+ 
128+ grad_hin.copy_(torch.randn(grad_hin.shape, dtype=x.dtype, device=x.device))
129+ grad_h_post.copy_(
130+ torch.randn(h_pre_val.shape, dtype=torch.float32, device=x.device)
131+ )
132+ grad_h_res.copy_(
133+ torch.randn(grad_h_res.shape, dtype=torch.float32, device=x.device)
134+ )
135+ 
136+ if is_3d:
137+ x4 = x_fp32.unsqueeze(0)
138+ gh4 = grad_hin.float().unsqueeze(0)
139+ gp4 = grad_h_post.unsqueeze(0)
140+ ghres4 = grad_h_res.unsqueeze(0)
141+ hp4 = h_pre_val.unsqueeze(0)
142+ hcbn4 = hcbn.unsqueeze(0)
143+ invr4 = inv_rms_val.unsqueeze(0)
144+ suma = sum_out_val.unsqueeze(1)
145+ norm4 = norm_out_val.unsqueeze(1)
146+ else:
147+ x4, gh4, gp4, ghres4 = x_fp32, grad_hin.float(), grad_h_post, grad_h_res
148+ hp4, hcbn4, invr4 = h_pre_val, hcbn, inv_rms_val
149+ suma, norm4 = sum_out_val, norm_out_val
150+ 
151+ B4, S4, n4, d4 = x4.shape
152+ 
153+ grad_x_hin = gh4[..., None, :] * hp4[..., None]
154+ g_hpre = (gh4[..., None, :] * x4).sum(-1)
155+ 
156+ nf4 = hcbn4 * invr4
157+ zp4 = nf4[..., :n4] * alpha[0] + bias[:n4]
158+ zpost4 = nf4[..., n4 : 2 * n4] * alpha[1] + bias[n4 : 2 * n4]
159+ zres4 = (nf4[..., 2 * n4 :] * alpha[2] + bias[2 * n4 :]).reshape(B4, S4, n4, n4)
160+ 
161+ gzp4 = _sigmoid_grad(zp4, g_hpre, is_pre=True, hc_eps=hc_eps_val)
162+ gzpost4 = 2 * _sigmoid_grad(zpost4, gp4, is_pre=False, hc_eps=hc_eps_val)
163+ skg4 = _sinkhorn_grad(ghres4, suma, norm4)
164+ gzres4 = _exp_grad(zres4, skg4).flatten(2)
165+ 
166+ gold_bias = torch.cat([gzp4.sum((0, 1)), gzpost4.sum((0, 1)), gzres4.sum((0, 1))])
167+ ga_pre = (nf4[..., :n4] * gzp4).sum()
168+ ga_post = (nf4[..., n4 : 2 * n4] * gzpost4).sum()
169+ ga_res = (nf4[..., 2 * n4 :] * gzres4).sum()
170+ gold_alpha = torch.tensor(
171+ [ga_pre, ga_post, ga_res], dtype=torch.float32, device=x.device
172+ )
173+ 
174+ gn4 = torch.cat([gzp4 * alpha[0], gzpost4 * alpha[1], gzres4 * alpha[2]], dim=-1)
175+ ghcbn4 = gn4 * invr4
176+ ginvr4 = (hcbn4 * gn4).sum(-1, keepdim=True)
177+ gx_rms4 = _rms_norm_grad(x4.flatten(2), invr4, ginvr4)
178+ gx_mm4 = ghcbn4 @ phi
179+ gold_phi = ghcbn4.flatten(0, 1).T @ x4.flatten(2).flatten(0, 1)
180+ gold_x = grad_x_hin + gx_rms4.view(x4.shape) + gx_mm4.view(x4.shape)
181+ 
182+ if is_3d:
183+ gold_x = gold_x.view(-1, n4, d4)
184+ 
185+ grad_x_out.copy_(gold_x.to(x.dtype))
186+ grad_phi_out.copy_(gold_phi)
187+ grad_alpha_out.copy_(gold_alpha)
188+ grad_bias_out.copy_(gold_bias)
189+ 
190+ return [
191+ grad_hin,
192+ grad_h_post,
193+ grad_h_res,
194+ x.detach(),
195+ phi.detach(),
196+ alpha.detach(),
197+ bias.detach(),
198+ h_pre,
199+ hc_before_norm,
200+ inv_rms,
201+ sum_out,
202+ norm_out,
203+ hc_eps,
204+ grad_x_out,
205+ grad_phi_out,
206+ grad_alpha_out,
207+ grad_bias_out,
208+ ]
@@ -0,0 +1,14 @@
1+# -----------------------------------------------------------------------------------------------------------
2+# Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+# CANN Open Software License Agreement Version 2.0 (the "License").
5+# Please refer to the License for details. You may not use this file except in compliance with the License.
6+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+# See LICENSE in the root of the software repository for the full text of the License.
9+# -----------------------------------------------------------------------------------------------------------
10+ 
11+message(STATUS "=== Debug: target_sources add test_aclnn_mhc_pre_sinkhorn_backward")
12+if(UT_TEST_ALL OR OP_API_UT)
13+ add_modules_ut_sources(UT_NAME ${OP_API_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR})
14+endif()
@@ -0,0 +1,230 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+#include <vector>
12+#include <array>
13+#include <gtest/gtest.h>
14+#include "../../../../op_host/op_api/aclnn_mhc_pre_sinkhorn_backward.h"
15+#include "op_api_ut_common/tensor_desc.h"
16+#include "op_api_ut_common/scalar_desc.h"
17+#include "op_api_ut_common/op_api_ut.h"
18+#include "opdev/platform.h"
19+ 
20+using namespace std;
21+using namespace op;
22+ 
23+class MhcPreSinkhornBackwardOpapiUt : public testing::Test {
24+protected:
25+ static void SetUpTestCase()
26+ {
27+ cout << "MhcPreSinkhornBackwardOpapiUt SetUp" << endl;
28+ }
29+ 
30+ static void TearDownTestCase()
31+ {
32+ cout << "MhcPreSinkhornBackwardOpapiUt TearDown" << endl;
33+ }
34+};
35+ 
36+TEST_F(MhcPreSinkhornBackwardOpapiUt, aclnn_mhc_pre_sinkhorn_backward_basic_4d_bf16)
37+{
38+ int64_t B = 2;
39+ int64_t S = 128;
40+ int64_t N = 4;
41+ int64_t C = 256;
42+ int64_t skIterCount = 20;
43+ int64_t hcMix = N * N + 2 * N;
44+ float hcEps = 1e-6f;
45+ 
46+ auto gradHin = TensorDesc({B, S, C}, ACL_BF16, ACL_FORMAT_ND);
47+ auto gradHPost = TensorDesc({B, S, N}, ACL_FLOAT, ACL_FORMAT_ND);
48+ auto gradHRes = TensorDesc({B, S, N, N}, ACL_FLOAT, ACL_FORMAT_ND);
49+ auto x = TensorDesc({B, S, N, C}, ACL_BF16, ACL_FORMAT_ND);
50+ auto phi = TensorDesc({hcMix, N * C}, ACL_FLOAT, ACL_FORMAT_ND);
51+ auto alpha = TensorDesc({3}, ACL_FLOAT, ACL_FORMAT_ND);
52+ auto bias = TensorDesc({hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
53+ auto hPre = TensorDesc({B, S, N}, ACL_FLOAT, ACL_FORMAT_ND);
54+ auto hcBeforeNorm = TensorDesc({B, S, hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
55+ auto invRms = TensorDesc({B, S, 1}, ACL_FLOAT, ACL_FORMAT_ND);
56+ auto sumOut = TensorDesc({skIterCount * 2, B, S, N}, ACL_FLOAT, ACL_FORMAT_ND);
57+ auto normOut = TensorDesc({skIterCount * 2, B, S, N, N}, ACL_FLOAT, ACL_FORMAT_ND);
58+ auto eps = 1e-6;
59+ 
60+ auto gradX = TensorDesc({B, S, N, C}, ACL_BF16, ACL_FORMAT_ND);
61+ auto gradPhi = TensorDesc({hcMix, N * C}, ACL_FLOAT, ACL_FORMAT_ND);
62+ auto gradAlpha = TensorDesc({3}, ACL_FLOAT, ACL_FORMAT_ND);
63+ auto gradBias = TensorDesc({hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
64+ 
65+ auto ut = OP_API_UT(
66+ aclnnMhcPreSinkhornBackward,
67+ INPUT(gradHin, gradHPost, gradHRes, x, phi, alpha, bias, hPre, hcBeforeNorm, invRms, sumOut, normOut, eps),
68+ OUTPUT(gradX, gradPhi, gradAlpha, gradBias));
69+ 
70+ uint64_t workspaceSize = 0;
71+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
72+ EXPECT_EQ(aclRet, ACL_SUCCESS);
73+}
74+ 
75+TEST_F(MhcPreSinkhornBackwardOpapiUt, aclnn_mhc_pre_sinkhorn_backward_basic_3d_bf16)
76+{
77+ int64_t T = 256;
78+ int64_t N = 4;
79+ int64_t C = 256;
80+ int64_t skIterCount = 20;
81+ int64_t hcMix = N * N + 2 * N;
82+ float hcEps = 1e-6f;
83+ 
84+ auto gradHin = TensorDesc({T, C}, ACL_BF16, ACL_FORMAT_ND);
85+ auto gradHPost = TensorDesc({T, N}, ACL_FLOAT, ACL_FORMAT_ND);
86+ auto gradHRes = TensorDesc({T, N, N}, ACL_FLOAT, ACL_FORMAT_ND);
87+ auto x = TensorDesc({T, N, C}, ACL_BF16, ACL_FORMAT_ND);
88+ auto phi = TensorDesc({hcMix, N * C}, ACL_FLOAT, ACL_FORMAT_ND);
89+ auto alpha = TensorDesc({3}, ACL_FLOAT, ACL_FORMAT_ND);
90+ auto bias = TensorDesc({hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
91+ auto hPre = TensorDesc({T, N}, ACL_FLOAT, ACL_FORMAT_ND);
92+ auto hcBeforeNorm = TensorDesc({T, hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
93+ auto invRms = TensorDesc({T, 1}, ACL_FLOAT, ACL_FORMAT_ND);
94+ auto sumOut = TensorDesc({skIterCount * 2, T, N}, ACL_FLOAT, ACL_FORMAT_ND);
95+ auto normOut = TensorDesc({skIterCount * 2, T, N, N}, ACL_FLOAT, ACL_FORMAT_ND);
96+ auto eps = 1e-6;
97+ 
98+ auto gradX = TensorDesc({T, N, C}, ACL_BF16, ACL_FORMAT_ND);
99+ auto gradPhi = TensorDesc({hcMix, N * C}, ACL_FLOAT, ACL_FORMAT_ND);
100+ auto gradAlpha = TensorDesc({3}, ACL_FLOAT, ACL_FORMAT_ND);
101+ auto gradBias = TensorDesc({hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
102+ 
103+ auto ut = OP_API_UT(
104+ aclnnMhcPreSinkhornBackward,
105+ INPUT(gradHin, gradHPost, gradHRes, x, phi, alpha, bias, hPre, hcBeforeNorm, invRms, sumOut, normOut, eps),
106+ OUTPUT(gradX, gradPhi, gradAlpha, gradBias));
107+ 
108+ uint64_t workspaceSize = 0;
109+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
110+ EXPECT_EQ(aclRet, ACL_SUCCESS);
111+}
112+ 
113+TEST_F(MhcPreSinkhornBackwardOpapiUt, aclnn_mhc_pre_sinkhorn_backward_empty_tensor_4d_B0)
114+{
115+ int64_t B = 0;
116+ int64_t S = 128;
117+ int64_t N = 4;
118+ int64_t C = 256;
119+ int64_t skIterCount = 20;
120+ int64_t hcMix = N * N + 2 * N;
121+ float hcEps = 1e-6f;
122+ 
123+ auto gradHin = TensorDesc({B, S, C}, ACL_BF16, ACL_FORMAT_ND);
124+ auto gradHPost = TensorDesc({B, S, N}, ACL_FLOAT, ACL_FORMAT_ND);
125+ auto gradHRes = TensorDesc({B, S, N, N}, ACL_FLOAT, ACL_FORMAT_ND);
126+ auto x = TensorDesc({B, S, N, C}, ACL_BF16, ACL_FORMAT_ND);
127+ auto phi = TensorDesc({hcMix, N * C}, ACL_FLOAT, ACL_FORMAT_ND);
128+ auto alpha = TensorDesc({3}, ACL_FLOAT, ACL_FORMAT_ND);
129+ auto bias = TensorDesc({hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
130+ auto hPre = TensorDesc({B, S, N}, ACL_FLOAT, ACL_FORMAT_ND);
131+ auto hcBeforeNorm = TensorDesc({B, S, hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
132+ auto invRms = TensorDesc({B, S, 1}, ACL_FLOAT, ACL_FORMAT_ND);
133+ auto sumOut = TensorDesc({skIterCount * 2, B, S, N}, ACL_FLOAT, ACL_FORMAT_ND);
134+ auto normOut = TensorDesc({skIterCount * 2, B, S, N, N}, ACL_FLOAT, ACL_FORMAT_ND);
135+ auto eps = 1e-6;
136+ 
137+ auto gradX = TensorDesc({B, S, N, C}, ACL_BF16, ACL_FORMAT_ND);
138+ auto gradPhi = TensorDesc({hcMix, N * C}, ACL_FLOAT, ACL_FORMAT_ND);
139+ auto gradAlpha = TensorDesc({3}, ACL_FLOAT, ACL_FORMAT_ND);
140+ auto gradBias = TensorDesc({hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
141+ 
142+ auto ut = OP_API_UT(
143+ aclnnMhcPreSinkhornBackward,
144+ INPUT(gradHin, gradHPost, gradHRes, x, phi, alpha, bias, hPre, hcBeforeNorm, invRms, sumOut, normOut, eps),
145+ OUTPUT(gradX, gradPhi, gradAlpha, gradBias));
146+ 
147+ uint64_t workspaceSize = 0;
148+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
149+ EXPECT_EQ(aclRet, ACL_SUCCESS);
150+ EXPECT_EQ(workspaceSize, 0);
151+}
152+ 
153+TEST_F(MhcPreSinkhornBackwardOpapiUt, aclnn_mhc_pre_sinkhorn_backward_empty_tensor_4d_S0)
154+{
155+ int64_t B = 2;
156+ int64_t S = 0;
157+ int64_t N = 4;
158+ int64_t C = 256;
159+ int64_t skIterCount = 20;
160+ int64_t hcMix = N * N + 2 * N;
161+ float hcEps = 1e-6f;
162+ 
163+ auto gradHin = TensorDesc({B, S, C}, ACL_BF16, ACL_FORMAT_ND);
164+ auto gradHPost = TensorDesc({B, S, N}, ACL_FLOAT, ACL_FORMAT_ND);
165+ auto gradHRes = TensorDesc({B, S, N, N}, ACL_FLOAT, ACL_FORMAT_ND);
166+ auto x = TensorDesc({B, S, N, C}, ACL_BF16, ACL_FORMAT_ND);
167+ auto phi = TensorDesc({hcMix, N * C}, ACL_FLOAT, ACL_FORMAT_ND);
168+ auto alpha = TensorDesc({3}, ACL_FLOAT, ACL_FORMAT_ND);
169+ auto bias = TensorDesc({hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
170+ auto hPre = TensorDesc({B, S, N}, ACL_FLOAT, ACL_FORMAT_ND);
171+ auto hcBeforeNorm = TensorDesc({B, S, hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
172+ auto invRms = TensorDesc({B, S, 1}, ACL_FLOAT, ACL_FORMAT_ND);
173+ auto sumOut = TensorDesc({skIterCount * 2, B, S, N}, ACL_FLOAT, ACL_FORMAT_ND);
174+ auto normOut = TensorDesc({skIterCount * 2, B, S, N, N}, ACL_FLOAT, ACL_FORMAT_ND);
175+ auto eps = 1e-6;
176+ 
177+ auto gradX = TensorDesc({B, S, N, C}, ACL_BF16, ACL_FORMAT_ND);
178+ auto gradPhi = TensorDesc({hcMix, N * C}, ACL_FLOAT, ACL_FORMAT_ND);
179+ auto gradAlpha = TensorDesc({3}, ACL_FLOAT, ACL_FORMAT_ND);
180+ auto gradBias = TensorDesc({hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
181+ 
182+ auto ut = OP_API_UT(
183+ aclnnMhcPreSinkhornBackward,
184+ INPUT(gradHin, gradHPost, gradHRes, x, phi, alpha, bias, hPre, hcBeforeNorm, invRms, sumOut, normOut, eps),
185+ OUTPUT(gradX, gradPhi, gradAlpha, gradBias));
186+ 
187+ uint64_t workspaceSize = 0;
188+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
189+ EXPECT_EQ(aclRet, ACL_SUCCESS);
190+ EXPECT_EQ(workspaceSize, 0);
191+}
192+ 
193+TEST_F(MhcPreSinkhornBackwardOpapiUt, aclnn_mhc_pre_sinkhorn_backward_empty_tensor_3d_T0)
194+{
195+ int64_t T = 0;
196+ int64_t N = 4;
197+ int64_t C = 256;
198+ int64_t skIterCount = 20;
199+ int64_t hcMix = N * N + 2 * N;
200+ float hcEps = 1e-6f;
201+ 
202+ auto gradHin = TensorDesc({T, C}, ACL_BF16, ACL_FORMAT_ND);
203+ auto gradHPost = TensorDesc({T, N}, ACL_FLOAT, ACL_FORMAT_ND);
204+ auto gradHRes = TensorDesc({T, N, N}, ACL_FLOAT, ACL_FORMAT_ND);
205+ auto x = TensorDesc({T, N, C}, ACL_BF16, ACL_FORMAT_ND);
206+ auto phi = TensorDesc({hcMix, N * C}, ACL_FLOAT, ACL_FORMAT_ND);
207+ auto alpha = TensorDesc({3}, ACL_FLOAT, ACL_FORMAT_ND);
208+ auto bias = TensorDesc({hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
209+ auto hPre = TensorDesc({T, N}, ACL_FLOAT, ACL_FORMAT_ND);
210+ auto hcBeforeNorm = TensorDesc({T, hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
211+ auto invRms = TensorDesc({T, 1}, ACL_FLOAT, ACL_FORMAT_ND);
212+ auto sumOut = TensorDesc({skIterCount * 2, T, N}, ACL_FLOAT, ACL_FORMAT_ND);
213+ auto normOut = TensorDesc({skIterCount * 2, T, N, N}, ACL_FLOAT, ACL_FORMAT_ND);
214+ auto eps = 1e-6;
215+ 
216+ auto gradX = TensorDesc({T, N, C}, ACL_BF16, ACL_FORMAT_ND);
217+ auto gradPhi = TensorDesc({hcMix, N * C}, ACL_FLOAT, ACL_FORMAT_ND);
218+ auto gradAlpha = TensorDesc({3}, ACL_FLOAT, ACL_FORMAT_ND);
219+ auto gradBias = TensorDesc({hcMix}, ACL_FLOAT, ACL_FORMAT_ND);
220+ 
221+ auto ut = OP_API_UT(
222+ aclnnMhcPreSinkhornBackward,
223+ INPUT(gradHin, gradHPost, gradHRes, x, phi, alpha, bias, hPre, hcBeforeNorm, invRms, sumOut, normOut, eps),
224+ OUTPUT(gradX, gradPhi, gradAlpha, gradBias));
225+ 
226+ uint64_t workspaceSize = 0;
227+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
228+ EXPECT_EQ(aclRet, ACL_SUCCESS);
229+ EXPECT_EQ(workspaceSize, 0);
230+}
@@ -350,3 +350,141 @@ TEST_F(MhcPreSinkhornBackwardTiling, test_tiling_B4_S64_N4_C512)
350 350 
351 ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS);351 ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS);
352}352}
353+ 
354+TEST_F(MhcPreSinkhornBackwardTiling, test_tiling_T256_N4_C256_3d)
355+{
356+ int64_t B = 2;
357+ int64_t S = 128;
358+ int64_t T = B * S;
359+ int64_t N = 4;
360+ int64_t C = 256;
361+ int64_t skIterCount = 20;
362+ float eps = 1e-6f;
363+ 
364+ int64_t hcMix = N * N + 2 * N;
365+ int64_t phiDim0 = hcMix;
366+ int64_t phiDim1 = N * C;
367+ 
368+ optiling::MhcPreSinkhornBackwardCompileInfo compileInfo = {};
369+ 
370+ gert::TilingContextPara tilingContextPara(
371+ "MhcPreSinkhornBackward",
372+ {
373+ {{{T, C}, {T, C}}, ge::DT_BF16, ge::FORMAT_ND},
374+ {{{T, N}, {T, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
375+ {{{T, N, N}, {T, N, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
376+ {{{T, N, C}, {T, N, C}}, ge::DT_BF16, ge::FORMAT_ND},
377+ {{{phiDim0, phiDim1}, {phiDim0, phiDim1}}, ge::DT_FLOAT, ge::FORMAT_ND},
378+ {{{3}, {3}}, ge::DT_FLOAT, ge::FORMAT_ND},
379+ {{{hcMix}, {hcMix}}, ge::DT_FLOAT, ge::FORMAT_ND},
380+ {{{T, N}, {T, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
381+ {{{T, hcMix}, {T, hcMix}}, ge::DT_FLOAT, ge::FORMAT_ND},
382+ {{{T, 1}, {T, 1}}, ge::DT_FLOAT, ge::FORMAT_ND},
383+ {{{skIterCount * 2, T, N}, {skIterCount * 2, T, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
384+ {{{skIterCount * 2, T, N, N}, {skIterCount * 2, T, N, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
385+ },
386+ {
387+ {{{T, N, C}, {T, N, C}}, ge::DT_BF16, ge::FORMAT_ND},
388+ {{{phiDim0, phiDim1}, {phiDim0, phiDim1}}, ge::DT_FLOAT, ge::FORMAT_ND},
389+ {{{3}, {3}}, ge::DT_FLOAT, ge::FORMAT_ND},
390+ {{{hcMix}, {hcMix}}, ge::DT_FLOAT, ge::FORMAT_ND},
391+ },
392+ {
393+ {"eps", Ops::Transformer::AnyValue::CreateFrom<float>(eps)},
394+ },
395+ &compileInfo);
396+ 
397+ ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS);
398+}
399+ 
400+TEST_F(MhcPreSinkhornBackwardTiling, test_tiling_T64_N8_C128_3d)
401+{
402+ int64_t B = 1;
403+ int64_t S = 64;
404+ int64_t T = B * S;
405+ int64_t N = 8;
406+ int64_t C = 128;
407+ int64_t skIterCount = 20;
408+ float eps = 1e-6f;
409+ 
410+ int64_t hcMix = N * N + 2 * N;
411+ int64_t phiDim0 = hcMix;
412+ int64_t phiDim1 = N * C;
413+ 
414+ optiling::MhcPreSinkhornBackwardCompileInfo compileInfo = {};
415+ 
416+ gert::TilingContextPara tilingContextPara(
417+ "MhcPreSinkhornBackward",
418+ {
419+ {{{T, C}, {T, C}}, ge::DT_BF16, ge::FORMAT_ND},
420+ {{{T, N}, {T, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
421+ {{{T, N, N}, {T, N, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
422+ {{{T, N, C}, {T, N, C}}, ge::DT_BF16, ge::FORMAT_ND},
423+ {{{phiDim0, phiDim1}, {phiDim0, phiDim1}}, ge::DT_FLOAT, ge::FORMAT_ND},
424+ {{{3}, {3}}, ge::DT_FLOAT, ge::FORMAT_ND},
425+ {{{hcMix}, {hcMix}}, ge::DT_FLOAT, ge::FORMAT_ND},
426+ {{{T, N}, {T, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
427+ {{{T, hcMix}, {T, hcMix}}, ge::DT_FLOAT, ge::FORMAT_ND},
428+ {{{T, 1}, {T, 1}}, ge::DT_FLOAT, ge::FORMAT_ND},
429+ {{{skIterCount * 2, T, N}, {skIterCount * 2, T, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
430+ {{{skIterCount * 2, T, N, N}, {skIterCount * 2, T, N, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
431+ },
432+ {
433+ {{{T, N, C}, {T, N, C}}, ge::DT_BF16, ge::FORMAT_ND},
434+ {{{phiDim0, phiDim1}, {phiDim0, phiDim1}}, ge::DT_FLOAT, ge::FORMAT_ND},
435+ {{{3}, {3}}, ge::DT_FLOAT, ge::FORMAT_ND},
436+ {{{hcMix}, {hcMix}}, ge::DT_FLOAT, ge::FORMAT_ND},
437+ },
438+ {
439+ {"eps", Ops::Transformer::AnyValue::CreateFrom<float>(eps)},
440+ },
441+ &compileInfo);
442+ 
443+ ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS);
444+}
445+ 
446+TEST_F(MhcPreSinkhornBackwardTiling, test_tiling_T64_N9_C128_3d_fail)
447+{
448+ int64_t B = 1;
449+ int64_t S = 64;
450+ int64_t T = B * S;
451+ int64_t N = 9;
452+ int64_t C = 128;
453+ int64_t skIterCount = 20;
454+ float eps = 1e-6f;
455+ 
456+ int64_t hcMix = N * N + 2 * N;
457+ int64_t phiDim0 = hcMix;
458+ int64_t phiDim1 = N * C;
459+ 
460+ optiling::MhcPreSinkhornBackwardCompileInfo compileInfo = {};
461+ 
462+ gert::TilingContextPara tilingContextPara(
463+ "MhcPreSinkhornBackward",
464+ {
465+ {{{T, C}, {T, C}}, ge::DT_BF16, ge::FORMAT_ND},
466+ {{{T, N}, {T, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
467+ {{{T, N, N}, {T, N, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
468+ {{{T, N, C}, {T, N, C}}, ge::DT_BF16, ge::FORMAT_ND},
469+ {{{phiDim0, phiDim1}, {phiDim0, phiDim1}}, ge::DT_FLOAT, ge::FORMAT_ND},
470+ {{{3}, {3}}, ge::DT_FLOAT, ge::FORMAT_ND},
471+ {{{hcMix}, {hcMix}}, ge::DT_FLOAT, ge::FORMAT_ND},
472+ {{{T, N}, {T, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
473+ {{{T, hcMix}, {T, hcMix}}, ge::DT_FLOAT, ge::FORMAT_ND},
474+ {{{T, 1}, {T, 1}}, ge::DT_FLOAT, ge::FORMAT_ND},
475+ {{{skIterCount * 2, T, N}, {skIterCount * 2, T, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
476+ {{{skIterCount * 2, T, N, N}, {skIterCount * 2, T, N, N}}, ge::DT_FLOAT, ge::FORMAT_ND},
477+ },
478+ {
479+ {{{T, N, C}, {T, N, C}}, ge::DT_BF16, ge::FORMAT_ND},
480+ {{{phiDim0, phiDim1}, {phiDim0, phiDim1}}, ge::DT_FLOAT, ge::FORMAT_ND},
481+ {{{3}, {3}}, ge::DT_FLOAT, ge::FORMAT_ND},
482+ {{{hcMix}, {hcMix}}, ge::DT_FLOAT, ge::FORMAT_ND},
483+ },
484+ {
485+ {"eps", Ops::Transformer::AnyValue::CreateFrom<float>(eps)},
486+ },
487+ &compileInfo);
488+ 
489+ ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED);
490+}