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: add cpu function #21255

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8178af7
cpu pytorch frontend
Prajyot70 Aug 2, 2023
6257d55
Update cpu pytorch frontend
Prajyot70 Aug 9, 2023
628b7da
Merge branch 'unifyai:master' into patch-2
Prajyot70 Aug 9, 2023
d8ce0bc
Create test_tensor
Prajyot70 Aug 10, 2023
265956b
Rename cpu pytorch frontend to functional/frontend/torch/torch.py
Prajyot70 Aug 10, 2023
577e193
Delete torch.py
Prajyot70 Aug 13, 2023
b4b7165
Create cpu
Prajyot70 Aug 18, 2023
1a298a4
Update tensor.py
Prajyot70 Sep 1, 2023
7b8ae32
Update test_tensor.py
Prajyot70 Sep 1, 2023
4d72bc0
Update torch.py
Prajyot70 Sep 2, 2023
db0c288
Delete ivy_tests/test_ivy/test_frontends/test_torch/test_tensor
Prajyot70 Sep 2, 2023
2f2ad38
Delete ivy/functional/frontends/torch/torch.py
Prajyot70 Sep 2, 2023
44688cc
Update tensor.py
Prajyot70 Sep 9, 2023
b86109b
Update test_tensor.py
Prajyot70 Sep 9, 2023
32fc93f
lint
NripeshN Dec 6, 2023
44812e5
🤖 Lint code
ivy-branch Dec 6, 2023
f568a40
Merge branch 'main' into patch-2
Prajyot70 Dec 21, 2023
d8e747e
Update tensor.py
Prajyot70 Dec 21, 2023
1dcb9ed
Update test_tensor.py
Prajyot70 Dec 21, 2023
2747f29
🤖 Lint code
ivy-branch Dec 21, 2023
61d3859
Update test_tensor.py
Prajyot70 Dec 22, 2023
bc18489
🤖 Lint code
ivy-branch Dec 22, 2023
1e765d8
Update test_tensor.py
Prajyot70 Dec 22, 2023
602cc21
🤖 Lint code
ivy-branch Dec 22, 2023
6193216
Update test_tensor.py
Prajyot70 Dec 23, 2023
311532b
Update test_tensor.py
Prajyot70 Dec 27, 2023
bfa1299
🤖 Lint code
ivy-branch Dec 27, 2023
aecd4f9
Update test_tensor.py
Prajyot70 Dec 27, 2023
4befcf7
🤖 Lint code
ivy-branch Dec 27, 2023
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
19 changes: 19 additions & 0 deletions functional/frontend/torch/torch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# in ivy/functional/frontends/torch/torch.py
@to_ivy_arrays_and_back

import torch
import ivy.functional.frontends.torch as torch_frontend

def to_cpu(self):
if self.is_cuda:
return torch_frontend.self.to_cpu()
else:
return self

torch.Tensor.to_cpu = to_cpu

x = torch.randn(2, 3).cuda()

y = x.to_cpu()

print(y.device)
45 changes: 45 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_torch/test_tensor
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from ivy_test.helpers import *
from ivy_test.helpers import helpers
from ivy_test.helpers.helpers import handle_frontend_method

@handle_frontend_method(
class_tree=CLASS_TREE,
init_tree="torch.tensor",
method_name="to_cpu",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
num_arrays=1,
min_value=-1e04,
max_value=1e04,
allow_inf=False,
),
)


def test_torch_instance_to_cpu(
dtype_abd_x,
frontend,
backend_fw,
frontend_method_data,
init_flags,
method_flags,
):
input_dtype, x = dtype_and_x
helper.test_frontend_method(
init_input_dtypes=input_dtype,
init_all_as_kwargs_np={
"data"= x[0],
},
method_input_dtypes=input_dtype,
method_all_as_kwarg_np={},
frontend_method_data=frontend_method_data,
init_flags=init_flags,
method_flags=method_flags,
frontend=frontend,
backed_to_test=backend_fw,
)



# run the test
test_torch_instance_to_cpu