Skip to content

Conversation

wanghuancoder
Copy link
Contributor

@wanghuancoder wanghuancoder commented Aug 8, 2025

PR Category

Execute Infrastructure

PR Types

New features

Description

动态图支持传入一个out Tensor,用于接受返回值。同时,API也会返回一个Tensor。两者共享显存、autogradmeta。

该能力目前只支持前向、只有一个output、非inplace的场景。strings、sparse、反向、多输出暂不支持该功能。

如果API层需要该功能可以直接改造_C_ops的调用,比如从:

_C_ops.complex(real, imag)

改造为:

paddle.Tensor out_tensor
_C_ops.complex(real, imag, out=out_tensor)

对于API改造支持out能力建议修改步骤:

  1. 修改API签名,新增out参数,并修改中英文文档
  2. 修改_C_ops调用
  3. 添加单测,单测应参考本PR中test_complex_op的新增单测:1)测试4中output的场景;2)设计一个小的组网,检查前向返回值,和反向梯度的一致性。
  4. 检查_C_ops传入out和不传入out的一致性。
    具体可参考本PR的:
    python/paddle/tensor/creation.py
    test/legacy_test/test_complex_op.py

TODO:

  1. 对于多output输出的场景,机制暂时没能支持,有需求的API还得通过paddle.assign实现
  2. PIR暂未支持out,这有动静不一致问题,需后续处理

Pcard-67164

Copy link

paddle-bot bot commented Aug 8, 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.

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

@wanghuancoder wanghuancoder merged commit 9e9428c into PaddlePaddle:develop Aug 11, 2025
107 of 112 checks passed
Enigmatisms pushed a commit to Enigmatisms/Paddle that referenced this pull request Aug 11, 2025
* dygraph support input a out Tensor

* refine

* refine

* refine

* refine

* refine

* refine

* refine

* refine
maxiaolong001 pushed a commit to maxiaolong001/Paddle that referenced this pull request Aug 12, 2025
* dygraph support input a out Tensor

* refine

* refine

* refine

* refine

* refine

* refine

* refine

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

Successfully merging this pull request may close these issues.

3 participants