Hi,
I guess you have two possibilites here:

When a particular element is finished, then remove it from the batch and continue the processing with only the remaining ones. At the end, recreate the output with all the elements.  For example, put outputs at the right place in a list (corresponding to the sample position in the batch) and then stack that list along the batch dimension at the end.
Process all the inputs all the way to the end of the net and keep all intermediary results then compute the final output with some masking: out = out_it1 * has_stopped_at_it1 + out_it2 * has_stopped_at_it2 + ... where has_stopped_at_it1 is a Tensor containing an entry for each element in the batch with 1 if this sample stopped at iteration 1 and 0 otherwise. and the sum of all these tensors should be a tensor full of 1 (each element should stop at some point).

The second one might be faster for most usecase. The first may win out if you have many iterations and most of your samples actually stop at a very early stage.