The length of a DataLoader returns the number of batches.
I’m not sure what’s your current use case, as you are somehow using the number of batches and the current epoch to reset the iterator.
Could you explain your use case a bit?