I am performing Federated learning using pysyft and pytorch. I am using a diabetes dataset. I got this error while training(element 0 of tensors does not require grad and does not have a grad_fn). I am attaching the screen shots of my error and also the note book file:

enter image description here

My code:

epochs = 500
final_loss = []
for i in range(epochs):
    i = i + 1
    model.train()
    for batch_idx, (data, target) in enumerate(federated_train_loader): # <-- now it is a distributed dataset
        model.send(data.location) # <-- NEW: send the model to the right location
   
        data, target = data.to(device), target.to(device)
        output = model.forward(data)
        loss = loss_function(output, target)
        final_loss.append(loss)
        if i % 10 == 1:
            print('Epoch number: {} and the loss: {}'.format(i, loss.get()))
        optimizer.zero_grad() ## Clears the gradients of all optimized class
        loss.backward() ## for backward propagation and to find the derivative
        optimizer.step() ## performs a single optimization step.
        model.get()

My model:

class ANN_Model(nn.Module):
    def __init__(self, input_features = 8, hidden1 = 20, hidden2 = 20, out_features = 2):
        super().__init__()
        self.f_connected1 = nn.Linear(input_features, hidden1)
        self.f_connected2 = nn.Linear(hidden1, hidden2)
        self.out = nn.Linear(hidden2, out_features)
    def forward(self, x):
        x = F.relu(self.f_connected1(x))
        x = F.relu(self.f_connected2(x))
        x = self.out(x)
        return x
0

There are 0 answers