I have the following code below using torch.multiprocessing.spawn
to parallelize over multiple GPUs:
import numpy as np
import torch
from torch.multiprocessing import Pool, set_start_method, spawn
X = np.array([[1, 3, 2, 3], [2, 3, 5, 6], [1, 2, 3, 4]])
X = torch.DoubleTensor(X)
def X_power_func(j):
X_power = X.cuda()**j
return X_power
if __name__ == '__main__':
results = spawn(X_power_func, range(4), nprocs=1)
results
But I am getting this error below when I run the code:
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-9-97eb990d7396> in <module>()
12
13 if __name__ == '__main__':
---> 14 results = spawn(X_power_func, range(4), nprocs=1)
15
16 results
2 frames
/usr/local/lib/python3.6/dist-packages/torch/multiprocessing/spawn.py in join(self, timeout)
111 raise Exception(
112 "process %d terminated with exit code %d" %
--> 113 (error_index, exitcode)
114 )
115
Exception: process 0 terminated with exit code 1
What I have done wrong in my code?