Skip to content
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
2 changes: 1 addition & 1 deletion python/pyarrow/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def register_torch_serialization_handlers(serialization_context):
import torch

def _serialize_torch_tensor(obj):
return obj.numpy()
return obj.detach().numpy()

def _deserialize_torch_tensor(data):
return torch.from_numpy(data)
Expand Down
4 changes: 4 additions & 0 deletions python/pyarrow/tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ def test_torch_serialization(large_buffer):
serialization_roundtrip(obj, large_buffer,
context=serialization_context)

tensor_requiring_grad = torch.randn(10, 10, requires_grad=True)
serialization_roundtrip(tensor_requiring_grad, large_buffer,
context=serialization_context)


def test_numpy_immutable(large_buffer):
obj = np.zeros([10])
Expand Down