import torch as tc
import torch.multiprocessing as mp
def do_something():
b = tc.randn(1000, 1000)
print(f'A tensor is created in process {mp.current_process().name}')
print(b.sum()) # This line hangs forever
def bug():
# a = tc.randn(1000, 1000)
a = tc.ones(1000, 1000) # comment out this line and revive the line above will make the bug go away
p = mp.Process(target=do_something, args=())
p.start()
p.join()
if __name__ == '__main__':
bug()
My torch version is 1.10.2
It is crazy that creating a tensor in parent process causes a deadlock in the child process, and the tensor is not even passed to the child process.
It is even crazier that if I replace the tensor in parent process with anther one, the deadlock goes away!
Is it generally not recommended to use forked subprocess in pytorch?
thanks
I ran your code and did not see any bugs. The code just completed smoothly. My torch is 1.10.0