Skip to content

Instantly share code, notes, and snippets.

@EricCousineau-TRI
Created September 8, 2020 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricCousineau-TRI/4cedd0847ffc5acdd992403beffbc7b1 to your computer and use it in GitHub Desktop.
Save EricCousineau-TRI/4cedd0847ffc5acdd992403beffbc7b1 to your computer and use it in GitHub Desktop.
# Using torch==1.4.0
import numpy as np
import torch
import torch.multiprocessing as mp
torch.set_grad_enabled(False)
def target(inputs, outputs):
x = inputs.get()
outputs.put(x)
outputs.join()
inputs = mp.Queue(1)
outputs = mp.JoinableQueue(1)
value = torch.tensor([1., 2.])
inputs.put(value)
proc = mp.Process(target=target, args=(inputs, outputs))
proc.start()
x = outputs.get()
outputs.task_done()
proc.join()
print(x)
# Using torch==1.4.0
import numpy as np
import torch
import torch.multiprocessing as mp
torch.set_grad_enabled(False)
def target(inputs, outputs):
x = inputs.get()
if isinstance(x, torch.Tensor):
x = x.clone()
outputs.put(x)
inputs = mp.Queue(1)
outputs = mp.Queue(1)
# value = "hey" # Works.
# value = np.array([1]) # Works.
value = torch.tensor([1., 2.]) # Fails.
inputs.put(value)
proc = mp.Process(target=target, args=(inputs, outputs))
proc.start()
x = outputs.get()
proc.join()
proc.terminate()
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment