Google Colab raised an issue Regarding Pytorch

Here is my Error:
RuntimeError: isDifferentiableType(variable.scalar_type()) INTERNAL ASSERT FAILED at “/pytorch/torch/csrc/autograd/functions/utils.h”:59, please report a bug to PyTorch.

2 Likes

Could you post a code snippet to reproduce this error or link to your notebook, so that we could have a look?

here is my code

import torch.nn as nn
import csv
import numpy
import numpy as np
class PrintLayer(nn.Module):
    def __init__(self):
        super(PrintLayer, self).__init__()
        m = nn.Conv2d(3, 96, kernel_size=(11,11), stride=(4,4), padding=0, bias = False)
    
    def forward(self, x):
        # Do your print / debug stuff here
        #print("x is",x)
        return x

def init_weights(m):
      if type(m) == nn.Conv2d:
        torch.nn.init.xavier_uniform(m.weight)
        #for weight
        a_file1 = open("1st_layer_8bit_weight.txt","r")
        list_of_lists1 = []
        for line in a_file1:
          stripped_line1 = line.strip()
          line_list1 = stripped_line1.split()
          list_of_lists1.extend(line_list1)
        a_file1.close()

        b = torch.from_numpy(numpy.array(list_of_lists1,dtype= 'int8'))
        w = torch.tensor(b)
        ten = w.reshape(96,3,11,11)
        m.weight.data = ten

        #for bias
        """a_file12 = open("bias.txt","r")
        list_of_lists12 = []
        for line in a_file12:
          stripped_line12 = line.strip()
          line_list12 = stripped_line12.split()
          list_of_lists12.extend(line_list12)
        a_file12.close()

        c = torch.from_numpy(numpy.array(list_of_lists12,dtype= 'float32'))
        d = torch.tensor(c)
        ten1 = d.reshape(256)
        m.bias.data = ten1"""
       
        #print("actual weight is",m.weight)
        #print(m.bias)
      
model = nn.Sequential(
        nn.Conv2d(3, 96, kernel_size=(11,11), stride=(4,4), padding=0, bias = False),
        PrintLayer(),
         # Add Print layer for debug
        )
model.apply(init_weights)

#for input
a_file = open("1st_layer_8bit_input.txt","r")
list_of_lists = []
for line in a_file:
  stripped_line = line.strip()
  line_list = stripped_line.split()
  list_of_lists.extend(line_list)
a_file.close()
b = torch.from_numpy(numpy.array(list_of_lists,dtype= 'int8'))
x = torch.tensor(b)
x = x.reshape(1,3,227,227)
output = model(x)

np.set_printoptions(threshold=50000000,formatter={'float_kind':'{:f}'.format})
output = output.detach().numpy()
file = open("correct_output.txt","w")
file.write(str(output))
file.close()
print(model)
#for weight and bias
print(list(model.named_parameters()))
#print(model.state_dict())```

Thanks for the code. Unfortunately, I cannot reproduce this issue using random input data, since the used file is undefined.
Are you only seeing the error using the weights loaded from the file or could you post an executable code snippet?