The mnist dataset is actually a file with two Tensors, one for images and one for labels. You can see how it’s loaded here: https://github.com/pytorch/vision/blob/74de51d6d478e289135d9274e6af550a9bfba137/torchvision/datasets/mnist.py#L89 23
So you can just modify these two Tensors and save them again.