Kernel have died it will restart automatically

Hi there, when i was training the neural network the system shows this below is my code

depth=[4,8]
class ConvNet(nn.Module):
def init(self):
super(ConvNet,self).init()
self.conv1=nn.Conv2d(1,4,5,padding=2)
self.pool=nn.MaxPool2d(2,2)
#No2.Convolution
self.conv2=nn.Conv2d(depth[0],depth[1],5,padding=2)
self.fc1=nn.Linear(image_size//4image_size//4depth[1],512)#int division
self.fc2=nn.Linear(512,num_classes)
def forward(self,x):
x=self.conv1(x)
x=F.relu(x)
x=self.pool(x)
x=self.conv2(x)
x=F.relu(x)
x=self.pool(x)
x=x.view(-1,image_size//4image_size//4depth[1])
x=F.relu(self.fc1(x))
x=F.dropout(x,training=self.training)
x=self.fc2(x)
x=F.log_softmax(x,dim=1)
return x
def retreive_features(self,x):#get_features maps
features_map1=F.relu(self.conv1(x))
x=self.pool(feature_map1)
features_map2=F.relu(self.conv2(x))
return (features_map1,features_map2)

criterion=nn.CrossEntropyLoss()
optimizer=optim.SGD(net.parameters(),lr=0.001,momentum=0.9)
record=[]
weights=[]
for epoch in range(num_epochs):
#train_rights=[]
for batch_idx,(data,target) in enumerate(train_loader):
data,target=Variable(data).cuda(),Variable(target).cuda()#change Tensor to Variable
net.train()
output=net(data)
loss=criterion(output,target)#calculate loss
optimizer.zero_grad()
loss.backward()
optimizer.step()
if batch_idx%100==0:
net.eval()
#val_rights=[]
print(loss)
for (data,target) in validation_loader:
data,target=Variable(data).cuda(),Variable(target).cuda()
output=net(data)

My TEMP MEMEORY is 16GB it rises from 4.8 to 7.3 then it shows the message->kernel have died
it will restart automatically ,how can i do?
PS:my init has underline so don’t worry

Could you run the code in a terminal, as this should give you a proper error message?

er…no… Also i run on pycharm same problem so i don’t know why…Is this pytoch’s problem?

Hard to tell without a proper error message.
So far it seems your IPython kernel dies, so it might be related to PyTorch.

I wonder why torch has some problem that it can’t solve

It’s not necessarily a PyTorch issue, since the Jupyter kernel might die without printing a proper error message due to other issues in the code.
Since you cannot run the code in a terminal to get a proper error message, I would recommend to remove code snippets until you can properly isolate the kernel restart to a small code snippet.

I had a similar issue using Conv2d with PyTorch 1.1 (which I had to use due to compatibility with an old GPU), it disappeared when I used a more recent version of PyTorch.

I know this is not a very specific response, but maybe it helps anyway.