Instructions to use TopAI-1/Pixel-1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TopAI-1/Pixel-1 with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("TopAI-1/Pixel-1", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
| import torch | |
| import torch.nn as nn | |
| from transformers import PreTrainedModel | |
| from .configuration_pixel import TopAIImageConfig | |
| class ResidualBlock(nn.Module): | |
| def __init__(self, channels): | |
| super().__init__() | |
| self.block = nn.Sequential( | |
| nn.Conv2d(channels, channels, kernel_size=3, padding=1, bias=False), | |
| nn.BatchNorm2d(channels), | |
| nn.ReLU(True), | |
| nn.Conv2d(channels, channels, kernel_size=3, padding=1, bias=False), | |
| nn.BatchNorm2d(channels) | |
| ) | |
| def forward(self, x): | |
| return x + self.block(x) | |
| class TopAIImageGenerator(PreTrainedModel): | |
| config_class = TopAIImageConfig | |
| # ืชืืงืื ื-AttributeError: ืืืื ืืืืืช ืืืืื (dict) ืืื ืฉืชืืื ืื ืืชืืื .keys() | |
| all_tied_weights_keys = {} | |
| def __init__(self, config): | |
| super().__init__(config) | |
| # ืฉืืืืฉ ื-hidden_dim ืืืงืื ืคืื (512) | |
| h = config.hidden_dim | |
| self.text_projection = nn.Linear(config.input_dim, 4 * 4 * h) | |
| # ืื ืืื ืืื ืืืช ืฉืืชืืืื ืืืืืง ืืืฉืงืืืืช ื-Safetensors | |
| self.decoder = nn.Sequential( | |
| # ืฉืืื 0: ื-512 ื-512 (ืืื ืืื ื-Mismatch) | |
| self._upsample(h, h), | |
| # ืฉืืื 1 | |
| ResidualBlock(h), | |
| # ืฉืืื 2: ื-512 ื-256 | |
| self._upsample(h, 256), | |
| # ืฉืืื 3 | |
| ResidualBlock(256), | |
| # ืฉืืื 4: ื-256 ื-128 | |
| self._upsample(256, 128), | |
| # ืฉืืื 5: ื-128 ื-64 | |
| self._upsample(128, 64), | |
| # ืฉืืื 6: ืืืขืืจ ืืกืืคื ื-32 ืคืืืืจืื | |
| nn.ConvTranspose2d(64, 32, 4, 2, 1, bias=False), | |
| nn.BatchNorm2d(32), | |
| nn.ReLU(True), | |
| # ืฉืืื 9: ืืืจื ืืขืจืืฆื ืชืืื ื (RGB) | |
| nn.Conv2d(32, config.image_channels, kernel_size=3, padding=1), | |
| nn.Tanh() | |
| ) | |
| def _upsample(self, i, o): | |
| return nn.Sequential( | |
| nn.ConvTranspose2d(i, o, 4, 2, 1, bias=False), | |
| nn.BatchNorm2d(o), | |
| nn.ReLU(True) | |
| ) | |
| def forward(self, text_embeddings): | |
| # ืฉืื ืื ืฆืืจื ืืืคืช ืืืคืืื ืื ืจืืฉืื ืืช | |
| x = self.text_projection(text_embeddings) | |
| x = x.view(-1, self.config.hidden_dim, 4, 4) | |
| return self.decoder(x) |