Download SwiGLU.py from strectelite/PebbleGPT-320M: direct link, hf CLI and curl.
- Browser
- Download file 585 Bytes
-
https://huggingface.co/strectelite/PebbleGPT-320M/resolve/main/SwiGLU.py
- Command line
-
hf download hf://strectelite/PebbleGPT-320M/SwiGLU.py
-
curl -L -o SwiGLU.py https://huggingface.co/strectelite/PebbleGPT-320M/resolve/main/SwiGLU.py
585 Bytes
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| class SwiGLU(nn.Module): | |
| def __init__(self, hidden_size: int = 1024, intermediate_size: int = 2816): | |
| super().__init__() | |
| self.gate = nn.Linear(hidden_size, intermediate_size, bias=False) | |
| self.content = nn.Linear(hidden_size, intermediate_size, bias=False) | |
| self.swish = F.silu | |
| self.down = nn.Linear(intermediate_size, hidden_size, bias=False) | |
| def forward(self, x: torch.Tensor) -> torch.Tensor: | |
| return self.down(self.swish(self.gate(x)) * self.content(x)) | |