Just found a solution …
Inside the web browser that shows the Jupyter window,

select Kernel from the top menu
select Change Kernel

select the new kernel, in my case Python [conda env: new_env_name]


Continuing … to get the right graph, besides removing “Variable”, I also need to change the input argument of make_dot() …
The modified code is:
%reload_ext autoreload
%autoreload 2

import os, re, math, copy, datetime, sys, traceback
import numpy as np 
import scipy.signal as signal 

import torch                            
#from torch.autograd import Variable
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import Dataset, DataLoader
from torch.optim import lr_scheduler

import GPUtil
import pdb

gpu_avail = GPUtil.getAvailable()

if gpu_avail == []:
    print ('There are no free GPUs; using CPU.')
    use_gpu = False
else:
    use_gpu = True

num_samples = 2000
numCats = 10
batch_size = 256

class BnLayer2(nn.Module):
    def __init__(self, ni, nf, stride=2, kernel_size=(3,3)):
        super().__init__()
        self.conv1 = nn.Conv2d(ni, nf, kernel_size=kernel_size, stride=stride,
                              bias=False, padding=(1,1))
        self.bn1 = nn.BatchNorm2d(nf)
        self.conv2 = nn.Conv2d(nf, nf, kernel_size=kernel_size, stride=stride,
                              bias=False, padding=(1,1))
        self.bn2 = nn.BatchNorm2d(nf)
               
    def forward(self, x):
        x = F.relu(self.bn1(self.conv1(x))) 
        x = F.relu(self.bn2(self.conv2(x)))    
        return x

class SimpleNet(nn.Module):
    def __init__(self, layers, c, input_shape, p=0.2):
        super().__init__()
        self.input_shape = input_shape
        self.conv1 = nn.Conv2d(1, layers[0], kernel_size=(3,3), stride=1, padding=(1,1))
        self.layers = BnLayer2(layers[0], layers[1])
        self.out = nn.Linear(layers[-1] + 1, c)  # with concatenation
        #self.out = nn.Linear(layers[-1], c)  # without concatenation
        self.drop = nn.Dropout(p)

    def do_sth(self, x):
        max_x = torch.max(x, 1)
        return max_x   

    def forward(self, x):
        x_init = x  
        x = x.view(-1,*self.input_shape)        
        x = F.relu(self.conv1(x))    
        x = self.layers(x)
        x = F.adaptive_max_pool2d(x, 1)
        max_x = self.do_sth(x)
        max_val = torch.FloatTensor(max_x[0].data) 
        max_val = max_val[:, None, :, :] * 0
        #x = Variable(torch.cat((x.data, max_val), 1))  # concatenation causes parameters cut off
        x = torch.cat((x.data, max_val), 1)
        x = x.view(x.size(0), -1)
        x = self.drop(x)       
        return F.log_softmax(self.out(x), dim=-1)

model = SimpleNet([10,13], numCats, (1,2,num_samples), p=0.20)  # p = dropout

from graphviz import Digraph
from torchviz import make_dot

#x=Variable(torch.randn(batch_size,1,2,num_samples))
x=torch.randn(batch_size,1,2,num_samples, requires_grad=True)
y=model(x)
#dot = make_dot(y.mean(),params=dict(model.named_parameters()))  # this causes KeyError with pytorch 0.3.1
dot = make_dot(y)
dot.attr(size="140,140")  
dot

The correct graph is:

correct_neural_net_with_pytorch_0_4_1.png865×1543 48.1 KB

Cheers!