add rule for _C_ops.matmul#640
Open
greenhandF wants to merge 5 commits into
Open
Conversation
cangtianhuang
requested changes
Jun 11, 2026
cangtianhuang
left a comment
Collaborator
There was a problem hiding this comment.
修改后要统一复测一下原有配置,在pr描述里贴上测试结果,要看精度没有大问题~
| or ( | ||
| isinstance(paddle_item, paddle.Tensor) | ||
| and not (paddle_item._is_initialized() or paddle_item.numel() == 0) | ||
| and (not paddle_item._is_initialized() or paddle_item.numel() == 0) |
Collaborator
There was a problem hiding this comment.
这样会影响合法的 0size tensor 正常判断(0size tensor 的 numel 为 0,但是有数据类型与形状),是否能改成:
Suggested change
| and (not paddle_item._is_initialized() or paddle_item.numel() == 0) | |
| and not paddle_item._is_initialized() |
| or ( | ||
| isinstance(paddle_item, paddle.Tensor) | ||
| and not (paddle_item._is_initialized() or paddle_item.numel() == 0) | ||
| and (not paddle_item._is_initialized() or paddle_item.numel() == 0) |
Comment on lines
+7483
to
+7484
| do1_e = torch.zeros_like(o1) | ||
| o2_s_e = torch.zeros_like(do2_s) |
Collaborator
There was a problem hiding this comment.
可能 empty_like 更贴切~但是都行
Comment on lines
+7520
to
+7525
| pg_out[s:e] = (do2_c * o2_val).sum(dim=-1) | ||
| # o2_s 写入需在 do1 之前完成时使用 do2_2d 切片;这里 o2_s 与 do1 | ||
| # 来自不同 buffer(即使 inplace 也是 do2_s vs o1),互不影响。 | ||
| o2_s_out[s:e] = (o2_val * prob_c).to(do2_dtype) | ||
| do1_out[s:e, :H] = x0g.to(o1_dtype) | ||
| do1_out[s:e, H:] = x1g.to(o1_dtype) |
Collaborator
There was a problem hiding this comment.
这处切片赋值会对 fp32 的叶子节点进行原地写入,torch 会报错,考虑加 torch.no_grad() 包裹
可以复现一下:
paddle._C_ops._run_custom_op("fused_swiglu_probs_bwd", Tensor([2, 4],"float32"), Tensor([2, 2],"float32"), Tensor([2, 1],"float32"), True, )
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

add mapping and rule for paddle.C_ops.matmul