MCPcopy Create free account
hub / github.com/MiniMax-AI/VTP / Mlp

Class Mlp

vtp/models/layers/ffn.py:21–48  ·  view source on GitHub ↗

Standard MLP layer with optional dropout.

Source from the content-addressed store, hash-verified

19
20
21class Mlp(nn.Module, ListForwardMixin):
22 """Standard MLP layer with optional dropout."""
23
24 def __init__(
25 self,
26 in_features: int,
27 hidden_features: Optional[int] = None,
28 out_features: Optional[int] = None,
29 act_layer: Callable[..., nn.Module] = nn.GELU,
30 drop: float = 0.0,
31 bias: bool = True,
32 device=None,
33 ) -> None:
34 super().__init__()
35 out_features = out_features or in_features
36 hidden_features = hidden_features or in_features
37 self.fc1 = nn.Linear(in_features, hidden_features, bias=bias, device=device)
38 self.act = act_layer()
39 self.fc2 = nn.Linear(hidden_features, out_features, bias=bias, device=device)
40 self.drop = nn.Dropout(drop)
41
42 def forward(self, x: Tensor) -> Tensor:
43 x = self.fc1(x)
44 x = self.act(x)
45 x = self.drop(x)
46 x = self.fc2(x)
47 x = self.drop(x)
48 return x
49
50
51class SwiGLUFFN(nn.Module, ListForwardMixin):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected