PyTorch/Caffe2 tensor interop in Python (#17190)
authorDmytro Dzhulgakov <dzhulgakov@fb.com>
Mon, 4 Mar 2019 19:30:43 +0000 (11:30 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 4 Mar 2019 19:34:01 +0000 (11:34 -0800)
commitdec116e96f4af069c8c6568e8f01202a3cafc412
tree1be8d6478bf1c76a1eef03b30ca050eabead284f
parent244d3309804a0fc6fd4e66940026df79a4b75ed9
PyTorch/Caffe2 tensor interop in Python (#17190)

Summary:
Because of two separate python extensions with different pybind
instances I have to go through void* conversion. Since it's hidden from
user, it's fine.

New APIs added on C2 side:
- workspace.FetchTorch('blob')
- workspace.Workspace.current.blobs['blob'].to_torch()
- workspace.FeedBlob('blob', pytorch_tensor)

Works on CPU an GPU.

The only glitches are with resizing because of variable/tensor split.
But data sharing works properly.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17190

Reviewed By: ezyang

Differential Revision: D14163882

Pulled By: dzhulgakov

fbshipit-source-id: d18e5b8fcae026f393c842a1149e972515732de2
aten/src/ATen/core/Tensor.cpp
c10/test/util/intrusive_ptr_test.cpp
c10/util/intrusive_ptr.h
caffe2/python/pybind_state.cc
caffe2/python/workspace.py
caffe2/python/workspace_test.py
torch/csrc/autograd/python_variable.cpp