It depends on your custom sampler and I don’t know how you’ve implemented it.
You could compare your implementation to the SequentialSampler 4, which returns iter(range(len(self.data_source))) and thus indices in the range of the dataset.