Skip to content
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

fix test_elementwise_sub_op #60078

Closed
wants to merge 2 commits into from
Closed

fix test_elementwise_sub_op #60078

wants to merge 2 commits into from

Conversation

DrRyanHuang
Copy link
Member

PR types

Others

PR changes

Others

Description

Copy link

paddle-bot bot commented Dec 16, 2023

你的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.

@paddle-bot paddle-bot bot added the contributor External developers label Dec 16, 2023
@DrRyanHuang DrRyanHuang changed the title 【PIR OpTest Fix No.31】 fix test_elementwise_sub_op 【PIR OpTest Fix No.22】 fix test_elementwise_sub_op Dec 16, 2023
@kangguangli
Copy link
Contributor

这个算子单测失败的原因应该不是 在PIR下缺少 elementwise_sub算子的定义,在op_compat.yaml 里面已经将elementwise_sub 映射到 subtract。这个问题可能较复杂一点,有兴趣的话可以先分析下单测失败原因。

@DrRyanHuang
Copy link
Member Author

这是单测 test_elementwise_sub_op 报错的log:

W1221 13:44:05.297209 643880 pir_interpreter.cc:1665]  OP id:2 pd_op.mean_all raises an EnforceNotMet exception phi::enforce::EnforceNotMet, In user code:


    InvalidArgumentError: The type of data we are trying to retrieve (float64) does not match the type of data (complex128) currently contained in the container.
      [Hint: Expected dtype() == phi::CppTypeToDataType<T>::Type(), but received dtype():13 != phi::CppTypeToDataType<T>::Type():11.] (at /home/aistudio/Paddle/paddle/phi/core/dense_tensor.cc:171)
      [operator < pd_kernel.phi_kernel > error]

ERROR: test_check_grad_ingore_x (__main__.TestRealComplexElementwiseSubOp)
ERROR: test_check_grad_ingore_y (__main__.TestRealComplexElementwiseSubOp)
ERROR: test_check_grad_normal (__main__.TestRealComplexElementwiseSubOp)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/legacy_test/test_elementwise_sub_op.py", line 856, in test_check_grad_ingore_x
    self.check_grad(
  File "/home/aistudio/Paddle/test/legacy_test/op_test.py", line 2969, in check_grad
    self.check_grad_with_place(
  File "/home/aistudio/Paddle/test/legacy_test/op_test.py", line 3207, in check_grad_with_place
    analytic_grads = self._get_gradient(
  File "/home/aistudio/Paddle/test/legacy_test/op_test.py", line 3671, in _get_gradient
    self._check_ir_grad_output(
  File "/home/aistudio/Paddle/test/legacy_test/op_test.py", line 3513, in _check_ir_grad_output
    executor.run(
  File "/home/aistudio/Paddle/build/python/paddle/base/executor.py", line 1772, in run
    res = self._run_impl(
  File "/home/aistudio/Paddle/build/python/paddle/base/executor.py", line 1978, in _run_impl
    ret = new_exe.run(
  File "/home/aistudio/Paddle/build/python/paddle/base/executor.py", line 827, in run
    tensors = self._new_exe.run(
ValueError: In user code:

    InvalidArgumentError: The type of data we are trying to retrieve (float64) does not match the type of data (complex128) currently contained in the container.
      [Hint: Expected dtype() == phi::CppTypeToDataType<T>::Type(), but received dtype():13 != phi::CppTypeToDataType<T>::Type():11.] (at /home/aistudio/Paddle/paddle/phi/core/dense_tensor.cc:171)
      [operator < pd_kernel.phi_kernel > error]

----------------------------------------------------------------------
Ran 8 tests in 3.073s

FAILED (errors=3)

貌似是 mean_allsubtract infer_meta 函数问题? 但我看他俩的 yaml 文件

- op : mean_all
  args : (Tensor x)
  output : Tensor
  infer_meta :
    func : MeanAllInferMeta
  kernel :
    func : mean_all
  backward : mean_all_grad
void MeanAllInferMeta(const MetaTensor& x, MetaTensor* out) {
  out->set_dims(common::make_ddim({}));
  out->set_dtype(x.dtype());
  out->set_layout(x.layout());
}

都有 out->set_dtype(x.dtype()); 这句呀,输出类型指定了,也不像是 kernel 注册的问题

PD_REGISTER_KERNEL(mean_all,
                   GPU,
                   ALL_LAYOUT,
                   phi::MeanAllKernel,
                   float,
                   double,
                   phi::dtype::float16,
                   phi::dtype::complex<float>,
                   phi::dtype::complex<double>) {}

这里复数类型也都注册过,之前说算子的类型检查下沉到C++侧了, 是这个问题吗? 可以给点提示嘛 😆
@kangguangli

@kangguangli
Copy link
Contributor

这里的问题是pd_op_to_kernel_pass里面在类型提升后没有处理输出的类型,解决方案是在类型提升后再做一次 infer_meta,重新推导输出类型,目前内部同事 @chen2016013 正在开发中,可以关注下。

@DrRyanHuang DrRyanHuang closed this by deleting the head repository Dec 26, 2023
@luotao1 luotao1 changed the title 【PIR OpTest Fix No.22】 fix test_elementwise_sub_op fix test_elementwise_sub_op Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants