Questions tagged [torch]

Torch is a scientific computing framework for LuaJIT. It is widely used by machine learning researchers around the world.

Torch is a scientific computing framework based on Lua[JIT] with strong CPU and CUDA backends with wide support for machine learning algorithms. It is easy to use and provides a very efficient implementation, thanks to an easy and fast scripting language, LuaJIT, and an underlying C implementation.

Among other things, it provides:

  • a powerful N-dimensional array
  • lots of routines for indexing, slicing, transposing, ...
  • amazing interface to C, via LuaJIT
  • linear algebra routines
  • neural network, and energy-based models
  • numeric optimization routines

Torch7 website.

2264 questions
139
votes
4 answers

Pytorch, what are the gradient arguments

I am reading through the documentation of PyTorch and found an example where they write gradients = torch.FloatTensor([0.1, 1.0, 0.0001]) y.backward(gradients) print(x.grad) where x was an initial variable, from which y was constructed (a…
Qubix
  • 4,161
  • 7
  • 36
  • 73
92
votes
6 answers

How to check if two Torch tensors or matrices are equal?

I need a Torch command that checks if two tensors have the same content, and returns TRUE if they have the same content. For example: local tens_a = torch.Tensor({9,8,7,6}); local tens_b = torch.Tensor({9,8,7,6}); if (tens_a EQUIVALENCE_COMMAND…
DavideChicco.it
  • 3,318
  • 13
  • 56
  • 84
68
votes
5 answers

PyTorch: How to use DataLoaders for custom Datasets

How to make use of the torch.utils.data.Dataset and torch.utils.data.DataLoader on your own data (not just the torchvision.datasets)? Is there a way to use the inbuilt DataLoaders which they use on TorchVisionDatasets to be used on any dataset?
Sarthak
  • 1,076
  • 1
  • 12
  • 20
62
votes
11 answers

"AssertionError: Torch not compiled with CUDA enabled" in spite upgrading to CUDA version

I figured out this is a popular question, but still I couldn't find a solution for that. I'm trying to run a simple repo Here which uses PyTorch. Although I just upgraded my Pytorch to the latest CUDA version from pytorch.org (1.2.0), it still…
Tina J
  • 4,983
  • 13
  • 59
  • 125
62
votes
3 answers

Torch - How to change tensor type?

I created a permutation of the numbers from 1 to 3. th> y = torch.randperm(3 ); th> y 3 2 1 [torch.DoubleTensor of size 3] Now, I want to convert y to a Torch.LongTensor. How can I do that?
una_dinosauria
  • 1,881
  • 2
  • 18
  • 19
56
votes
1 answer

Pytorch. How does pin_memory work in Dataloader?

I want to understand how pin_memory in Dataloader works. According to the documentation: pin_memory (bool, optional) – If True, the data loader will copy tensors into CUDA pinned memory before returning them. Below is a self-contained code…
Ivan Belonogov
  • 719
  • 1
  • 6
  • 8
49
votes
3 answers

What is the relationship between PyTorch and Torch?

There are two PyTorch repositories : https://github.com/hughperkins/pytorch https://github.com/pytorch/pytorch 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…
Labo
  • 2,482
  • 2
  • 18
  • 38
45
votes
2 answers

Taking subsets of a pytorch dataset

I have a network which I want to train on some dataset (as an example, say CIFAR10). I can create data loader object via trainset = torchvision.datasets.CIFAR10(root='./data', train=True, download=True,…
Miriam Farber
  • 18,986
  • 14
  • 61
  • 76
38
votes
3 answers

Pytorch RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got CUDAType instead

I am trying to re-execute a GitHub project on my computer for recommendation using embedding, the goal is to first embed the user and item present in the movieLens dataset, and then use the inner product to predict a rating, when I finished the…
Ilyes
  • 581
  • 1
  • 5
  • 12
34
votes
3 answers

What is the difference of static Computational Graphs in tensorflow and dynamic Computational Graphs in Pytorch?

When I was learning tensorflow, one basic concept of tensorflow was computational graphs, and the graphs was said to be static. And I found in Pytorch, the graphs was said to be dynamic. What's the difference of static Computational Graphs in…
user166974
  • 443
  • 1
  • 4
  • 4
30
votes
1 answer

Why is PyTorch called PyTorch?

I have been looking into deep learning frameworks lately and have been wondering about the origin of the name of PyTorch. With Keras, their home page nicely explains the name's origin, and with something like TensorFlow, the reasoning behind the…
Grayscale
  • 1,462
  • 1
  • 13
  • 20
27
votes
2 answers

What is the difference between view() and unsqueeze() in Torch?

Use of unsqueeze(): input = torch.Tensor(2, 4, 3) # input: 2 x 4 x 3 print(input.unsqueeze(0).size()) # prints - torch.size([1, 2, 4, 3]) Use of view(): input = torch.Tensor(2, 4, 3) # input: 2 x 4 x 3 print(input.view(1, -1, -1, -1).size()) #…
Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161
26
votes
2 answers

What is the proper way to weight decay for Adam Optimizer

Since Adam Optimizer keeps an pair of running averages like mean/variance for the gradients, I wonder how it should properly handle weight decay. I have seen two ways of implementing it. Only update mean/variance from the gradients based on the…
Kato
  • 478
  • 1
  • 5
  • 8
24
votes
3 answers

AttributeError: '_MultiProcessingDataLoaderIter' object has no attribute 'next'

I am trying to load the dataset using Torch Dataset and DataLoader, but I got the following error: AttributeError: '_MultiProcessingDataLoaderIter' object has no attribute 'next' the code I use is: class WineDataset(Dataset): def…
Adham Enaya
  • 780
  • 1
  • 11
  • 29
24
votes
6 answers

How to access the network weights while using PyTorch 'nn.Sequential'?

I'm building a neural network and I don't know how to access the model weights for each layer. I've tried model.input_size.weight Code: input_size = 784 hidden_sizes = [128, 64] output_size = 10 # Build a feed-forward network model =…
Muhammad Shamel
  • 301
  • 1
  • 2
  • 6
1
2 3
99 100