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 set value grad #59034

Merged
merged 7 commits into from
Dec 25, 2023
Merged

Conversation

zoooo0820
Copy link
Contributor

@zoooo0820 zoooo0820 commented Nov 15, 2023

PR types

Bug fixes

PR changes

OPs

Description

Pcard-66985

在此前,为了适配分布式动半模式,set_value算子及其反向算子迁移到phi下。在此之前,set_value算子可同时处理value 为scalar或tensor两种场景,由input ValueTensor是否存在来决定。相应的,其反向set_value_grad也是如此。

由于phi的要求,需要显式区分set_value (对应value 为scalar) 和 set_value_with_tensor (对应value 为tensor)两个算子。因此,反向也需要对应区分。在phi之前的算子历史定义fluid/operator中,将前者的反向行为错误地设置为assign,这使得在迁移phi时 #58893 的行为参考有误。导致目前value 为scalar时,赋值的反向结果与预期不符,需要修复。
本PR 中新增kernel set_value_with_scalar_grad,用于该场景的计算,替代此前错误的assign行为,其底层仍然复用SetValueGradImpl

Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

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

这个修改还需要麻烦永康Review一下。这么改了以后paddle/fluid/ir_adaptor/translator/op_translator.cc里的SetValueGradOpTranscriber需要做调整吗?

Comment on lines 356 to 358
switch (rank) {
case 1:
SetValueGradImpl<T, Context, 1>(dev_ctx,
Copy link
Contributor

Choose a reason for hiding this comment

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

这里是不是直接调SetValueGradKernel就可以了,value_grad传入nullptr。

Comment on lines 154 to 155
op->SetType("set_value_grad");
op->SetInput(framework::GradVarName("Out"), this->OutputGrad("Out"));
Copy link
Contributor

Choose a reason for hiding this comment

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

这里应该讨论,如果有ValueTensor调用set_value_grad,没有ValueTensor调用set_value_with_scalar_grad

op->SetType("assign");
op->SetInput("X", this->OutputGrad("Out"));
op->SetOutput("Out", this->InputGrad("Input"));
op->SetType("set_value_with_scalar_grad");
Copy link
Contributor

Choose a reason for hiding this comment

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

这行看起来依然没有被覆盖到,是不是需要注册一个新Op set_value_with_scalar_grad?

Copy link

paddle-ci-bot bot commented Nov 26, 2023

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

Copy link
Contributor

@kangguangli kangguangli left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@jeff41404 jeff41404 left a comment

Choose a reason for hiding this comment

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

LGTM

@jeff41404 jeff41404 merged commit 85e3693 into PaddlePaddle:develop Dec 25, 2023
29 checks passed
@zoooo0820 zoooo0820 deleted the fix_set_value_grad branch December 25, 2023 07:11
Wanglongzhi2001 pushed a commit to Wanglongzhi2001/Paddle that referenced this pull request Jan 7, 2024
* first fix the UT

* fix set value grad

* polish code

* add static mode backward test

* always has input valuetensor

* add dygraph test
zoooo0820 added a commit to zoooo0820/Paddle that referenced this pull request Jan 18, 2024
* first fix the UT

* fix set value grad

* polish code

* add static mode backward test

* always has input valuetensor

* add dygraph test
XiaoguangHu01 pushed a commit that referenced this pull request Jan 19, 2024
* Fix set value grad (#59034)

* first fix the UT

* fix set value grad

* polish code

* add static mode backward test

* always has input valuetensor

* add dygraph test

* Fix shape error in combined-indexing setitem (#60447)

* add ut

* fix shape error in combine-indexing

* fix ut

* Set value with scalar (#60452)

* set_value with scalar

* fix ut

* remove test_pir

* remove one test since 2.6 not support uint8-add
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.

None yet

4 participants