Skip to content

Conversation

@luyl975
Copy link
Contributor

@luyl975 luyl975 commented Jul 1, 2025

PR Category

Operator Mechanism

PR Types

Bug fixes

Description

image

修复:
a. 在Paddle代码中检索def as_real,发现as_real的核心实现调用的是_C_ops的as_real
b. 以_C_ops的as_real在paddle/phi/ops/yaml中检索,发现as_real的InferMeta函数使用为:AsRealInferMeta
c. 在代码中检索AsRealInferMeta,其函数体位于paddle\phi\infermeta\unary.cc,检查其对于0-size张量发现并无直接的相关操作
d. 在paddle/phi/kernels中检索as_real(asreal),寻找有关Kernel的相关实现。发现存在函数AsRealStridedKernel,添加对于0-size问题的判定

if (out && out->numel() == 0) {
    if (x.dtype() == DataType::COMPLEX64) {
      out->set_type(DataType::FLOAT32);
    } else if (x.dtype() == DataType::COMPLEX128) {
      out->set_type(DataType::FLOAT64);
    } else {
      PADDLE_THROW(common::errors::Unimplemented(
          "as_real is not supported data type (%s).",
          DataTypeToString(x.dtype())));
    }
    out->set_offset(x.offset());
    out->ResetHolder(x.Holder());
    out->ShareInplaceVersionCounterWith(x);
    return;
  }

PaddleAPITest测试结果:
image

pcard-67164

@paddle-bot
Copy link

paddle-bot bot commented Jul 1, 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.

@paddle-bot paddle-bot bot added the contributor External developers label Jul 1, 2025
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Jul 1, 2025
Comment on lines +32 to +46
if (out && out->numel() == 0) {
if (x.dtype() == DataType::COMPLEX64) {
out->set_type(DataType::FLOAT32);
} else if (x.dtype() == DataType::COMPLEX128) {
out->set_type(DataType::FLOAT64);
} else {
PADDLE_THROW(common::errors::Unimplemented(
"as_real is not supported data type (%s).",
DataTypeToString(x.dtype())));
}
out->set_offset(x.offset());
out->ResetHolder(x.Holder());
out->ShareInplaceVersionCounterWith(x);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修复似乎没有必要。as_real 应该已经被修过了,请修复之前先运行下paddleapitest 尝试能否复现问题,然后进行修复。如果复现不了问题需要添加几个0-size的单测

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢您的回复,经过进一步研究发现有效修改位于paddle/phi/kernels/stride/as_complex_kernel.cc中的AsComplexStridedKernel函数

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以添加几个单测,完善0-size Tensor的验证机制

@paddle-ci-bot
Copy link

paddle-ci-bot bot commented Jul 10, 2025

Sorry to inform you that 6a725bd's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

@luotao1
Copy link
Contributor

luotao1 commented Jul 14, 2025

close due to the following PR is merged:

@luotao1 luotao1 closed this Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants