Skip to content

Commit

Permalink
Fix grad node interface name (#61958)
Browse files Browse the repository at this point in the history
* Fix

* ci

* ci
  • Loading branch information
co63oc authored Feb 23, 2024
1 parent 9d10d5c commit c4dbcc8
Show file tree
Hide file tree
Showing 17 changed files with 294 additions and 293 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ paddle::Tensor add_n_ad_func(const std::vector<paddle::Tensor>& x) {
// SetAttributes if needed

// Set TensorWrappers for Forward Inputs if needed
grad_node->SetTensorWrapperx(x);
grad_node->SetTensorWrapper_x(x);
// SetGradOutMeta & SetEdges
grad_node->SetGradOutMeta(x, 0);
// SetOutRank & SetHistory & SetGradInMeta & RetainGrad
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ paddle::Tensor conv2d_ad_func(const paddle::Tensor& input,
}

// SetAttributes if needed
grad_node->SetAttributestrides(strides);
grad_node->SetAttributepaddings(paddings);
grad_node->SetAttributepadding_algorithm(padding_algorithm);
grad_node->SetAttributegroups(groups);
grad_node->SetAttributedilations(dilations);
grad_node->SetAttributedata_format(data_format);
grad_node->SetAttribute_strides(strides);
grad_node->SetAttribute_paddings(paddings);
grad_node->SetAttribute_padding_algorithm(padding_algorithm);
grad_node->SetAttribute_groups(groups);
grad_node->SetAttribute_dilations(dilations);
grad_node->SetAttribute_data_format(data_format);
// Set TensorWrappers for Forward Inputs if needed
grad_node->SetTensorWrapperinput(input);
grad_node->SetTensorWrapperfilter(filter);
grad_node->SetTensorWrapper_input(input);
grad_node->SetTensorWrapper_filter(filter);
// SetGradOutMeta & SetEdges
grad_node->SetGradOutMeta(input, 0);
grad_node->SetGradOutMeta(filter, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,25 @@ paddle::Tensor multiply_ad_func(const paddle::Tensor& x,
grad_node->SetForwardTrace(egr::Controller::Instance().GetPythonStack());
}
// SetAttributes if needed
grad_node->SetAttributeaxis(-1);
grad_node->SetAttribute_axis(-1);
if (paddle::platform::is_gpu_place(x.place())) {
if (x_autograd_meta != nullptr && x_autograd_meta->StopGradient() &&
y_autograd_meta != nullptr && !y_autograd_meta->StopGradient()) {
grad_node->SetTensorWrapperx(x);
grad_node->SetTensorWrapperNoNeedBuffery(y);
grad_node->SetTensorWrapper_x(x);
grad_node->SetTensorWrapperNoNeedBuffer_y(y);
} else if (x_autograd_meta != nullptr &&
!x_autograd_meta->StopGradient() &&
y_autograd_meta != nullptr &&
y_autograd_meta->StopGradient()) {
grad_node->SetTensorWrapperNoNeedBufferx(x);
grad_node->SetTensorWrappery(y);
grad_node->SetTensorWrapperNoNeedBuffer_x(x);
grad_node->SetTensorWrapper_y(y);
} else {
grad_node->SetTensorWrapperx(x);
grad_node->SetTensorWrappery(y);
grad_node->SetTensorWrapper_x(x);
grad_node->SetTensorWrapper_y(y);
}
} else {
grad_node->SetTensorWrapperx(x);
grad_node->SetTensorWrappery(y);
grad_node->SetTensorWrapper_x(x);
grad_node->SetTensorWrapper_y(y);
}
// SetGradOutMeta & SetEdges
grad_node->SetGradOutMeta(x, 0);
Expand Down Expand Up @@ -300,11 +300,11 @@ paddle::Tensor& multiply__ad_func(paddle::Tensor& x, // NOLINT
grad_node->SetForwardTrace(egr::Controller::Instance().GetPythonStack());
}
// SetAttributes if needed
grad_node->SetAttributeaxis(-1);
grad_node->SetAttribute_axis(-1);
// Set TensorWrappers for Forward Inputs if needed
auto x_clone = paddle::experimental::assign(x);
grad_node->SetTensorWrapperx(x_clone);
grad_node->SetTensorWrappery(y);
grad_node->SetTensorWrapper_x(x_clone);
grad_node->SetTensorWrapper_y(y);
}

// Forward API Call
Expand Down Expand Up @@ -505,8 +505,8 @@ paddle::Tensor multiply_ad_func(const paddle::Tensor& x,
// SetAttributes if needed

// Set TensorWrappers for Forward Inputs if needed
grad_node->SetTensorWrapperx(x);
grad_node->SetTensorWrappery(y);
grad_node->SetTensorWrapper_x(x);
grad_node->SetTensorWrapper_y(y);
// SetGradOutMeta & SetEdges
grad_node->SetGradOutMeta(x, 0);
grad_node->SetGradOutMeta(y, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ paddle::Tensor reshard_ad_function(
std::shared_ptr<ReshardGradNode>(new ReshardGradNode(1, 1)); // NOLINT

// Set TensorWrappers for Forward Inputs if needed
grad_node->SetTensorWrapperNoNeedBufferInput(input);
grad_node->SetTensorWrapperNoNeedBuffer_Input(input);
}

// Forward API Call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,16 @@ sync_batch_norm__ad_func(const paddle::Tensor& x,

egr::Controller::Instance().PushBackForceSequentialNodes(grad_node.get());
// SetAttributes if needed
grad_node->SetAttributemomentum(momentum);
grad_node->SetAttributeepsilon(epsilon);
grad_node->SetAttributedata_layout(data_layout);
grad_node->SetAttributeis_test(is_test);
grad_node->SetAttributeuse_global_stats(use_global_stats);
grad_node->SetAttributetrainable_statistics(trainable_statistics);
grad_node->SetAttribute_momentum(momentum);
grad_node->SetAttribute_epsilon(epsilon);
grad_node->SetAttribute_data_layout(data_layout);
grad_node->SetAttribute_is_test(is_test);
grad_node->SetAttribute_use_global_stats(use_global_stats);
grad_node->SetAttribute_trainable_statistics(trainable_statistics);
// Set TensorWrappers for Forward Inputs if needed
grad_node->SetTensorWrapperx(x);
grad_node->SetTensorWrapperscale(scale);
grad_node->SetTensorWrapperbias(bias);
grad_node->SetTensorWrapper_x(x);
grad_node->SetTensorWrapper_scale(scale);
grad_node->SetTensorWrapper_bias(bias);
// SetGradOutMeta & SetEdges
grad_node->SetGradOutMeta(x, 0);
grad_node->SetGradOutMeta(scale, 3);
Expand Down Expand Up @@ -293,9 +293,9 @@ sync_batch_norm__ad_func(const paddle::Tensor& x,
grad_node->SetGradInMeta(saved_variance, 4);
grad_node->SetGradInMeta(reserve_space, 5);
// Set TensorWrappers for Forward Outputs if needed
grad_node->SetTensorWrappersaved_mean(saved_mean);
grad_node->SetTensorWrappersaved_variance(saved_variance);
grad_node->SetTensorWrapperreserve_space(reserve_space);
grad_node->SetTensorWrapper_saved_mean(saved_mean);
grad_node->SetTensorWrapper_saved_variance(saved_variance);
grad_node->SetTensorWrapper_reserve_space(reserve_space);
}

VLOG(4) << "Finish AD API: sync_batch_norm_";
Expand Down Expand Up @@ -571,16 +571,16 @@ sync_batch_norm__ad_func(const paddle::Tensor& x,
new SyncBatchNormGradNode(6, 5));
egr::Controller::Instance().PushBackForceSequentialNodes(grad_node.get());
// SetAttributes if needed
grad_node->SetAttributemomentum(momentum);
grad_node->SetAttributeepsilon(epsilon);
grad_node->SetAttributedata_layout(data_layout);
grad_node->SetAttributeis_test(is_test);
grad_node->SetAttributeuse_global_stats(use_global_stats);
grad_node->SetAttributetrainable_statistics(trainable_statistics);
grad_node->SetAttribute_momentum(momentum);
grad_node->SetAttribute_epsilon(epsilon);
grad_node->SetAttribute_data_layout(data_layout);
grad_node->SetAttribute_is_test(is_test);
grad_node->SetAttribute_use_global_stats(use_global_stats);
grad_node->SetAttribute_trainable_statistics(trainable_statistics);
// Set TensorWrappers for Forward Inputs if needed
grad_node->SetTensorWrapperx(x);
grad_node->SetTensorWrapperscale(scale);
grad_node->SetTensorWrapperbias(bias);
grad_node->SetTensorWrapper_x(x);
grad_node->SetTensorWrapper_scale(scale);
grad_node->SetTensorWrapper_bias(bias);
// SetGradOutMeta & SetEdges
grad_node->SetGradOutMeta(x, 0);
grad_node->SetGradOutMeta(scale, 3);
Expand Down Expand Up @@ -629,9 +629,9 @@ sync_batch_norm__ad_func(const paddle::Tensor& x,
grad_node->SetGradInMeta(saved_variance, 4);
grad_node->SetGradInMeta(reserve_space, 5);
// Set TensorWrappers for Forward Outputs if needed
grad_node->SetTensorWrappersaved_mean(saved_mean);
grad_node->SetTensorWrappersaved_variance(saved_variance);
grad_node->SetTensorWrapperreserve_space(reserve_space);
grad_node->SetTensorWrapper_saved_mean(saved_mean);
grad_node->SetTensorWrapper_saved_variance(saved_variance);
grad_node->SetTensorWrapper_reserve_space(reserve_space);
}

VLOG(4) << "Finish AD API: sync_batch_norm_";
Expand Down
18 changes: 9 additions & 9 deletions paddle/fluid/eager/api/manual/eager_manual/nodes/conv2d_nodes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ Conv2dGradNodeFinal::operator()(
auto grad_node = std::shared_ptr<Conv2dDoubleGradNodeFinal>( // NOLINT
new Conv2dDoubleGradNodeFinal(2, 3));
// SetAttributes if needed
grad_node->SetAttributestrides(strides);
grad_node->SetAttributepaddings(paddings);
grad_node->SetAttributepadding_algorithm(padding_algorithm);
grad_node->SetAttributegroups(groups);
grad_node->SetAttributedilations(dilations);
grad_node->SetAttributedata_format(data_format);
grad_node->SetAttribute_strides(strides);
grad_node->SetAttribute_paddings(paddings);
grad_node->SetAttribute_padding_algorithm(padding_algorithm);
grad_node->SetAttribute_groups(groups);
grad_node->SetAttribute_dilations(dilations);
grad_node->SetAttribute_data_format(data_format);
// Set TensorWrappers for Forward Inputs if needed
grad_node->SetTensorWrapperinput(input);
grad_node->SetTensorWrapperfilter(filter);
grad_node->SetTensorWrappergrad_out(grad_out);
grad_node->SetTensorWrapper_input(input);
grad_node->SetTensorWrapper_filter(filter);
grad_node->SetTensorWrapper_grad_out(grad_out);
// SetGradOutMeta & SetEdges
if (grad_filter_autograd_meta) {
grad_node->SetGradOutMeta(input, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ MultiplyGradNode::operator()(
auto grad_node = std::shared_ptr<MultiplyDoubleGradNode>( // NOLINT
new MultiplyDoubleGradNode(2, 3));
// SetAttributes if needed
grad_node->SetAttributeaxis(axis);
grad_node->SetAttribute_axis(axis);
// Set TensorWrappers for Forward Inputs if needed
grad_node->SetTensorWrapperx(x);
grad_node->SetTensorWrappery(y);
grad_node->SetTensorWrappergrad_out(grad_out);
grad_node->SetTensorWrapper_x(x);
grad_node->SetTensorWrapper_y(y);
grad_node->SetTensorWrapper_grad_out(grad_out);
// SetGradOutMeta & SetEdges
grad_node->SetGradOutMeta(x, 0);
grad_node->SetGradOutMeta(y, 1);
Expand Down
Loading

0 comments on commit c4dbcc8

Please sign in to comment.