How pytorch's parallel method and distributed method works?











up vote
3
down vote

favorite
1












I'm no expert in distributed system and CUDA. But there is one really interesting feature that PyTorch support which is nn.DataParallel and nn.DistributedDataParallel. How they are actually implemented? How they separate common embeddings and synchronize data?



Here is a basic example of DataParallel.



import torch.nn as nn
from torch.autograd.variable import Variable
import numpy as np

class Model(nn.Module):
def __init__(self):
super().__init__(
embedding=nn.Embedding(1000, 10),
rnn=nn.Linear(10, 10),
)

def forward(self, x):
x = self.embedding(x)
x = self.rnn(x)
return x

model = nn.DataParallel(Model())
model.forward(Variable.from_numpy(np.array([1,2,3,4,5,6], dtype=np.int64)).cuda()).cpu()


PyTorch can split the input and send them to many GPUs and merge the results back.



How does it manage embeddings and synchronization for a parallel model or a distributed model?

I wandered around PyTorch's code but it's very hard to know how the fundamentals work.










share|improve this question

















This question has an open bounty worth +50
reputation from fantasticfears ending in 3 days.


This question has not received enough attention.












  • 1




    It might actually be better to ask on pytorch forums.
    – Umang Gupta
    Nov 22 at 20:06










  • My question on the forum: discuss.pytorch.org/t/…
    – fantasticfears
    yesterday















up vote
3
down vote

favorite
1












I'm no expert in distributed system and CUDA. But there is one really interesting feature that PyTorch support which is nn.DataParallel and nn.DistributedDataParallel. How they are actually implemented? How they separate common embeddings and synchronize data?



Here is a basic example of DataParallel.



import torch.nn as nn
from torch.autograd.variable import Variable
import numpy as np

class Model(nn.Module):
def __init__(self):
super().__init__(
embedding=nn.Embedding(1000, 10),
rnn=nn.Linear(10, 10),
)

def forward(self, x):
x = self.embedding(x)
x = self.rnn(x)
return x

model = nn.DataParallel(Model())
model.forward(Variable.from_numpy(np.array([1,2,3,4,5,6], dtype=np.int64)).cuda()).cpu()


PyTorch can split the input and send them to many GPUs and merge the results back.



How does it manage embeddings and synchronization for a parallel model or a distributed model?

I wandered around PyTorch's code but it's very hard to know how the fundamentals work.










share|improve this question

















This question has an open bounty worth +50
reputation from fantasticfears ending in 3 days.


This question has not received enough attention.












  • 1




    It might actually be better to ask on pytorch forums.
    – Umang Gupta
    Nov 22 at 20:06










  • My question on the forum: discuss.pytorch.org/t/…
    – fantasticfears
    yesterday













up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





I'm no expert in distributed system and CUDA. But there is one really interesting feature that PyTorch support which is nn.DataParallel and nn.DistributedDataParallel. How they are actually implemented? How they separate common embeddings and synchronize data?



Here is a basic example of DataParallel.



import torch.nn as nn
from torch.autograd.variable import Variable
import numpy as np

class Model(nn.Module):
def __init__(self):
super().__init__(
embedding=nn.Embedding(1000, 10),
rnn=nn.Linear(10, 10),
)

def forward(self, x):
x = self.embedding(x)
x = self.rnn(x)
return x

model = nn.DataParallel(Model())
model.forward(Variable.from_numpy(np.array([1,2,3,4,5,6], dtype=np.int64)).cuda()).cpu()


PyTorch can split the input and send them to many GPUs and merge the results back.



How does it manage embeddings and synchronization for a parallel model or a distributed model?

I wandered around PyTorch's code but it's very hard to know how the fundamentals work.










share|improve this question















I'm no expert in distributed system and CUDA. But there is one really interesting feature that PyTorch support which is nn.DataParallel and nn.DistributedDataParallel. How they are actually implemented? How they separate common embeddings and synchronize data?



Here is a basic example of DataParallel.



import torch.nn as nn
from torch.autograd.variable import Variable
import numpy as np

class Model(nn.Module):
def __init__(self):
super().__init__(
embedding=nn.Embedding(1000, 10),
rnn=nn.Linear(10, 10),
)

def forward(self, x):
x = self.embedding(x)
x = self.rnn(x)
return x

model = nn.DataParallel(Model())
model.forward(Variable.from_numpy(np.array([1,2,3,4,5,6], dtype=np.int64)).cuda()).cpu()


PyTorch can split the input and send them to many GPUs and merge the results back.



How does it manage embeddings and synchronization for a parallel model or a distributed model?

I wandered around PyTorch's code but it's very hard to know how the fundamentals work.







c++ python-3.x parallel-processing distributed-computing pytorch






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 13:50









blue-phoenox

3,27181439




3,27181439










asked Nov 19 at 13:13









fantasticfears

31129




31129






This question has an open bounty worth +50
reputation from fantasticfears ending in 3 days.


This question has not received enough attention.








This question has an open bounty worth +50
reputation from fantasticfears ending in 3 days.


This question has not received enough attention.










  • 1




    It might actually be better to ask on pytorch forums.
    – Umang Gupta
    Nov 22 at 20:06










  • My question on the forum: discuss.pytorch.org/t/…
    – fantasticfears
    yesterday














  • 1




    It might actually be better to ask on pytorch forums.
    – Umang Gupta
    Nov 22 at 20:06










  • My question on the forum: discuss.pytorch.org/t/…
    – fantasticfears
    yesterday








1




1




It might actually be better to ask on pytorch forums.
– Umang Gupta
Nov 22 at 20:06




It might actually be better to ask on pytorch forums.
– Umang Gupta
Nov 22 at 20:06












My question on the forum: discuss.pytorch.org/t/…
– fantasticfears
yesterday




My question on the forum: discuss.pytorch.org/t/…
– fantasticfears
yesterday

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375422%2fhow-pytorchs-parallel-method-and-distributed-method-works%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375422%2fhow-pytorchs-parallel-method-and-distributed-method-works%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Tonle Sap (See)

I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

Guatemaltekische Davis-Cup-Mannschaft