MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / MLPBlock

Class MLPBlock

tests/unit/compile/test_tp_compile.py:30–43  ·  view source on GitHub ↗

Llama-style MLP: gate/up are column-parallel and down is row-parallel.

Source from the content-addressed store, hash-verified

28
29
30class MLPBlock(torch.nn.Module):
31 """Llama-style MLP: gate/up are column-parallel and down is row-parallel."""
32
33 def __init__(self):
34 super().__init__()
35 self.gate_proj = torch.nn.Linear(HIDDEN_DIM, INTERMEDIATE_DIM, bias=False)
36 self.up_proj = torch.nn.Linear(HIDDEN_DIM, INTERMEDIATE_DIM, bias=False)
37 self.down_proj = torch.nn.Linear(INTERMEDIATE_DIM, HIDDEN_DIM, bias=False)
38
39 def forward(self, x):
40 # The residual is what makes this block interesting for the pass: x feeds the two
41 # column-parallel matmuls and the addition, and only the matmuls may be routed through the
42 # backward all-reduce. Reducing the residual gradient too would scale it by the TP size.
43 return x + self.down_proj(torch.nn.functional.silu(self.gate_proj(x)) * self.up_proj(x))
44
45
46class MLPModel(torch.nn.Module):

Callers 3

__init__Method · 0.70
__init__Method · 0.70
__init__Method · 0.70

Calls

no outgoing calls

Tested by 3

__init__Method · 0.56
__init__Method · 0.56
__init__Method · 0.56