Sorry for late reply.
Here is full backtrace I can have based on your commands:
(gdb) catch throw
Catchpoint 1 (throw)
(gdb) run train.py 
Starting program: /home/zarzen/anaconda3/bin/python train.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffb36dd700 (LWP 11650)]
[New Thread 0x7fffb2edc700 (LWP 11651)]
[New Thread 0x7fffb26db700 (LWP 11652)]
[New Thread 0x7fffabeda700 (LWP 11654)]
[New Thread 0x7fffab6d9700 (LWP 11655)]
[New Thread 0x7fffa2ed8700 (LWP 11656)]
Traceback (most recent call last):
  File "train.py", line 32, in <module>
    train()
  File "train.py", line 25, in train
    loss.backward()
  File "/home/zarzen/anaconda3/lib/python3.6/site-packages/torch/autograd/variable.py", line 167, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph, retain_variables)
  File "/home/zarzen/anaconda3/lib/python3.6/site-packages/torch/autograd/__init__.py", line 99, in backward
    variables, grad_variables, retain_graph)
RuntimeError: invalid argument 1: expected 3D tensor, got 4D at /opt/conda/conda-bld/pytorch_1512386481460/work/torch/lib/TH/generic/THTensorMath.c:1630
[Thread 0x7fffa2ed8700 (LWP 11656) exited]
[Thread 0x7fffab6d9700 (LWP 11655) exited]
[Thread 0x7fffabeda700 (LWP 11654) exited]
[Thread 0x7fffb26db700 (LWP 11652) exited]
[Thread 0x7fffb2edc700 (LWP 11651) exited]
[Thread 0x7fffb36dd700 (LWP 11650) exited]
[Inferior 1 (process 11646) exited with code 01]