Skip to content

Commit 1cdf6a3

Browse files
committed
Merge branch 'paddle_grad_bug_fix_v2' of https://github.com/jim19930609/Paddle into add_double_grad_yamls_v1
2 parents a4644c1 + ab17c93 commit 1cdf6a3

File tree

7 files changed

+16
-10
lines changed

7 files changed

+16
-10
lines changed

paddle/fluid/eager/auto_code_generator/eager_generator.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,7 +2484,8 @@ static std::string GenerateGradNodeHeaderContents(
24842484
" std::string name() override { return \" GradNode%s \"; } \n "
24852485
"\n"
24862486
"std::shared_ptr<GradNodeBase> Copy() const override {{\n "
2487-
" auto copied_node = std::make_shared<GradNode%s>(*this);\n "
2487+
" auto copied_node = std::shared_ptr<GradNode%s>(new "
2488+
"GradNode%s(*this));\n "
24882489
" return copied_node;\n "
24892490
"}}\n "
24902491
"\n"
@@ -2601,7 +2602,7 @@ static std::string GenerateGradNodeHeaderContents(
26012602

26022603
std::string grad_node_str = paddle::string::Sprintf(
26032604
GRAD_NODE_TEMPLATE, op_type, op_type, op_type, op_type, op_type, op_type,
2604-
op_type, clear_tensor_wrappers_str, op_type, op_type,
2605+
op_type, clear_tensor_wrappers_str, op_type, op_type, op_type,
26052606
set_tensor_wrappers_str, set_attr_map_str, tensor_wrapper_members_str,
26062607
attr_members_str);
26072608

paddle/fluid/eager/auto_code_generator/final_state_generator/eager_gen.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ class {} : public egr::GradNodeBase {{
128128
}}
129129
130130
std::shared_ptr<GradNodeBase> Copy() const override {{
131-
auto copied_node = std::make_shared<{}>(*this);
131+
auto copied_node = std::shared_ptr<{}>(new {}(*this));
132+
132133
return copied_node;
133134
}}
134135
@@ -1241,8 +1242,9 @@ def GenerateNodeDeclaration(self):
12411242
self.node_declaration_str = NODE_DECLARATION_TEMPLATE.format(
12421243
grad_node_name, grad_node_name, grad_node_name, grad_node_name,
12431244
grad_node_name, clear_tensor_wrapper_str, grad_node_name,
1244-
set_tensor_wrapper_methods_str, set_attribute_methods_str,
1245-
tensor_wrapper_members_str, attribute_members_str)
1245+
grad_node_name, set_tensor_wrapper_methods_str,
1246+
set_attribute_methods_str, tensor_wrapper_members_str,
1247+
attribute_members_str)
12461248

12471249
logging.info(f"Generated Node Declaration: {self.node_declaration_str}")
12481250

paddle/fluid/eager/custom_operator/custom_operator_node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class RunCustomOpNode : public GradNodeBase {
6969
void SetAttrs(const std::vector<paddle::any>& attr) { attrs_ = attr; }
7070

7171
std::shared_ptr<GradNodeBase> Copy() const override {
72-
auto copied_node = std::make_shared<RunCustomOpNode>(*this);
72+
auto copied_node =
73+
std::shared_ptr<RunCustomOpNode>(new RunCustomOpNode(*this));
7374
return copied_node;
7475
}
7576

paddle/fluid/eager/pylayer/py_layer_node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class GradNodePyLayer : public GradNodeBase {
6868
}
6969

7070
std::shared_ptr<GradNodeBase> Copy() const override {
71-
auto copied_node = std::make_shared<GradNodePyLayer>(*this);
71+
auto copied_node =
72+
std::shared_ptr<GradNodePyLayer>(new GradNodePyLayer(*this));
7273
return copied_node;
7374
}
7475

paddle/fluid/eager/tests/data_structure_tests/grad_node_test.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class GradTestNode : public egr::GradNodeBase {
5353

5454
std::shared_ptr<GradNodeBase> Copy() const override {
5555
{
56-
auto copied_node = std::make_shared<GradTestNode>(*this);
56+
auto copied_node = std::shared_ptr<GradTestNode>(new GradTestNode(*this));
5757
return copied_node;
5858
}
5959
}

paddle/fluid/eager/to_static/run_program_op_node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ class GradNodeRunProgram : public egr::GradNodeBase {
465465
}
466466

467467
std::shared_ptr<GradNodeBase> Copy() const override {
468-
auto copied_node = std::make_shared<GradNodeRunProgram>(*this);
468+
auto copied_node =
469+
std::shared_ptr<GradNodeRunProgram>(new GradNodeRunProgram(*this));
469470
return copied_node;
470471
}
471472

python/paddle/fluid/tests/unittests/test_imperative_double_grad.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ def test_matmul(self):
650650
grad_out = paddle.to_tensor(
651651
np.ones([3, 3]), stop_gradient=False, dtype='float32')
652652

653-
out = _C_ops.final_state_matmul(x, y, False, False)
653+
out = paddle.matmul(x, y, False, False)
654654
new_x_g, new_y_g = paddle.grad(
655655
[out], [x, y], [grad_out], retain_graph=True, create_graph=True)
656656
new_x_g.backward()

0 commit comments

Comments
 (0)