Hi guys.
I am going through a tutorial of NN. I am stacked on a very similar thing. could you look at it? i controlled my code like 10x with other tutorial codes that are already working but still it returns this error:
w.grad.data.zero_()
AttributeError: 'NoneType' object has no attribute 'data'

I would apreciate any cluu to what am i missing here. thanks a lot!
class Data(Dataset):
        def __init__(self,X):
            self.x = torch.arange(-3,3,0.1).view(-1,1)
            #self.y = 1 * X - 1
            self.f = 1 * X - 1
            self.y = self.f + 0.1*torch.randn(self.x.size())
            self.len = self.x.shape[0]
            
        def __getitem__(self, index):
            return self.x[index], self.y[index]
        
        def __len__(self):
            return self.len
        
    def forward(x):
        return w*x + b
    
    def criterion(yhat,y):
        return torch.mean((yhat - y)**2)
    
    w = torch.tensor(-10.0, requires_grad=True)                    
    b = torch.tensor(-10.0, requires_grad=True)
    #init input for loss function testing
    X = torch.arange(-3, 3, 0.1).view(-1, 1)
    #prepare input data
    dataset = Data(X)        
    trainloader = DataLoader(dataset = dataset, batch_size = 4)
    
    lr = 0.1
    for epoch in range(4):              # learning process x-times
        for x,y in trainloader:             #   for every minibach do:
            #print(x,y)
            yhat = forward(x)           #     compute current output of function
            loss = criterion(yhat,y)    #     compute difference between current function and wanted function
            loss.backward()             #     examine slope of the loss function
            w = w.data - lr*w.grad.data #     prepare parameters for next model
            b = b.data - lr*b.grad.data
            w.grad.data.zero_()
            b.grad.data.zero_()