--- license: mit pipeline_tag: text-to-image library_name: pytorch tags: - pixel-art - text-to-image - sprites - game-assets - 16x16 - masked-diffusion - discrete-diffusion ---

smalt

# smalt · tiny text-to-pixel-art Made for **[nemini.ai](https://nemini.ai)** & **[pixilab.ai](https://pixilab.ai)**. Every letter of the logo above, and the slime, was drawn by the model itself (`text gold letter s`, …, `purple slime monster`). ![smalt sprites](assets/hero.png) **smalt** draws **16×16 game sprites from a short prompt**: potions, chests, swords, keys, monsters, tiles, letters. Type `red health potion`, get a clean, transparent, palette-exact sprite you can drop straight into a game. | | | |---|---| | **Parameters** | 24.5M | | **Output** | 16×16 RGBA, every pixel one colour of a fixed 512-colour palette (index 0 = transparent) | | **Speed** | ~0.12 s for 4 sprites on a GPU · ~1.2 s for one sprite on 2 CPU threads | | **Dependencies** | `torch`, `tokenizers`, `safetensors`, `numpy`, `pillow` (no CLIP, no VAE) | | **License** | MIT (weights and code) | Try it in the browser: **[smalt studio](https://huggingface.co/spaces/PixilabAI/smalt-studio)**. ## How it works Every pixel is a token from a 512-colour palette. The model starts from a fully masked 16×16 canvas and fills it in **in parallel, in about 16 steps**: at each step it predicts a colour for every empty pixel and keeps the ones it is most sure about. The prompt is read by its own small text encoder, trained together with the image model. Because the output is palette indices, sprites come out pixel-perfect: hard edges, no blur, no stray anti-aliasing, true transparency. The same loop does **inpainting**: lock some pixels, and the model fills the rest around them. ## Quickstart ```bash pip install torch tokenizers safetensors numpy pillow huggingface_hub ``` ```python import sys from huggingface_hub import snapshot_download path = snapshot_download("PixilabAI/smalt-small") sys.path.insert(0, path) # the repo ships the small `smalt` package from smalt import SmaltPipeline pipe = SmaltPipeline(path) # cuda if available, else cpu sprites = pipe("red health potion", n=4, seed=0) # 4 × 16×16 RGBA PIL images for i, s in enumerate(sprites): s.resize((128, 128), 0).save(f"potion_{i}.png") # 0 = nearest neighbour, keeps pixels crisp ``` Several prompts in one batch: `pipe(["red key", "silver sword", "treasure chest"])`. **Settings** (keyword arguments): | | default | what it does | |---|---|---| | `steps` | 16 | decoding steps; 8 is faster, 24–32 a little cleaner | | `guidance` | 3.0 | how strictly the prompt is followed; 2–5 is the useful range | | `temperature` | 0.4 | lower = cleaner and more typical, higher = more variety (above ~1.0 adds stray pixels) | | `seed` | random | same seed + same settings = same sprites | **Inpainting**: pass a canvas of palette ids and a mask of the pixels to keep. ```python import numpy as np tok = pipe.tokens("blue mana potion", n=1, seed=3) # (1, 256) palette ids keep = np.zeros(256, bool); keep[128:] = True # keep the bottom half new = pipe("red health potion", n=4, canvas=tok[0].cpu().numpy(), keep=keep) ``` **Live steps**: `pipe.stream(prompt, n=4)` yields the canvas after every step (`step.tokens`, `step.preview`, `step.confidence`), handy for animations. ## Prompting Short prompts work best: **colour or material first, then the thing**. Two to six words. ![prompt examples](assets/prompts.png) - **Objects, creatures, characters**: just name them: `red health potion`, `silver sword`, `purple slime monster`, `knight in silver armor`, `yellow bat`. - **Tiles**: start with `tile with`: `tile with stone bricks`, `tile with blue water`, `tile with green grass`. - **Effects**: start with `effect`: `effect orange fireball`, `effect blue magic sparkle`. - **Interface pieces**: start with `ui`: `ui wooden button`. - **Letters**: start with `text`: `text gold letter a` (digits are less reliable). ## Limitations - 16×16 only. It is a sprite model, not a scene or portrait model. - Some subjects are weak or get mixed up: `pine tree` tends to draw a blue crystal, `ghost` can come out as a black bomb, `crown` and `gold coin` often turn into gold chests, a bare `heart` gives pink squares (`red heart` works). - Effects and interface pieces (health bars, explosions) are rough compared to objects. - Characters described by their clothes can drift to the object they resemble (`wizard with a blue robe` may draw a blue potion). Naming the creature first helps. - English prompts only. Trained from scratch on openly licensed pixel art; no outputs of other image generators were used. ## License MIT, see [LICENSE](LICENSE). Sprites you generate are yours to use, including commercially. Inspiration: [thejagstudio/tessera-small](https://huggingface.co/thejagstudio/tessera-small).