GPU Memory Profiling

I’ve got a Torch: invalid memory size, do you know how can I do GPU memory profiling on my code?

Initializing CNN model
The model has 2,599,530 trainable parameters
Traceback (most recent call last):
  File "text_classification.py", line 268, in <module>
    main()
  File "text_classification.py", line 231, in main
    valid_loss, valid_acc = evaluate(model, valid_iterator, criterion)
  File "text_classification.py", line 121, in evaluate
    predictions = model(batch.text)
  File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 489, in __call__
    result = self.forward(*input, **kwargs)
  File "text_classification.py", line 58, in forward
    conved = [F.relu(conv(embedded)).squeeze(3) for conv in self.convs]
  File "text_classification.py", line 58, in <listcomp>
    conved = [F.relu(conv(embedded)).squeeze(3) for conv in self.convs]
  File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 489, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 320, in forward
    self.padding, self.dilation, self.groups)
RuntimeError: $ Torch: invalid memory size -- maybe an overflow? at /opt/conda/conda-bld/pytorch_1544199946412/work/aten/src/TH/THGeneral.cpp:188

Are you sure this is a GPU problem? I think that maybe something is wrong with tensor sizes (i.e. tensor.size()).

Just execute it on CPU and see if the error is still there.