Spyder just "kernel died,restarting" when I run net.forward in pytorch
I am using PYTHON IDE spyder3.2.1 in anaconda2, with python2.7, ubuntu14.04

code is just simple as follows:

import torch
from torch.autograd import Variable
import torch.nn as nn
import torch.nn.functional as F
import numpy as np

"""
input:[batch_size,in_channel,height,width]
kernel:[out_channel,in_channel,kh,kw]
"""
class Net(nn.Module):

    def __init__(self):
        super(Net, self).__init__()
        # 1 input image channel, 6 output channels, 5x5 square convolution
        # kernel
        self.conv1 = nn.Conv2d(1, 6, 5)
        #(28-5+1)/2=12
        self.conv2 = nn.Conv2d(6, 16, 5)
        #(12-5+1)/2=4
        # an affine operation: y = Wx + b
        self.fc1 = nn.Linear(16 * 5 * 5, 120)
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84, 10)

    def forward(self, x):
        # Max pooling over a (2, 2) window
        x = F.max_pool2d(F.relu(self.conv1(x)), (2, 2))
        # If the size is a square you can only specify a single number
        print "after conv1 size is {}".format(x.size())
        x = F.max_pool2d(F.relu(self.conv2(x)), 2)
        print "after conv2 size is {}".format(x.size())
        x = x.view(-1, self.num_flat_features(x))
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x

    def num_flat_features(self, x):
        size = x.size()[1:]  # all dimensions except the batch dimension
        num_features = 1
        for s in size:
            num_features *= s
        return num_features

net = Net()
print(net)

print "hello wrold"
input = Variable(torch.Tensor(np.random.randint(1,10,size=(1,1,32,32))))
print net.forward(input)


when I use jupyter notebook or console, it runs normally, it means the code has no error.
But when I use it from Spyder, it just hangs likes this:

As I am not allowed to embed the error image: it says "Kernel died, restarting"

I just try to shrink my code to find where the problem is.

The problem is absolutely around the very start F.max_pool2d(), in the forward method function.

But after I searched a lot, I still have no idea how to fix it.

conda list:

alabaster                 0.7.10                   py27_0  
anaconda                  4.4.0               np112py27_0  
anaconda-client           1.6.3                    py27_0  
anaconda-navigator        1.6.2                    py27_0  
anaconda-project          0.6.0                    py27_0  
asn1crypto                0.22.0                   py27_0  
astroid                   1.4.9                    py27_0  
astroid                   1.5.3                     &lt;pip&gt;
astropy                   1.3.2               np112py27_0  
Babel                     2.5.0                     &lt;pip&gt;
babel                     2.4.0                    py27_0  
backports                 1.0                      py27_0  
backports.functools-lru-cache 1.4                       &lt;pip&gt;
backports.weakref         1.0rc1                    &lt;pip&gt;
backports_abc             0.5                      py27_0  
beautifulsoup4            4.6.0                    py27_0  
bitarray                  0.8.1                    py27_0  
blaze                     0.10.1                   py27_0  
bleach                    1.5.0                    py27_0  
bleach                    2.0.0                     &lt;pip&gt;
bokeh                     0.12.5                   py27_1  
boto                      2.46.1                   py27_0  
bottleneck                1.2.1               np112py27_0  
cairo                     1.14.8                        0  
cdecimal                  2.3                      py27_2  
certifi                   2017.7.27.1               &lt;pip&gt;
cffi                      1.10.0                   py27_0  
chardet                   3.0.3                    py27_0  
chardet                   3.0.4                     &lt;pip&gt;
click                     6.7                      py27_0  
cloudpickle               0.2.2                    py27_0  
clyent                    1.2.2                    py27_0  
colorama                  0.3.9                    py27_0  
conda                     4.3.21                   py27_0  
conda-env                 2.6.0                         0  
configparser              3.5.0                    py27_0  
contextlib2               0.5.5                    py27_0  
cryptography              1.8.1                    py27_0  
curl                      7.52.1                        0  
cycler                    0.10.0                   py27_0  
cython                    0.25.2                   py27_0  
cytoolz                   0.8.2                    py27_0  
dask                      0.14.3                   py27_1  
datashape                 0.5.4                    py27_0  
dbus                      1.10.10                       0  
decorator                 4.0.11                   py27_0  
distributed               1.16.3                   py27_0  
docutils                  0.14                      &lt;pip&gt;
docutils                  0.13.1                   py27_0  
entrypoints               0.2.2                    py27_1  
entrypoints               0.2.3                     &lt;pip&gt;
enum34                    1.1.6                    py27_0  
et_xmlfile                1.0.1                    py27_0  
expat                     2.1.0                         0  
fastcache                 1.0.2                    py27_1  
flask                     0.12.2                   py27_0  
flask-cors                3.0.2                    py27_0  
fontconfig                2.12.1                        3  
freetype                  2.5.5                         2  
funcsigs                  1.0.2                    py27_0  
functools32               3.2.3.2                  py27_0  
futures                   3.1.1                    py27_0  
get_terminal_size         1.0.0                    py27_0  
gevent                    1.2.1                    py27_0  
glib                      2.50.2                        1  
greenlet                  0.4.12                   py27_0  
grin                      1.2.1                    py27_3  
gst-plugins-base          1.8.0                         0  
gstreamer                 1.8.0                         0  
h5py                      2.7.0               np112py27_0  
harfbuzz                  0.9.39                        2  
hdf5                      1.8.17                        1  
heapdict                  1.0.0                    py27_1  
html5lib                  0.999999999               &lt;pip&gt;
html5lib                  0.999                    py27_0  
icu                       54.1                          0  
idna                      2.5                      py27_0  
idna                      2.6                       &lt;pip&gt;
imagesize                 0.7.1                    py27_0  
ipaddress                 1.0.18                   py27_0  
ipykernel                 4.6.1                    py27_0  
ipython                   5.3.0                    py27_0  
ipython_genutils          0.2.0                    py27_0  
ipywidgets                6.0.0                    py27_0  
isort                     4.2.5                    py27_0  
isort                     4.2.15                    &lt;pip&gt;
itsdangerous              0.24                     py27_0  
jbig                      2.1                           0  
jdcal                     1.3                      py27_0  
jedi                      0.10.2                   py27_2  
jinja2                    2.9.6                    py27_0  
jpeg                      9b                            0  
jsonschema                2.6.0                    py27_0  
jupyter                   1.0.0                    py27_3  
jupyter-client            5.1.0                     &lt;pip&gt;
jupyter_client            5.0.1                    py27_0  
jupyter_console           5.1.0                    py27_0  
jupyter_core              4.3.0                    py27_0  
lazy-object-proxy         1.2.2                    py27_0  
lazy-object-proxy         1.3.1                     &lt;pip&gt;
libffi                    3.2.1                         1  
libgcc                    4.8.5                         2  
libgfortran               3.0.0                         1  
libiconv                  1.14                          0  
libpng                    1.6.27                        0  
libsodium                 1.0.10                        0  
libtiff                   4.0.6                         3  
libtool                   2.4.2                         0  
libxcb                    1.12                          1  
libxml2                   2.9.4                         0  
libxslt                   1.1.29                        0  
llvmlite                  0.18.0                   py27_0  
locket                    0.2.0                    py27_1  
lxml                      3.7.3                    py27_0  
Markdown                  2.6.8                     &lt;pip&gt;
markupsafe                0.23                     py27_2  
MarkupSafe                1.0                       &lt;pip&gt;
matplotlib                2.0.2               np112py27_0  
mccabe                    0.6.1                     &lt;pip&gt;
mistune                   0.7.4                    py27_0  
mkl                       2017.0.1                      0  
mkl-service               1.1.2                    py27_3  
mock                      2.0.0                     &lt;pip&gt;
mpmath                    0.19                     py27_1  
msgpack-python            0.4.8                    py27_0  
multipledispatch          0.4.9                    py27_0  
navigator-updater         0.1.0                    py27_0  
nbconvert                 5.2.1                     &lt;pip&gt;
nbconvert                 5.1.1                    py27_0  
nbformat                  4.4.0                     &lt;pip&gt;
nbformat                  4.3.0                    py27_0  
networkx                  1.11                     py27_0  
nltk                      3.2.3                    py27_0  
nose                      1.3.7                    py27_1  
notebook                  5.0.0                    py27_0  
numba                     0.33.0              np112py27_0  
numexpr                   2.6.2               np112py27_0  
numpy                     1.12.1                   py27_0  
numpy                     1.13.1                    &lt;pip&gt;
numpydoc                  0.6.0                    py27_0  
numpydoc                  0.7.0                     &lt;pip&gt;
odo                       0.5.0                    py27_1  
olefile                   0.44                     py27_0  
opencv                    1.0.1                     &lt;pip&gt;
opencv-python             3.3.0.9                   &lt;pip&gt;
openpyxl                  2.4.7                    py27_0  
openssl                   1.0.2l                        0  
packaging                 16.8                     py27_0  
pandas                    0.20.1              np112py27_0  
pandocfilters             1.4.1                    py27_0  
pandocfilters             1.4.2                     &lt;pip&gt;
pango                     1.40.3                        1  
partd                     0.3.8                    py27_0  
path.py                   10.3.1                   py27_0  
pathlib2                  2.3.0                     &lt;pip&gt;
pathlib2                  2.2.1                    py27_0  
patsy                     0.4.1                    py27_0  
pbr                       3.1.1                     &lt;pip&gt;
pcre                      8.39                          1  
pep8                      1.7.0                    py27_0  
pexpect                   4.2.1                    py27_0  
pickleshare               0.7.4                    py27_0  
pillow                    4.1.1                    py27_0  
pip                       9.0.1                    py27_1  
pixman                    0.34.0                        0  
ply                       3.10                     py27_0  
prompt_toolkit            1.0.14                   py27_0  
protobuf                  3.3.0                     &lt;pip&gt;
psutil                    5.2.2                    py27_0  
ptyprocess                0.5.1                    py27_0  
py                        1.4.33                   py27_0  
pycairo                   1.10.0                   py27_0  
pycodestyle               2.3.1                     &lt;pip&gt;
pycosat                   0.6.2                    py27_0  
pycparser                 2.17                     py27_0  
pycrypto                  2.6.1                    py27_6  
pycurl                    7.43.0                   py27_2  
pyflakes                  1.5.0                    py27_0  
pyflakes                  1.6.0                     &lt;pip&gt;
pygments                  2.2.0                    py27_0  
pylint                    1.6.4                    py27_1  
pylint                    1.7.2                     &lt;pip&gt;
pylzma                    0.4.9.post0               &lt;pip&gt;
pyodbc                    4.0.16                   py27_0  
PyOpenGL                  3.1.0                     &lt;pip&gt;
pyopenssl                 17.0.0                   py27_0  
pyparsing                 2.1.4                    py27_0  
pyqt                      5.6.0                    py27_2  
pytables                  3.3.0               np112py27_0  
pytest                    3.0.7                    py27_0  
python                    2.7.13                        0  
python-dateutil           2.6.1                     &lt;pip&gt;
python-dateutil           2.6.0                    py27_0  
pytz                      2017.2                   py27_0  
pywavelets                0.5.2               np112py27_0  
pyyaml                    3.12                     py27_0  
pyzmq                     16.0.2                   py27_0  
qt                        5.6.2                         4  
qtawesome                 0.4.4                    py27_0  
qtconsole                 4.3.0                    py27_0  
qtconsole                 4.3.1                     &lt;pip&gt;
qtpy                      1.2.1                    py27_0  
QtPy                      1.3.1                     &lt;pip&gt;
readline                  6.2                           2  
requests                  2.18.4                    &lt;pip&gt;
requests                  2.14.2                   py27_0  
rope                      0.10.7                    &lt;pip&gt;
rope                      0.9.4                    py27_1  
ruamel_yaml               0.11.14                  py27_1  
scandir                   1.5                      py27_0  
scikit-image              0.13.0              np112py27_0  
scikit-learn              0.18.1              np112py27_1  
scipy                     0.19.0              np112py27_0  
seaborn                   0.7.1                    py27_0  
setuptools                27.2.0                   py27_0  
setuptools                36.2.7                    &lt;pip&gt;
simplegeneric             0.8.1                    py27_1  
singledispatch            3.4.0.3                  py27_0  
sip                       4.18                     py27_0  
six                       1.10.0                   py27_0  
snowballstemmer           1.2.1                    py27_0  
sortedcollections         0.5.3                    py27_0  
sortedcontainers          1.5.7                    py27_0  
Sphinx                    1.6.3                     &lt;pip&gt;
sphinx                    1.5.6                    py27_0  
sphinxcontrib-websupport  1.0.1                     &lt;pip&gt;
spyder                    3.2.1                     &lt;pip&gt;
spyder                    3.1.4                    py27_0  
sqlalchemy                1.1.9                    py27_0  
sqlite                    3.13.0                        0  
ssl_match_hostname        3.4.0.2                  py27_1  
statsmodels               0.8.0               np112py27_0  
subprocess32              3.2.7                    py27_0  
sympy                     1.0                      py27_0  
tblib                     1.3.2                    py27_0  
tensorflow                1.2.1                     &lt;pip&gt;
tensorlayer               1.6.0                     &lt;pip&gt;
terminado                 0.6                      py27_0  
testpath                  0.3.1                     &lt;pip&gt;
testpath                  0.3                      py27_0  
tk                        8.5.18                        0  
toolz                     0.8.2                    py27_0  
torch-0.2.0               1                         &lt;pip&gt;
torchvision               0.1.9                     &lt;pip&gt;
tornado                   4.5.1                    py27_0  
tqdm                      4.15.0                    &lt;pip&gt;
traitlets                 4.3.2                    py27_0  
typing                    3.6.2                     &lt;pip&gt;
unicodecsv                0.14.1                   py27_0  
unixodbc                  2.3.4                         0  
urllib3                   1.22                      &lt;pip&gt;
wcwidth                   0.1.7                    py27_0  
webencodings              0.5.1                     &lt;pip&gt;
werkzeug                  0.12.2                   py27_0  
wheel                     0.29.0                   py27_0  
widgetsnbextension        2.0.0                    py27_0  
wrapt                     1.10.11                   &lt;pip&gt;
wrapt                     1.10.10                  py27_0  
xlrd                      1.0.0                    py27_0  
xlsxwriter                0.9.6                    py27_0  
xlwt                      1.2.0                    py27_0  
xz                        5.2.2                         1  
yaml                      0.1.6                         0  
zeromq                    4.1.5                         0  
zict                      0.1.2                    py27_0  
zlib                      1.2.8                         3


(Spyder developer here) I don't know why this is happening, but I opened an issue in our issue tracker so we don't forget to take a look at it in the future.

Update: This problem was solved by the OP by updating PyTorch.
