Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

【Hackathon 5th No.112】add the config of identitiy_loss -part #60178

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 0 additions & 107 deletions paddle/fluid/operators/identity_loss_op.cc

This file was deleted.

34 changes: 0 additions & 34 deletions paddle/fluid/operators/ops_signature/identity_loss_sig.cc

This file was deleted.

11 changes: 11 additions & 0 deletions paddle/phi/api/yaml/backward.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,17 @@
kernel :
func : i1e_grad

- backward_op : identity_loss_grad
forward : identity_loss (Tensor x, int reduction) -> Tensor(out)
args : (Tensor x, Tensor out_grad, int reduction = 1)
output : Tensor(x_grad)
infer_meta :
func : IdentityLossGradInferMeta
kernel :
func : identity_loss_grad
data_type : out_grad
inplace : (out_grad -> x_grad)

- backward_op : imag_grad
forward : imag (Tensor x) -> Tensor(out)
args : (Tensor out_grad)
Expand Down
6 changes: 6 additions & 0 deletions paddle/phi/api/yaml/op_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3439,6 +3439,12 @@
outputs :
out : Out

- op: identity_loss
inputs :
x: X
outputs :
out : Out

- op: lod_array_length
inputs :
{x: X}
Expand Down
12 changes: 12 additions & 0 deletions paddle/phi/api/yaml/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,18 @@
func : i1e
backward : i1e_grad

- op : identity_loss
args : (Tensor x, int reduction = 1)
output : Tensor(out)
infer_meta :
func : IdentityLossInferMeta
kernel :
func : identity_loss
data_type : x
backend : x
inplace: (x -> out)
backward : identity_loss_grad

- op : imag
args : (Tensor x)
output : Tensor (out)
Expand Down
9 changes: 9 additions & 0 deletions paddle/phi/infermeta/binary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3354,6 +3354,15 @@ void WeightDequantizeInferMeta(const MetaTensor& x,
out->set_dtype(out_dtype);
}

void IdentityLossGradInferMeta(const MetaTensor& x,
const MetaTensor& out_grad,
const int reduction,
MetaTensor* x_grad) {
x_grad->set_dims(x.dims());
x_grad->share_lod(x);
x_grad->set_dtype(out_grad.dtype());
}

} // namespace phi

PD_REGISTER_INFER_META_FN(add_raw, phi::ElementwiseRawInferMeta);
5 changes: 5 additions & 0 deletions paddle/phi/infermeta/binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,4 +526,9 @@ void WeightDequantizeInferMeta(const MetaTensor& x,
DataType out_dtype,
MetaTensor* out);

void IdentityLossGradInferMeta(const MetaTensor& x,
const MetaTensor& out_grad,
const int reduction,
MetaTensor* x_grad);

} // namespace phi
4 changes: 2 additions & 2 deletions python/paddle/incubate/nn/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from paddle import _legacy_C_ops
from paddle import _C_ops
from paddle.base.data_feeder import check_variable_and_dtype
from paddle.base.layer_helper import LayerHelper
from paddle.framework import in_dynamic_mode
Expand Down Expand Up @@ -60,7 +60,7 @@ def identity_loss(x, reduction="none"):
raise Exception("Unsupported reduction type.")

if in_dynamic_mode():
return _legacy_C_ops.identity_loss(x, "reduction", reduction)
return _C_ops.identity_loss(x, reduction)

check_variable_and_dtype(x, 'x', ['float32', 'float64'], "identity_loss")
attrs = {'reduction': reduction}
Expand Down