One way to train a NN is
for epoch in range(1,30): 
     pred  = model(whole_input_data)
     loss = myLoss(pred, whole_target_data)
     opt.zero_grad()
     loss.backward()
     opt.step()

If the whole_input_data is very large, one resolves to training in mini-batches like this:
for epoch in range(1,300):
     for batch_x, batch_y in loader:
           pred = model(batch_x)
           loss_batch = myLoss(pred, batch_y)
           opt.zero_grad()
           loss.backward()
           opt.step()

The downside of above is one has to increase the number of epochs.
Does it make sense to call backward() method over loss_per_sample like following to train a NN;
for epoch in range(1, 3000):
     for x_per_sample, y_per_sample in zip(X_train, y_train):
           pred = model(x_per_sample)
           loss_per_sample = myLoss(pred, y_per_sample)
           opt.zero_grad()
           loss_per_sample.backward()
           opt.step()

Will it train the NN?