This seems to be a multiprocessing pickle issue. How did you launch it. Is it sth like python test.py from command line or through notebook?
And can you confirm you see the same error even if you remove all torch.distributed code? Say make demo_basic into the following and remove other functions?
def demo_basic(rank, world_size):
    pass