def train_epoch_cpu(trainLoader,model,optimizer,criterion,epoch):
Losses=[]

model.train()
for i, (ids, tensor) in enumerate(trainLoader):
   
    input_var = torch.autograd.Variable(tensor)
    # compute output
    output = model(input_var)
    loss = criterion(output)

    # loss = angular_distance(output.data.cpu(), targets.cpu())
    # compute gradient and do SGD step
    optimizer.zero_grad()
    loss.backward()
    Losses.append(loss.data.cpu()[0])
    optimizer.step()


    #print('Train Epoch: [{0}][{1}/{2}]\t'
       # 'angles {ang} ({ang})\t'
      #  'Loss {loss} ({loss})\t'.format(
       #  epoch, i, len(trainLoader), ang=loss, loss=Losses))

return loss

here in  output = model(input_var) the returned output is nan.
When i debug the code i find the model parametrs are nan also.
the initial declared net is :
NetDSpace (
(conv1): Conv2d(1, 6, kernel_size=(3, 3), stride=(1, 1))
(pool): MaxPool2d (size=(2, 2), stride=(2, 2), dilation=(1, 1))
(conv2): Conv2d(6, 16, kernel_size=(3, 3), stride=(1, 1))
(fc1): Linear (144 -> 2048)
(fc2): Linear (2048 -> 1024)
(fc3): Linear (1024 -> 400)