Instructions to use OpCustom/OpAI1.1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Adapters
How to use OpCustom/OpAI1.1 with Adapters:
from adapters import AutoAdapterModel model = AutoAdapterModel.from_pretrained("<base-model-id>") model.load_adapter("OpCustom/OpAI1.1", set_active=True) - Notebooks
- Google Colab
- Kaggle
Download transformer_block.py from OpCustom/OpAI1.1: direct link, hf CLI and curl.
- Browser
- Download file 878 Bytes
-
https://huggingface.co/OpCustom/OpAI1.1/resolve/main/transformer_block.py
- Command line
-
hf download hf://OpCustom/OpAI1.1/transformer_block.py
-
curl -L -o transformer_block.py https://huggingface.co/OpCustom/OpAI1.1/resolve/main/transformer_block.py
878 Bytes
| import torch | |
| import torch.nn as nn | |
| from multi_head_attention import MultiHeadAttention # Add this import | |
| from feedforward import FeedForward | |
| class TransformerBlock(nn.Module): | |
| def __init__(self, d_model, n_heads, ff_dim): | |
| super(TransformerBlock, self).__init__() | |
| self.attention = MultiHeadAttention(d_model, n_heads) | |
| self.ffn = FeedForward(d_model, ff_dim) | |
| self.norm1 = nn.LayerNorm(d_model) | |
| self.norm2 = nn.LayerNorm(d_model) | |
| self.dropout1 = nn.Dropout(0.1) | |
| self.dropout2 = nn.Dropout(0.1) | |
| def forward(self, x, mask=None): | |
| # Multi-head attention | |
| attn_out = self.attention(x, x, x, mask) | |
| x = self.norm1(x + self.dropout1(attn_out)) | |
| # Feedforward network | |
| ff_out = self.ffn(x) | |
| x = self.norm2(x + self.dropout2(ff_out)) | |
| return x | |