Hey; I have multiple loss functions, each with respect to a batch of data point. I want to save each gradient to a buffer.Here is my way of doing
buffer = []
for b in range(num_batch):
    weights.zero_grad()
    loss = loss_func(batch[b])
    loss.backward()
    buffer.append(weights.grad)

However, I’m wondering if there is any none-loop way of doing this ?