mirror of https://github.com/hpcaitech/ColossalAI
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
557 B
20 lines
557 B
import torch
|
|
import colossalai
|
|
import colossalai.nn as col_nn
|
|
|
|
class MLP(torch.nn.Module):
|
|
def __init__(self, dim: int = 256):
|
|
super().__init__()
|
|
intermediate_dim = dim * 4
|
|
self.dense_1 = col_nn.Linear(dim, intermediate_dim)
|
|
self.activation = torch.nn.GELU()
|
|
self.dense_2 = col_nn.Linear(intermediate_dim, dim)
|
|
self.dropout = col_nn.Dropout(0.1)
|
|
|
|
def forward(self, x):
|
|
x = self.dense_1(x)
|
|
x = self.activation(x)
|
|
x = self.dense_2(x)
|
|
x = self.dropout(x)
|
|
return x
|