When i tried using max() it throw another error
Code is:
def my_MSELoss(predict, true):
    return ((predict - true)**2).mean()
    
for epoch in range(5):
    losses = 0.0
    for data, label in train_loader:
        #.float() to convert data into weights type
        #you can know type of weights through: 
        #next(model.conv1.parameters()).dtype
        network.zero_grad()
        predict = network(data.unsqueeze(1).float())
        print(predict.shape)
        #predict = predict.argmax(axis = 1)
        _, y_preds = predict.max(axis = 1)
        print(y_preds.shape)
        loss = my_MSELoss(y_preds, label.float())
        print(loss)
        loss.backward()
        optimizer.step()
        loss = loss.item()
        losses += loss
    print("For epoch: {}, losses are: {}".format(epoch + 1, losses))

Output is:
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn