I’m trying to figure out how one can compute the gradient for individual samples in a batched fashion.  Specifically, given an input batch, and the score outputs (ex mse for each sample), I want to compute what the gradients are for each item in the batch.  I can think of a simple way to do this, which is just running forward/backward passes on individual items in a for loop, but that seems like it would be slow (since you’re looping in python instead of efficiently doing the forward prop on the whole batch).  Is there a better way to do this?