I think you could write a custom sampler by deriving or reusing the SubsetRandomSampler 5 and pass a length argument to it.
In the __iter__ method, you could use:
torch.randperm(len(self.indices), generator=self.generator).tolist()[:self.length]

Let me know, if this would work for you or if I misunderstood your use case.