You might want to check out the multiprocessing module–either the torch version or the native version available in Python: Multiprocessing package - torch.multiprocessing — PyTorch 1.10.1 documentation