Spaces:
Runtime error
Runtime error
Download models/transformer/encode_decode/sublayer_connection.py from JingyuanLtd/LLM-fastAPI: direct link, hf CLI and curl.
- Browser
- Download file 597 Bytes
-
https://huggingface.co/spaces/JingyuanLtd/LLM-fastAPI/resolve/main/models/transformer/encode_decode/sublayer_connection.py
- Command line
-
hf download hf://spaces/JingyuanLtd/LLM-fastAPI/models/transformer/encode_decode/sublayer_connection.py
-
curl -L -o sublayer_connection.py https://huggingface.co/spaces/JingyuanLtd/LLM-fastAPI/resolve/main/models/transformer/encode_decode/sublayer_connection.py
597 Bytes
| import torch.nn as nn | |
| from models.transformer.encode_decode.layer_norm import LayerNorm | |
| class SublayerConnection(nn.Module): | |
| """ | |
| A residual connection followed by a layer norm. | |
| Note for code simplicity the norm is first as opposed to last. | |
| """ | |
| def __init__(self, size, dropout): | |
| super(SublayerConnection, self).__init__() | |
| self.norm = LayerNorm(size) | |
| self.dropout = nn.Dropout(dropout) | |
| def forward(self, x, sublayer): | |
| "Apply residual connection to any sublayer with the same size." | |
| return x + self.dropout(sublayer(self.norm(x))) | |