You could take a look at the sampler implementations and adapt one to your use case. In particular I think you might want to pass the target tensors to the sampler and create the desired sample indices in the __iter__ method.