Add dtype check for MatmulInferMeta #74217
Open
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.
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