Hi,
You can do this, and if the backward does not raise an error you will get the correct gradients.
What can happen though is that you get Tensor needed for backward has been changed by an inplace operation. As inplace operations can change a tensor needed during the backward pass. The engine is over-restrictive and so if it works, will always give the right answer. If it does not, you will have to remove the inplace ops. To create a vector of results, you can for example store them in a list while you create them and then cat them at the end.