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

Adding new presets for pytorch c++ frontend? #623

Open
wumo opened this Issue Oct 13, 2018 · 9 comments

Comments

Projects
None yet
5 participants
@wumo
Copy link
Contributor

wumo commented Oct 13, 2018

Recently pytorch release preview version 1.0, which features the experimental C++ frontend. The pytorch C++ frontend is easier and more complete than tensorflow.

The C++ frontend is a pure C++ interface to the PyTorch backend that follows the API and architecture of the established Python frontend. It is intended to enable research in high performance, low latency and bare metal C++ applications. It provides equivalents to torch.nn, torch.optim, torch.data and other components of the Python frontend. Here is a minimal side-by-side comparison of the two language frontends:

Python:

import torch

model = torch.nn.Linear(5, 1)
optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
prediction = model.forward(torch.randn(3, 5))
loss = torch.nn.functional.mse_loss(prediction, torch.ones(3, 1))
loss.backward()
optimizer.step()

C++:

#include <torch/torch.h>

torch::nn::Linear model(5, 1);
torch::optim::SGD optimizer(model->parameters(), /*lr=*/0.1);
torch::Tensor prediction = model->forward(torch::randn({3, 5}));
auto loss = torch::mse_loss(prediction, torch::ones({3, 1}));
loss.backward();
optimizer.step();

Will you consider adding the pytorch c++ frontend presets?

@saudet

This comment has been minimized.

Copy link
Member

saudet commented Oct 13, 2018

@saudet

This comment has been minimized.

Copy link
Member

saudet commented Oct 16, 2018

BTW, @Neiko2002, is this something you would be also interested in having?

@saudet

This comment has been minimized.

Copy link
Member

saudet commented Oct 16, 2018

/cc @cypof

@Neiko2002

This comment has been minimized.

Copy link
Member

Neiko2002 commented Oct 16, 2018

@saudet To be honest I have never tried pytorch yet. Their python API looks similar to Java. A javacpp version of it might be easier to use than the official C++ API. Right now we deploy javacpp-tensorflow in production systems but train networks in python. Pytorch on the other hand has a simple C++ API to train and run a network.

Looking at the C++ API it does not feel it offers more than the Tensorflow API.

@saudet

This comment has been minimized.

Copy link
Member

saudet commented Oct 21, 2018

I think there is great potential in being able to (re)train on a platform that's more efficient than CPython, so I do hope this panes out. In any case, TensorFlow has obviously given up on that, let's see where PyTorch is willing to go! They used to promote Lua for this exact reason, although not Java for whatever political reason, so anyway IMO there is a chance they will redo something similar for C++11:
http://bytedeco.org/news/2015/03/14/java-meets-caffe/

@karllessard If you have any opinions about this, I would love to hear them!

@karllessard

This comment has been minimized.

Copy link

karllessard commented Oct 22, 2018

@karllessard If you have any opinions about this, I would love to hear them!

For the moment no I don't but this is very interesting, thanks for the tip @saudet !

@saudet

This comment has been minimized.

Copy link
Member

saudet commented Dec 27, 2018

I've been looking at the the C++ API over the past couple of days, and it looks like a mess. It mixes types from Caffe2, ATen, and C10 with no clear understanding of how they fit together: pytorch/pytorch#14850

Moreover, it's currently unable to train for MNIST using simple examples on either CPU or GPU:
https://discuss.pytorch.org/t/in-c-api-1-0-0-mnist-results-are-unstable/32823
pytorch/pytorch#15522
I've personally confirmed those results by building from source both PyTorch 1.0.0 and current master, both with and without CUDA/cuDNN.

We should probably wait until all this gets cleared up and fixed before starting to map anything to Java...

@iwroldtan

This comment has been minimized.

Copy link

iwroldtan commented Dec 29, 2018

Recently pytorch release preview version 1.0, which features the experimental C++ frontend. The pytorch C++ frontend is easier and more complete than tensorflow.

The C++ frontend is a pure C++ interface to the PyTorch backend that follows the API and architecture of the established Python frontend. It is intended to enable research in high performance, low latency and bare metal C++ applications. It provides equivalents to torch.nn, torch.optim, torch.data and other components of the Python frontend. Here is a minimal side-by-side comparison of the two language frontends:

Python:

import torch

model = torch.nn.Linear(5, 1)
optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
prediction = model.forward(torch.randn(3, 5))
loss = torch.nn.functional.mse_loss(prediction, torch.ones(3, 1))
loss.backward()
optimizer.step()

C++:

#include <torch/torch.h>

torch::nn::Linear model(5, 1);
torch::optim::SGD optimizer(model->parameters(), /*lr=*/0.1);
torch::Tensor prediction = model->forward(torch::randn({3, 5}));
auto loss = torch::mse_loss(prediction, torch::ones({3, 1}));
loss.backward();
optimizer.step();

Will you consider adding the pytorch c++ frontend presets?

Could you give me a hand? I can not find the file, torch/torch.h.

@saudet

This comment has been minimized.

Copy link
Member

saudet commented Jan 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment