FrameXlabs commited on
Commit
207b90a
·
verified ·
1 Parent(s): fa05756

Add README.md

Browse files
Files changed (1) hide show
  1. README.md +77 -84
README.md CHANGED
@@ -1,109 +1,102 @@
1
  ---
2
- license: apache-2.0
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-lm
 
13
  ---
14
-
15
- # 🐟 Trout: a diffusion language model for 16×16 pixel art
16
-
17
- **Trout** is a 47.6M-parameter absorbing-state **masked diffusion** model that treats each
18
- 16×16 sprite as a 256-token "sentence" over a learned **512-color palette**
19
- (token 0 = transparent). A bidirectional hourglass transformer starts from a
20
- fully masked canvas and unmasks all 256 pixels **in parallel in about 16 steps**,
21
- conditioned on a frozen CLIP text encoder. No VAE, no latent space, no autoregression.
22
-
23
- Trout was **built and trained from scratch** (architecture after
24
- [Tessera-small](https://huggingface.co/thejagstudio/tessera-small) by Jagrat Patel
25
- (TheJagStudio), whose open model card and demo space document the design) on a
26
- 2-vCPU CPU-only sandbox. All numbers below are real and reproducible from
27
- `metrics.jsonl`.
 
28
 
29
  ## Model
30
 
31
  | | |
32
  |---|---|
33
- | Parameters | 47,597,568 (Tessera-small: 47.6M) |
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 (θ=100), Conv-SwiGLU, adaLN-single, 4 registers, self-conditioning, learned pos-emb |
35
- | Text encoder | frozen `openai/clip-vit-base-patch32` text tower, 24 tokens (not included, MIT) |
36
- | Vocabulary | 512 palette tokens (frequency-weighted OKLab k-means, mean ΔE 0.0099, snapped to dataset colors) + `<MASK>` |
37
- | Objective | absorbing-state masked diffusion, cosine mask schedule, stratified t, blob masks (25%), perceptual OKLab label smoothing (ε=0.1, τ=0.05), CFG dropout (10%), hflip aug |
38
- | Sampler | parallel confidence-ordered unmasking with CFG, Gumbel-annealed choice (T=2), spatial NMS (3×3, 0.9), self-conditioning feedback; inpainting supported |
39
- | Optimizer | Muon (batched Newton-Schulz, RMS-matched 0.2·√max(m,n)) on hidden matrices + AdamW elsewhere, Warmup-Stable-Decay, EMA |
40
-
41
- ## Training — and the honest compute gap
42
-
43
- Tessera-small was trained for **82,342 steps × 512 sprites** on an RTX PRO 6000
44
- (≈5.5 h). Trout was trained **from scratch on 2 vCPUs / 4 GB RAM** for
45
- **2,400 steps × 8 sprites** (~19k sprite-views of a 60k-sprite
46
- subset of the same dataset) in CPU fp32. The recipe (schedule, smoothing,
47
- self-conditioning, CFG dropout, Muon+AdamW, WSD, EMA) is followed faithfully;
48
- only the compute budget is smaller by ~4 orders of magnitude, so Trout's
49
- metrics are correspondingly weaker than Tessera's — this is a genuine
50
- budget-limited from-scratch run, not a distilled or fine-tuned copy.
51
-
52
- ## Metrics (exported weights)
53
-
54
- | Metric | Trout (this run) | Tessera-small (reference) |
55
- |---|---|---|
56
- | Validation NLL | 2.176 nats/pixel (perplexity 8.81 of 512) | 0.859 nats/pixel (2.36) |
57
- | Validation accuracy | 54.6% of masked pixels | 78.8% |
58
- | CLIP score (ViT-B/32) | 0.23 generated vs 0.26 real sprites |
59
 
60
- The full per-step log is in `metrics.jsonl`.
 
61
 
62
- ## Usage
63
 
64
  ```python
65
  from huggingface_hub import hf_hub_download
66
- from trout import load_model_from_checkpoint, FrozenTextEncoder, sample, tokens_to_images, make_grid
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
- states, pooled = enc.encode(["golden crown with blue gems"] * 4)
73
- toks = sample(model, states, pooled, steps=16, cfg_scale=3.0,
74
- generator=torch.Generator().manual_seed(0))
75
- images = tokens_to_images(toks, palette)
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` | exported weights (fp16; raw/EMA chosen by validation NLL), model config, palette, text-encoder id, step |
84
- | `trout.py` | single-file from-scratch implementation (model, palette, sampler, pipeline helpers) |
85
- | `model_config.json`, `train_config.json` | architecture + training hyperparameters |
86
- | `metrics.jsonl` | full training and validation log |
87
- | `showcase.png` | sample grid (16 prompts × 4 samples, steps=16, cfg=3.0) |
88
-
89
- ## Sources & credits (the knowledge this model is built on)
90
-
91
- - **Tessera-small** by Jagrat Patel ([TheJagStudio](https://huggingface.co/thejagstudio)) —
92
- the architecture this from-scratch reimplementation follows; its open model card and demo
93
- space were the design reference.
94
- - **Pixel Art Atlas 1.4M** by [Angais](https://huggingface.co/Angais) (CC0) — training data.
95
- - Sahoo et al., *Simple and Effective Masked Diffusion Language Models*, NeurIPS 2024 (arXiv:2406.07524).
96
- - Shi et al., *Simplified and Generalized Masked Diffusion for Discrete Data*, NeurIPS 2024 (arXiv:2406.04329).
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
- Apache-2.0 (Trout weights and code; trained on CC0 data; CLIP text tower keeps
108
- its own MIT license and is not redistributed here). Architecture credit to
109
- Tessera-small as noted above.
 
 
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).