Add README.md
Browse files
README.md
CHANGED
|
@@ -1,109 +1,102 @@
|
|
| 1 |
---
|
| 2 |
-
license:
|
| 3 |
-
library_name: pytorch
|
| 4 |
pipeline_tag: text-to-image
|
|
|
|
| 5 |
datasets:
|
| 6 |
-
- Angais/pixel-art-atlas-1.4m
|
| 7 |
tags:
|
| 8 |
-
- pixel-art
|
| 9 |
-
- text-to-image
|
| 10 |
-
- masked-diffusion
|
| 11 |
-
- discrete-diffusion
|
| 12 |
-
- diffusion-
|
|
|
|
| 13 |
---
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
**
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
## Model
|
| 30 |
|
| 31 |
| | |
|
| 32 |
|---|---|
|
| 33 |
-
| Parameters | 47,597,568 (
|
| 34 |
-
| Architecture | joint text+pixel bidirectional transformer, hourglass 2 + 8 + 2 blocks (2×2 patch-merged core), width 512, 8 heads, QK-RMSNorm, 2D axial RoPE
|
| 35 |
-
| Text encoder | frozen `openai/clip-vit-base-patch32` text tower, 24 tokens
|
| 36 |
-
| Vocabulary | 512 palette tokens (frequency-weighted OKLab k-means
|
| 37 |
-
| Objective | absorbing-state masked diffusion, cosine
|
| 38 |
-
| Sampler | parallel confidence-ordered unmasking with CFG, Gumbel-annealed choice
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
**
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
| 55 |
-
|
|
| 56 |
-
|
|
| 57 |
-
|
|
| 58 |
-
| CLIP score (ViT-B/32) | 0.23 generated vs 0.26 real sprites |
|
| 59 |
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
-
## Usage
|
| 63 |
|
| 64 |
```python
|
| 65 |
from huggingface_hub import hf_hub_download
|
| 66 |
-
from trout import
|
| 67 |
-
|
| 68 |
-
ckpt = hf_hub_download("FrameXlabs/Trout", "trout-fp16.pt")
|
| 69 |
-
model, palette, meta = load_model_from_checkpoint(ckpt, device="cpu")
|
| 70 |
-
enc = FrozenTextEncoder(meta["text_encoder"], model.cfg.text_len, "cpu")
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
images
|
| 76 |
-
make_grid(images, ncols=4).save("crowns.png") # or try the live demo Space
|
| 77 |
```
|
| 78 |
|
|
|
|
|
|
|
| 79 |
## Files
|
| 80 |
|
| 81 |
| File | Contents |
|
| 82 |
|---|---|
|
| 83 |
-
| `trout-fp16.pt` |
|
| 84 |
-
| `
|
| 85 |
-
| `
|
| 86 |
-
| `metrics.jsonl` | full training
|
| 87 |
-
| `showcase.png` | sample grid (16 prompts ×
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
- **
|
| 95 |
-
-
|
| 96 |
-
-
|
| 97 |
-
- Chang et al., *MaskGIT: Masked Generative Image Transformer*, CVPR 2022 (arXiv:2202.04200).
|
| 98 |
-
- Blecher et al., *Nougat* hourglass transformer (arXiv:2308.13418).
|
| 99 |
-
- Peebles & Xie, *DiT* adaLN (arXiv:2212.09748); PixArt-α adaLN-single.
|
| 100 |
-
- Darcet et al., *Vision Transformers Need Registers*, ICLR 2024.
|
| 101 |
-
- Chen, *Analog Bits* self-conditioning (arXiv:2208.04202).
|
| 102 |
-
- Jordan et al., *Muon* (arXiv:2502.16982); Moonshot, *Muon is Scalable* (arXiv:2508.02535).
|
| 103 |
-
- Ottosson, *OKLab* perceptual color space (2020).
|
| 104 |
|
| 105 |
## License
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: cc-by-nc-4.0
|
|
|
|
| 3 |
pipeline_tag: text-to-image
|
| 4 |
+
library_name: pytorch
|
| 5 |
datasets:
|
| 6 |
+
- Angais/pixel-art-atlas-1.4m
|
| 7 |
tags:
|
| 8 |
+
- pixel-art
|
| 9 |
+
- text-to-image
|
| 10 |
+
- masked-diffusion
|
| 11 |
+
- discrete-diffusion
|
| 12 |
+
- diffusion-llm
|
| 13 |
+
- from-scratch
|
| 14 |
---
|
| 15 |
+
# Trout: a from-scratch diffusion language model for 16×16 pixel art
|
| 16 |
+
|
| 17 |
+
**Author:** FrameXlabs
|
| 18 |
+
**Live demo:** [Trout Pixel Studio](https://huggingface.co/spaces/FrameXlabs/trout-pixel-studio)
|
| 19 |
+
**License:** [CC BY-NC 4.0](LICENSE) — free for education, research and personal non-commercial use with credit.
|
| 20 |
+
**Named after:** the trout, a small fish — small, real, and trained from scratch.
|
| 21 |
+
|
| 22 |
+
Trout is a from-scratch re-implementation of the same *kind* of model as
|
| 23 |
+
[Tessera-small](https://huggingface.co/thejagstudio/tessera-small) (TheJagStudio) with the
|
| 24 |
+
**same parameter count (47.6M)**: a joint text+pixel bidirectional masked-diffusion transformer
|
| 25 |
+
that treats a 16×16 sprite as a 256-token sentence over a learned 512-colour palette, conditioned
|
| 26 |
+
on a frozen CLIP text encoder. Nothing was copied from the reference — the palette is rebuilt from
|
| 27 |
+
the source data with our own frequency-weighted OKLab k-means, the weights are trained from random
|
| 28 |
+
initialisation with our own code, and the sampler is our own implementation of the same decoding
|
| 29 |
+
strategy (parallel confidence-ordered unmasking with CFG, Gumbel-annealed choice and spatial NMS).
|
| 30 |
|
| 31 |
## Model
|
| 32 |
|
| 33 |
| | |
|
| 34 |
|---|---|
|
| 35 |
+
| Parameters | 47.6M (47,597,568) (Trout-small) — frozen CLIP text tower not included (MIT licensed) |
|
| 36 |
+
| Architecture | joint text+pixel bidirectional transformer, hourglass 2 + 8 + 2 blocks (2×2 patch-merged core), width 512, 8 heads, QK-RMSNorm, 2D axial RoPE, Conv-SwiGLU, adaLN-single, 4 registers, self-conditioning |
|
| 37 |
+
| Text encoder | frozen `openai/clip-vit-base-patch32` text tower, 24 tokens |
|
| 38 |
+
| Vocabulary | 512 palette tokens (frequency-weighted OKLab k-means on the data, ΔE 0.010 mean quantisation error) + `<mask>` |
|
| 39 |
+
| Objective | absorbing-state masked diffusion, cosine schedule, blob masks, perceptual (OKLab) label smoothing, CFG dropout, self-conditioning |
|
| 40 |
+
| Sampler | parallel confidence-ordered unmasking with CFG, Gumbel-annealed choice, spatial NMS; inpainting supported |
|
| 41 |
+
|
| 42 |
+
## Training (honest numbers)
|
| 43 |
+
|
| 44 |
+
Trout was trained **from scratch** on
|
| 45 |
+
[Pixel Art Atlas 1.4M](https://huggingface.co/datasets/Angais/pixel-art-atlas-1.4m) (5 of 15 train
|
| 46 |
+
shards, 16-sprite batches, 1000 optimizer steps ≈ 16,000 sprites seen)
|
| 47 |
+
on a shared **CPU** sandbox — roughly 0.04% of the compute of the reference recipe
|
| 48 |
+
(82,342 steps × 512 sprites on an RTX PRO 6000). The optimizer is AdamW (the reference used
|
| 49 |
+
Muon+AdamW) with warmup + cosine decay, EMA 0.99. It is a real training run, but a
|
| 50 |
+
very short one, so the model is intentionally undertrained: expect plausible palettes, silhouettes
|
| 51 |
+
and colour blobs rather than crisp objects. Increase sampling steps / CFG scale for the best of
|
| 52 |
+
what it has learned.
|
| 53 |
+
|
| 54 |
+
| Metric (final checkpoint) | Value |
|
| 55 |
+
|---|---|
|
| 56 |
+
| Validation NLL | 2.673 nats / pixel (perplexity 14.49 of 512) |
|
| 57 |
+
| Validation accuracy | 48.8% of masked pixels |
|
| 58 |
+
| Palette quantisation | mean ΔE 0.010, p95 ΔE 0.025 |
|
| 59 |
+
| Trainable parameters | 47,597,568 |
|
|
|
|
| 60 |
|
| 61 |
+
(For scale: Tessera-small reports validation NLL 0.859 nats/pixel and 78.8% masked-pixel accuracy
|
| 62 |
+
after its full 82,342-step run.)
|
| 63 |
|
| 64 |
+
## Usage (non-commercial)
|
| 65 |
|
| 66 |
```python
|
| 67 |
from huggingface_hub import hf_hub_download
|
| 68 |
+
from trout.pipeline import TroutPipeline # code in this repo's `trout/` folder
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
ckpt = hf_hub_download("FrameXlabs/Trout", "trout-small-fp16.pt")
|
| 71 |
+
pipe = TroutPipeline.from_checkpoint(ckpt, device="cpu")
|
| 72 |
+
images = pipe(["red health potion bottle"], num_per_prompt=8, steps=16, cfg_scale=3.0, seed=0)
|
| 73 |
+
pipe.grid(images).save("potions.png")
|
|
|
|
| 74 |
```
|
| 75 |
|
| 76 |
+
Or try it live (the model runs in the Space): **[Trout Pixel Studio](https://huggingface.co/spaces/FrameXlabs/trout-pixel-studio)**.
|
| 77 |
+
|
| 78 |
## Files
|
| 79 |
|
| 80 |
| File | Contents |
|
| 81 |
|---|---|
|
| 82 |
+
| `trout-small-fp16.pt` | fp16 weights, model config, palette, text-encoder id, training step |
|
| 83 |
+
| `model_config.json`, `train_config.json` | architecture and training hyper-parameters actually used |
|
| 84 |
+
| `palette.json` | the 512-entry palette learned from the dataset |
|
| 85 |
+
| `metrics.jsonl` | the full training + validation log |
|
| 86 |
+
| `showcase.png` | sample grid (16 prompts × 8 samples) |
|
| 87 |
+
| `trout/` | inference code (model, sampler, palette, pipeline, CLIP wrapper) |
|
| 88 |
+
|
| 89 |
+
## Credits
|
| 90 |
+
|
| 91 |
+
- **[Angais](https://huggingface.co/Angais)** for creating and openly releasing
|
| 92 |
+
[Pixel Art Atlas 1.4M](https://huggingface.co/datasets/Angais/pixel-art-atlas-1.4m) — Trout was trained on it.
|
| 93 |
+
- **[Jagrat Patel (TheJagStudio)](https://huggingface.co/thejagstudio)** — Tessera-small inspired this
|
| 94 |
+
from-scratch build and defines the model family Trout reimplements at the same size.
|
| 95 |
+
- The frozen text encoder is OpenAI's CLIP ViT-B/32 text tower (MIT).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
## License
|
| 98 |
|
| 99 |
+
Trout is released under **[CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/)**. Free for
|
| 100 |
+
education, research and personal non-commercial use with credit ("Trout by FrameXlabs").
|
| 101 |
+
Commercial use requires a separate license. Third-party parts keep their own licenses: the CLIP text
|
| 102 |
+
encoder (OpenAI, MIT) and the Pixel Art Atlas 1.4M dataset (Angais).
|