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

feat(paddle): Add backward method to Paddle Frontend #23549

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
6 changes: 6 additions & 0 deletions ivy/functional/frontends/paddle/tensor/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,3 +758,9 @@ def remainder(self, y, name=None):

def is_floating_point(self):
return paddle_frontend.is_floating_point(self._ivy_array)

@with_supported_dtypes(
{"2.5.1 and below": ("float32", "float64", "int32", "int64")}, "paddle"
)
def backward(self, x):
return paddle_frontend.Tensor.backward(self.x)
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,42 @@ def test_paddle__reshape(
)


# backward


@handle_frontend_method(
class_tree=CLASS_TREE,
init_tree="paddle.to_tensor",
method_name="backward",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
),
)
def test_paddle_backward(
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename the test to test_paddle_tensor_backward to be in line with our naming convention.

dtype_and_x,
frontend_method_data,
init_flags,
method_flags,
frontend,
on_device,
backend_fw,
):
input_dtype, x = dtype_and_x
x = Tensor(x)
helpers.test_frontend_method(
Copy link
Contributor

Choose a reason for hiding this comment

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

x = Tensor(x) should not be needed here. I believe this is done inside test_frontend_method later on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AnnaTz
I passed the five tests only after I add x = Tensor(x), so I think it’s necessary

init_input_dtypes=input_dtype,
init_all_as_kwargs_np={"x": x},
method_all_as_kwargs_np={"x": x},
method_input_dtypes=input_dtype,
backend_to_test=backend_fw,
frontend_method_data=frontend_method_data,
init_flags=init_flags,
method_flags=method_flags,
frontend=frontend,
on_device=on_device,
)


# atan
@handle_frontend_method(
class_tree=CLASS_TREE,
Expand Down
Loading