PyTorch is an open source (originating at FB) machine learning framework based on the Torch library. Although slightly absurd, there is apparently also a C++ interface. Looks like FB also ran Caffe2 which was a competing framework; what is notable is that FB merged Caffe and all references to it are now obsolete or best handled by dealing directly with PyTorch.

Some people really like it!

"I’ve been using PyTorch a few months now and I’ve never felt better. I have more energy. My skin is clearer. My eye sight has improved."

Installing

I’m sure there are potentially horrendous hurdles to get to "the starting line" for certain exotic requirements, but for just the basics, I was pleased that normal Debian (11) could handle this.

apt install python3-torch python3-torchvision

Of course that was too good to be true. On Debian 11 I easily got a native package for python3-torchtext 0.8.1-1 but Ubuntu had nothing that I could find.

This page has install hints for more reluctant systems.

Now it looks like a decision must be made between these. * Stable 1.11.0 * Nightly Build * LTS 1.8.2

And since apt doesn’t seem to be handling this for Ubuntu, figure out if Conda or Pip is better. The little chart at the top the getting started page is interactive and you can get the command you need by clicking on the things you want.

Important Ideas

In PyTorch, there are five types of tensors.

FloatTensor

32-bit float (default)

DoubleTensor

64-bit float

HalfTensor

16-bit float

IntTensor

32-bit int

LongTensor

64-bit int

Change the default type with:

torch.set_default_tensor_type(whatever)

Usage

Methods that end in _ will operate in place.

Here’s how to check if the gods of Nvidia smile upon you.

if torch.cuda.is_available(): print("Sacrificing a goat to my GPU worked!")

If you do have sweet CUDA love, you can move tensors to the GPU with something like:

x.torch.tensor
x= x.cuda()

PyTorch3d

Installation is not as simple as basic PyTorch (no Debian packages that I can see). Looks like the traditional Conda quagmire.

Troubleshooting

What if you run a Pytorch program and get this right after you run the tensor.backward() function?

terminate called without an active exception
Aborted

Well… I don’t know exactly. These folks also didn’t seem to know. These guys think that setting the environment variable TORCH_AUTOGRAD_SHUTDOWN_WAIT_LIMIT=0 will help; not for me.