Spaces:
Runtime error
Runtime error
Download ml/model/block.py from TheAbyss99/abyss-api: direct link, hf CLI and curl.
- Browser
- Download file 868 Bytes
-
https://huggingface.co/spaces/TheAbyss99/abyss-api/resolve/main/ml/model/block.py
- Command line
-
hf download hf://spaces/TheAbyss99/abyss-api/ml/model/block.py
-
curl -L -o block.py https://huggingface.co/spaces/TheAbyss99/abyss-api/resolve/main/ml/model/block.py
868 Bytes
| """ | |
| One transformer block: a pre-norm residual around attention, then another | |
| around the SwiGLU MLP | |
| x = x + attn(norm1(x)) | |
| x = x + mlp(norm2(x)) | |
| Pre-norm (norm before each sublayer) keeps a clean residual highway, which | |
| lets deep stacks train stably. | |
| """ | |
| import torch.nn as nn | |
| from .norm import AbyssRMSNorm | |
| from .attention import AbyssCausalSelfAttention | |
| from .mlp import AbyssSwiGLU | |
| class AbyssBlock(nn.Module): | |
| def __init__(self, config): | |
| super().__init__() | |
| self.norm1 = AbyssRMSNorm(config.n_embd, config.norm_eps) | |
| self.attn = AbyssCausalSelfAttention(config) | |
| self.norm2 = AbyssRMSNorm(config.n_embd, config.norm_eps) | |
| self.mlp = AbyssSwiGLU(config) | |
| def forward(self, x): | |
| x = x + self.attn(self.norm1(x)) | |
| x = x + self.mlp(self.norm2(x)) | |
| return x |