Created
September 8, 2020 15:19
-
-
Save EricCousineau-TRI/4cedd0847ffc5acdd992403beffbc7b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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