Spaces:
Build error
Build error
Download src/models/block.py from HSinghHuggingFace/gpt-text-generator: direct link, hf CLI and curl.
- Browser
- Download file 468 Bytes
-
https://huggingface.co/spaces/HSinghHuggingFace/gpt-text-generator/resolve/main/src/models/block.py
- Command line
-
hf download hf://spaces/HSinghHuggingFace/gpt-text-generator/src/models/block.py
-
curl -L -o block.py https://huggingface.co/spaces/HSinghHuggingFace/gpt-text-generator/resolve/main/src/models/block.py
468 Bytes
| import torch.nn as nn | |
| from .attention import CausalSelfAttention | |
| from .mlp import MLP | |
| class Block(nn.Module): | |
| def __init__(self, config): | |
| super().__init__() | |
| self.ln_1 = nn.LayerNorm(config.n_embd) | |
| self.attn = CausalSelfAttention(config) | |
| self.ln_2 = nn.LayerNorm(config.n_embd) | |
| self.mlp = MLP(config) | |
| def forward(self, x): | |
| x = x + self.attn(self.ln_1(x)) | |
| x = x + self.mlp(self.ln_2(x)) | |
| return x |