Fix reproducibility in Training for PyTorch 1.11
# What does this PR do?

It used to be that PyTorch called just one random operation in the `RandomSampler` code, so to ensure reproducibility, we only had to get the first batch of a dataloader to have its generator RNG be in the same state as if we had done the whole epoch.

Well not anymore... Introducing PyTorch 1.11, where the `RandomSampler` now does two random operations, one being at the very end. So we need to iterate through the whole sampler to guarantee reproducibility. This PR deals with that.
_The documentation is not available anymore as the PR was closed or merged._