Spaces:
Runtime error
Runtime error
Download ml/model/mlp.py from TheAbyss99/abyss-api: direct link, hf CLI and curl.
- Browser
- Download file 818 Bytes
-
https://huggingface.co/spaces/TheAbyss99/abyss-api/resolve/main/ml/model/mlp.py
- Command line
-
hf download hf://spaces/TheAbyss99/abyss-api/ml/model/mlp.py
-
curl -L -o mlp.py https://huggingface.co/spaces/TheAbyss99/abyss-api/resolve/main/ml/model/mlp.py
818 Bytes
| """ | |
| SwiGLU feed-forward network (Llama-style). | |
| Two parallel projections up to the hidden width: one is the 'gate', run | |
| through SiLU; the other is the 'value'. Their elementwise product is | |
| projected back down. SiLU(gate) * up acts like a learned, smooth filter. | |
| """ | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| class AbyssSwiGLU(nn.Module): | |
| def __init__(self, config): | |
| super().__init__() | |
| self.gate = nn.Linear(config.n_embd, config.n_inner, bias=config.bias) | |
| self.up = nn.Linear(config.n_embd, config.n_inner, bias=config.bias) | |
| self.down = nn.Linear(config.n_inner, config.n_embd, bias=config.bias) | |
| self.drop = nn.Dropout(config.dropout) | |
| def forward(self, x): | |
| return self.drop(self.down(F.silu(self.gate(x)) * self.up(x))) |