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

Add smooth_l1_loss to Paddle frontend and test #18470

Closed
wants to merge 4 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
211 changes: 0 additions & 211 deletions ivy/functional/frontends/paddle/nn/functional/activation.py

This file was deleted.

23 changes: 23 additions & 0 deletions ivy/functional/frontends/paddle/nn/functional/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,26 @@ def cosine_embedding_loss(
out = ivy.sum(out)

return out


@with_supported_dtypes({"2.5.0 and below": ("float32", "float64")}, "paddle")
@to_ivy_arrays_and_back
def smooth_l1_loss(
input,
label,
reduction='mean',
delta=1.0,
name=None,
):
sum_diff = ivy.abs(input - label).astype(label.dtype)
condition = sum_diff <= delta
out = ivy.where(condition, 0.5 * ivy.pow(ivy.abs(input - label), 2).astype(label.dtype),
(delta * ivy.abs(ivy.abs(input - label))).astype(label.dtype)
- (0.5 * ivy.pow(delta, 2)).astype(label.dtype))
if reduction == "none":
pass
elif reduction == "mean":
out = ivy.mean(out)
elif reduction == "sum":
out = ivy.sum(out)
return out.astype(label.dtype)
Loading
Loading