Comments (13)
Yes, you should see a greater improvement by using larger batches and/or a larger model.
from practical-pytorch.
The tutorial does not use CUDA yet - usually you have to do something like
tensor = tensor.cuda()
for every tensor and model, to move it over to GPU. I will be updating it soon to include this.
from practical-pytorch.
I just updated it to include a USE_CUDA variable
from practical-pytorch.
Thank you for your help :οΌ
I tried to add .cuda()
in code, itβs only a slight acceleration for the run time. Due to the use of GPU is not high, I guess it maybe be related to batch_size
.
from practical-pytorch.
Was this change reverted? I don't see any CUDA commands in the code...
from practical-pytorch.
Currently only the seq2seq tutorial uses CUDA.
from practical-pytorch.
To run char-rnn-generation on 4 GPUs I need to create input batches (characters from multiple chunks), and change the leading dimension of inputs and outputs in forward function to batch_size, correct?
from practical-pytorch.
That sounds right... char-rnn.pytorch might help as it has batching & CUDA support, but I haven't tried it on multiple GPUs.
from practical-pytorch.
I implemented batching, but can't get it to work on multiple GPUs. Here's my code.
Using batch_size=64, I want to give each of my four GPUs 16 training samples, but instead I get this error:
Traceback (most recent call last):
File "char-rnn.py", line 185, in <module>
output, hidden = net(c, hidden, batch_size)
File "/root/miniconda2/lib/python2.7/site-packages/torch/nn/modules/module.py", line 206, in __call__
result = self.forward(*input, **kwargs)
File "/root/miniconda2/lib/python2.7/site-packages/torch/nn/parallel/data_parallel.py", line 61, in forward
outputs = self.parallel_apply(replicas, inputs, kwargs)
File "/root/miniconda2/lib/python2.7/site-packages/torch/nn/parallel/data_parallel.py", line 71, in parallel_apply
return parallel_apply(replicas, inputs, kwargs)
File "/root/miniconda2/lib/python2.7/site-packages/torch/nn/parallel/parallel_apply.py", line 45, in parallel_apply
raise output
RuntimeError: size '[64 x 1]' is invalid for input of with 16 elements at /py/conda-bld/pytorch_1490981920203/work/torch/lib/TH/THStorage.c:59
So it seems like each GPU (or just one GPU, not sure) gets full batch of 64 samples. Any ideas?
from practical-pytorch.
It looks like one caveat of DataParallel is you need the first dimension of every input to be the batch size (looking at https://github.com/pytorch/examples/pull/80/files) so maybe try transposing within the RNN module. Currently due to .t()
the input and target data are seq-first, and the hidden state of the RNN will be seq-first by default. You could also try the batch_first
argument of GRU. Beyond that I can't be too helpful because I only have one GPU π
from practical-pytorch.
Ok, I used batch_first=True, and have my inputs and outputs in correct shape, but now it complains about hidden, which as you said is seq-first by default.
class RNN(nn.Module):
def __init__(self, input_size, hidden_size, output_size, n_layers):
super(RNN, self).__init__()
self.input_size = input_size
self.hidden_size = hidden_size
self.output_size = output_size
self.n_layers = n_layers
self.encoder = nn.Embedding(input_size, hidden_size) #first arg is dictionary size
self.GRU = nn.GRU(hidden_size, hidden_size, n_layers, batch_first=True)
self.decoder = nn.Linear(hidden_size, output_size)
def forward(self, input, hidden, batch_size):
input = self.encoder(input)
output, hidden = self.GRU(input, hidden)
output = self.decoder(output)
return output, hidden
def init_hidden(self, batch_size):
return Variable(torch.randn(self.n_layers, batch_size, self.hidden_size).cuda())
Traceback (most recent call last):
File "char-rnn.py", line 232, in <module>
output = net(c, batch_size)
File "/root/miniconda2/lib/python2.7/site-packages/torch/nn/modules/module.py", line 206, in __call__
result = self.forward(*input, **kwargs)
File "/root/miniconda2/lib/python2.7/site-packages/torch/nn/parallel/data_parallel.py", line 61, in forward
outputs = self.parallel_apply(replicas, inputs, kwargs)
File "/root/miniconda2/lib/python2.7/site-packages/torch/nn/parallel/data_parallel.py", line 71, in parallel_apply
return parallel_apply(replicas, inputs, kwargs)
File "/root/miniconda2/lib/python2.7/site-packages/torch/nn/parallel/parallel_apply.py", line 45, in parallel_apply
raise output
RuntimeError: Expected hidden size (2, 16L, 256), got (2L, 64L, 256L)
Any ideas on what to do about this hidden tensor?
from practical-pytorch.
Could be related to the init_hidden
method, it might be easier to switch from hidden = net.module.init_hidden(batch_size)
to hidden = None
there and let the GRU handle it.
from practical-pytorch.
I thought so too, so I modified your code like this: https://gist.github.com/michaelklachko/540428fc112f5a6b06e842bb6a3f5e1e
However, getting the same error, looks like the hidden tensor inside the forward function must have batch_size as first dim as well. I don't quite understand how they managed to get it working in the OpenNMT code...
from practical-pytorch.
Related Issues (20)
- Issue on Windows
- Seq-seq not working for creating chatbot
- How to save and load train model and use it for evaluation HOT 2
- Link for Series 2 - RNNs for time-series data
- Question about Luong Attention Implementation HOT 7
- can't import torch HOT 2
- The link for Teacher Forcing in "Translation with a Sequence to Sequence Network and Attention" is broken
- Error in BahdanauAttnDecoderRNN HOT 1
- Issues in your tutorial on Classifying Names with a Character-Level RNN
- I can't calculate the score of attention in Seq2Seq Translation. HOT 2
- Error in practical-pytorch/seq2seq-translation/seq2seq-translation-batched.ipynb
- Question from character level RNN classifier, why not use the hidden state across epochs? HOT 1
- RuntimeError: 1D tensors expected, got 2D, 2D tensors HOT 1
- May I know how to support a new sentence translation?
- seq2seq: Replace the embeddings with pre-trained word embeddings such as word2vec
- About seq2seq-translation-batched.py RuntimeError HOT 1
- Wrong implementation of attention mechanism in pytorch tutorials
- FileNotFoundError: [Errno 2] No such file or directory: 'char-rnn-classification.pt'
- small format issue
- Implicit dimension choice for log_softmax has been deprecated while running 'python train.py'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from practical-pytorch.