-
Notifications
You must be signed in to change notification settings - Fork 21.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pipelining] Consolidate test models into a registry
ghstack-source-id: ccfae8ac81f3964d1494e72b91a61feb3a07722a Pull Request resolved: #126114
- Loading branch information
Showing
5 changed files
with
153 additions
and
66 deletions.
There are no files selected for viewing
Empty file.
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,61 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates | ||
# Owner(s): ["oncall: distributed"] | ||
# This file is a model zoo for testing torch.distributed.pipelining. | ||
import torch | ||
from torch.distributed.pipelining import pipe_split | ||
|
||
|
||
class ExampleCode(torch.nn.Module): | ||
default_dhid = 512 | ||
default_batch_size = 256 | ||
|
||
def __init__(self, d_hid: int = default_dhid): | ||
super().__init__() | ||
self.mm_param0 = torch.nn.Parameter(torch.randn(d_hid, d_hid)) | ||
self.mm_param1 = torch.nn.Parameter(torch.randn(d_hid, d_hid)) | ||
self.register_buffer("cval", torch.randn((d_hid,), requires_grad=False)) | ||
self.lin0 = torch.nn.Linear(d_hid, d_hid) | ||
self.lin1 = torch.nn.Linear(d_hid, d_hid) | ||
|
||
def forward(self, x, y=torch.zeros(default_batch_size, default_dhid)): | ||
x = torch.mm(x, self.mm_param0) | ||
x = x + y | ||
x = torch.relu(x) | ||
# try passing a value that doesn't require_grad across skip boundaries | ||
a_constant = self.cval.clone() | ||
x = self.lin0(x) | ||
pipe_split() | ||
x = torch.relu(x) + a_constant | ||
x = torch.mm(x, self.mm_param1) | ||
x = self.lin1(x) | ||
x = torch.relu(x) | ||
return x | ||
|
||
|
||
# MLP Layer | ||
class MLPModule(torch.nn.Module): | ||
def __init__(self, d_hid): | ||
super().__init__() | ||
self.net1 = torch.nn.Linear(d_hid, d_hid) | ||
self.relu = torch.nn.ReLU() | ||
self.net2 = torch.nn.Linear(d_hid, d_hid) | ||
|
||
def forward(self, x): | ||
x = self.net1(x) | ||
x = self.relu(x) | ||
x = self.net2(x) | ||
return x | ||
|
||
|
||
# Multi-MLP model | ||
class MultiMLP(torch.nn.Module): | ||
def __init__(self, d_hid): | ||
super().__init__() | ||
self.mlp0 = MLPModule(d_hid) | ||
self.mlp1 = MLPModule(d_hid) | ||
|
||
def forward(self, x): | ||
x = self.mlp0(x) | ||
pipe_split() | ||
x = self.mlp1(x) | ||
return 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
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