Specify this sampler with DataLoader

Looking at the pytorch data loader docs, one can specify a custom sampler. In my current code, I sampled the indexes as follows:

batch_index = np.random.choice(batch_order, batch_size, p=seq_sample_probs).tolist()
batch = torch.tensor(data.x_train[batch_index], dtype=torch_dtype, device=torch_device, requires_grad=False)

I am moving everything to more modern pytorch and I have a Dataset object now. I wonder how I can now connect such a sampler in the corresponding data loader?

You can subclass torch.utils.data.Sampler torch.utils.data — PyTorch 1.10.0 documentation and pass an instance of this when constructing the DataLoader:
torch.utils.data — PyTorch 1.10.0 documentation

Since it looks like you are sampling batches here, you might also want to take a look at using batch_sampler instead.