Labo
Labo

Reputation: 2782

What is the relationship between PyTorch and Torch?

There are two PyTorch repositories :

The first clearly requires Torch and lua and is a wrapper, but the second doesn't make any reference to the Torch project except with its name.

How is it related to the Lua Torch?

Upvotes: 58

Views: 65705

Answers (3)

juanmirocks
juanmirocks

Reputation: 6191

2023+ answer

Torch (torch/torch7) is the original implementation, primarily in C with a wrapper in Lua. The project was started in 2013 by IDIAP at EPFL. Later, other companies joined the efforts, including Facebook (now Meta Platforms). Development stopped by 2019.

PyTorch (pytorch/pytorch) is indeed a continuation of Torch, rewriting the core in C++ and with an equally-important interface in Python (which was and remains the focus). The project was started in 2016 by researchers at Facebook (now Meta AI), and was taken over by the PyTorch Foundation (part of the Linux Foundation) in late 2022.


Somewhat confusingly, the Python package for PyTorch on PyPi is just called torch. Fortunately, if you'd try to pip install pytorch (a dummy empty package), you'll get a clear error: You tried to install "pytorch". The package named for PyTorch is "torch".

On conda, rather, the package is called pytorch (under the channel/namespace pytorch).

Regardless of the package manager, in Python code you import torch.


P.S.: as for the other project you mentioned, hughperkins/pytorch, it's obvious by now that it didn't flourish; it ended development in 2016.

Upvotes: 27

blitu12345
blitu12345

Reputation: 3567

Here a short comparison on pytorch and torch.

Torch:

A Tensor library like numpy, unlike numpy it has strong GPU support.
Lua is a wrapper for Torch (Yes! you need to have a good understanding of Lua), and for that you will need LuaRocks package manager.

PyTorch:

No need for the LuaRocks package manager, no need to write code in Lua. And because we are using Python, we can develop Deep Learning models with utmost flexibility. We can also exploit major Python packages likes scipy, numpy, matplotlib and Cython with PyTorch's own autograd.

There is a detailed discussion on this on pytorch forum. Adding to that both PyTorch and Torch use THNN. Torch provides lua wrappers to the THNN library while Pytorch provides Python wrappers for the same.

PyTorch's recurrent nets, weight sharing and memory usage with the flexibility of interfacing with C, and the current speed of Torch.

For more insights, have a look at this discussion session here.

Upvotes: 43

Fabrice Dugas
Fabrice Dugas

Reputation: 519

Just to clarify the confusion between both pytorch repositories:

  • pytorch/pytorch is very similar to (Lua) Torch but in Python. So it's a wrapper over THNN. This was written by Facebook too.
  • hughperkins/pytorch: I have come across this repo when I was developing in Torch before pytorch existed, but I have never used it so I'm not quite sure if it is a wrapper written in Python over (Lua) Torch which is in turn a wrapper over THNN OR a wrapper over THNN and Lua. In both case, this is not the original version of Torch. It was written by Hugh Perkins when there was no Python alternative for Torch.

If you are wondering which one to go for, I would definitely recommend pytorch/pytorch as it communicates directly with THNN, is written by the people who made THNN and is continuously maintained. hughperkins/pytorch does not seem to be maintained anymore.

Upvotes: 15

Related Questions