This code is correct, assuming that inputs is all the instances of the training, i.e. there is only 1 batch in trainloader?
for epoch in range(n_epochs):

    for i, [inputs, labels] in enumerate(trainloader):
        inputs = inputs.to(device)
        labels = labels.to(device)

        # Forward + backward + optimize
        outputs = net(inputs.float())

        if epoch == 1:
            optimizer = torch.optim.Adam(net.parameters())

        optimizer.zero_grad()
        
        loss = criterion(outputs, labels.float())
        loss.backward()
        optimizer.step()