-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] add a Pipeline tutorial (#82)
- Loading branch information
Showing
5 changed files
with
63 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[settings] | ||
known_third_party =numpy,pytest,pytorch_sphinx_theme,recommonmark,setuptools,torch,torchtext,torchvision | ||
known_third_party =numpy,pytest,recommonmark,setuptools,torch,torchtext,torchvision |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
API Reference | ||
============= | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
optim/oss | ||
nn/pipe |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Tutorials | ||
========= | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
pipe |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Pipeline Parallel | ||
================= | ||
|
||
Let us start with a toy model that contains two linear layers. | ||
|
||
.. code-block:: default | ||
import torch | ||
import torch.nn as nn | ||
class ToyModel(nn.Module): | ||
def __init__(self): | ||
super(ToyModel, self).__init__() | ||
self.net1 = torch.nn.Linear(10, 10) | ||
self.relu = torch.nn.ReLU() | ||
self.net2 = torch.nn.Linear(10, 5) | ||
def forward(self, x): | ||
x = self.relu(self.net1(x)) | ||
return self.net2(x) | ||
model = ToyModel() | ||
To run this model on 2 GPUs we need to convert the model | ||
to ``torch.nn.Sequential`` and then wrap it with ``fairscale.nn.Pipe``. | ||
|
||
.. code-block:: default | ||
import fairscale | ||
import torch | ||
import torch.nn as nn | ||
model = nn.Sequential( | ||
torch.nn.Linear(10, 10), | ||
torch.nn.ReLU(), | ||
torch.nn.Linear(10, 5) | ||
) | ||
model = fairscale.nn.Pipe(model, balance=[2, 1]) | ||
This will run the first two layers on ``cuda:0`` and the last | ||
layer on ``cuda:1``. To learn more, visit the `Pipe <../api/nn/pipe.html>`_ documentation. |