Last active
December 11, 2017 07:12
-
-
Save diazona/fe65d04e00c17dead75a6dcf43aaf6e9 to your computer and use it in GitHub Desktop.
Simple example of multiprocessing
This file contains hidden or 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
import torch.multiprocessing as tmp | |
N_MINIBATCHES = 10 | |
def load_minibatches(q): | |
for i in range(N_MINIBATCHES): | |
# load minibatch i | |
q.put(minibatch) | |
q.close() | |
def train_neural_network(q): | |
for i in range(N_MINIBATCHES): | |
minibatch = q.get() | |
# train with minibatch i | |
def main(): | |
q = tmp.Queue(maxsize=1) | |
loader = tmp.Process(load_minibatches, args=(q,)) | |
loader.start() | |
trainer = tmp.Process(train_neural_network, args=(q,)) | |
trainer.start() | |
loader.join() | |
trainer.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment