I think that you don’t need to provide a custom collate function. You can just call .view on the output tensors to collapse the additional dimension.
About the iterator, it would be slightly more efficient to recreate the permutations only once they’re needed, not when the iterator is instantiated, but as long as your dataset isn’t huge it probably doesn’t matter too much.
I didn’t read the example very carefully but it looks good.