Skip to content

Conversation

@SigureMo
Copy link
Member

PR Category

Execute Infrastructure

PR Types

Bug fixes

Description

based on #69142

import paddle


def foo(x):
    y = x + 1
    z = y.reshape([2, 6])
    return z


static_foo = paddle.jit.to_static(foo, full_graph=True)
x = paddle.rand([3, 4], dtype='float32')
x.stop_gradient = False
out = static_foo(x)
ForwardProgram is :
{
    (%0) = "pd_op.data" [id:33] () {dtype:(pd_op.DataType)float32,name:"_jst.0.x.0",place:(pd_op.Place)Place(undefined:0),shape:(pd_op.IntArray)[3,4],stop_gradient:[false]} : () -> builtin.tensor<3x4xf32>
    (%1) = "pd_op.full" [id:34] () {dtype:(pd_op.DataType)float32,place:(pd_op.Place)Place(cpu),shape:(pd_op.IntArray)[1],stop_gradient:[true],value:(Double)1} : () -> builtin.tensor<1xf32>
    (%2) = "pd_op.scale" [id:35] (%0, %1) {bias:(Float)1,bias_after_scale:true,stop_gradient:[false]} : (builtin.tensor<3x4xf32>, builtin.tensor<1xf32>) -> builtin.tensor<3x4xf32>
    (%3) = "pd_op.full_int_array" [id:36] () {dtype:(pd_op.DataType)int64,place:(pd_op.Place)Place(cpu),stop_gradient:[true],value:[(Int64)2,(Int64)6]} : () -> builtin.tensor<2xi64>
    (%4) = "pd_op.reshape" [id:37] (%2, %3) {stop_gradient:[false]} : (builtin.tensor<3x4xf32>, builtin.tensor<2xi64>) -> builtin.tensor<2x6xf32>
    () = "builtin.shadow_output" [id:38] (%1) {output_name:"middle_0"} : (builtin.tensor<1xf32>) -> 
    () = "builtin.shadow_output" [id:39] (%2) {output_name:"middle_1"} : (builtin.tensor<3x4xf32>) -> 
    () = "builtin.shadow_output" [id:40] (%4) {output_name:"output_0"} : (builtin.tensor<2x6xf32>) -> 
}
BackwardProgram is:
{
    ^kw:%kwarg_output_grad_0, %kwarg_middle_0, %kwarg_middle_1
    (%0) = "pd_op.reshape_grad" [id:41] (%kwarg_middle_1, %kwarg_output_grad_0) {stop_gradient:[false]} : (builtin.tensor<3x4xf32>, builtin.tensor<2x6xf32>) -> builtin.tensor<3x4xf32>
    (%1) = "pd_op.scale" [id:42] (%0, %kwarg_middle_0) {bias:(Float)0,bias_after_scale:true,stop_gradient:[false]} : (builtin.tensor<3x4xf32>, builtin.tensor<1xf32>) -> builtin.tensor<3x4xf32>
    () = "builtin.shadow_output" [id:43] (%1) {output_name:"input_grad_0"} : (builtin.tensor<3x4xf32>) -> 
}

PIR 下,动转静 ReshapeOP 在存在反向的时候,输入会被反向用到(ShadowOutput),导致 ReshapeOp 不能 inplace,但这个输入实际是 no_need_buffer 的,因此在 Inplace Pass 中传入 no_need_buffer 信息,以确保其能成功 inplace

PCard-66972

@paddle-bot
Copy link

paddle-bot bot commented Nov 15, 2024

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

@SigureMo SigureMo requested a review from Copilot November 15, 2024 19:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

Files not reviewed (5)
  • paddle/fluid/eager/to_static/run_program_op_node.h: Language not supported
  • paddle/fluid/framework/executor_cache.cc: Language not supported
  • paddle/fluid/framework/executor_cache.h: Language not supported
  • paddle/fluid/pir/transforms/general/inplace_pass.cc: Language not supported
  • paddle/fluid/pir/transforms/general/inplace_pass.h: Language not supported

Copy link
Contributor

@zhangbo9674 zhangbo9674 left a comment

Choose a reason for hiding this comment

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

LGTM

@SigureMo SigureMo merged commit 3b27bf0 into PaddlePaddle:develop Nov 19, 2024
27 of 28 checks passed
@SigureMo SigureMo deleted the pir/fix-reshape-op-cannot-inplace-in-dy2st branch November 19, 2024 07:17
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.

2 participants