From this line of code 5 it seems the validation data are the first 5000 images of the train set, while the training data is the rest.
You can split the dataset in the same way using SubsetRandomSampler:
train_dataset = datasets.MNIST(root='./', train=True)
valid_dataset = datasets.MNIST(root='./', train=True)
test_dataset = datasets.MNIST(root='./', train=False)

indices = list(range(len(train_dataset)))
validation_size = 5000
train_idx, valid_idx = indices[validation_size:], indices[:validation_size]
train_sampler = SubsetRandomSampler(train_idx)
valid_sampler = SubsetRandomSampler(valid_idx)

train_loader = DataLoader(
    train_dataset,
    batch_size=64,
    sampler=train_sampler,
    num_workers=2
)

valid_loader = DataLoader(
    valid_dataset,
    batch_size=64,
    sampler=train_sampler,
    num_workers=2
)

test_loader = DataLoader(
    test_dataset,
    batch_size=64,
    num_workers=2
)