Skip to content

Add dtype check for MatmulInferMeta #74217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

zrr1999
Copy link
Member

@zrr1999 zrr1999 commented Jul 24, 2025

PR Category

Operator Mechanism

PR Types

Bug fixes

Description

linear 精度报错与 matmul 相关,暴露出 matmul 的报错信息不明确的问题,给MatmulInferMeta添加额外的检查可以让报错信息更明确。

matmul 的 x 和 y 类型不一致时,目前出现过两种报错
第一种报错
(InvalidArgument) The type of data we are trying to retrieve (float32) does not match the type of data (float16) currently contained in the container.
[Hint: Expected dtype() == phi::CppTypeToDataType::Type(), but received dtype():15 != phi::CppTypeToDataType::Type():10.] (at ../paddle/phi/core/dense_tensor.cc:160)
[operator < linear > error]
第二种报错
Traceback (most recent call last):
File "/workspace/PaddleAPITest/tester/accuracy.py", line 92, in test
exec(code.core_compiled, exec_globals, exec_locals)
File "", line 10, in
File "/workspace/PaddleAPITest/.venv/lib/python3.10/site-packages/torch/utils/_device.py", line 104, in torch_function
return func(*args, **kwargs)
RuntimeError: expected mat1 and mat2 to have the same dtype, but got: c10::Half != float
paddle kernel的核心源码如下

可以看到实际上是要求x和y输入类型一致的,但是不一致时并不会直接报错,因为 MatmulInferMeta 里并没有检查,所以需要添加检查从而减少后续错误排查的工作量。

Pcard-67164

Copy link

paddle-bot bot commented Jul 24, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant