File size: 4,842 Bytes
47f584a
48441eb
 
 
 
47f584a
 
 
48441eb
 
 
 
 
 
 
 
 
32eebab
48441eb
 
 
 
 
 
 
47f584a
 
48441eb
 
c59e329
 
 
48441eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
title: Solstice 80M WebGPU
emoji: ☀️
colorFrom: yellow
colorTo: indigo
sdk: static
pinned: false
license: apache-2.0
short_description: Solstice 80M and Nyx 36M pixel-art sprites in WebGPU
models:
- ThalisAI/solstice-80m
- Bhoidy/nyx-image-36m
- google/t5gemma-2b-2b-ul2
- google/siglip-base-patch16-224
custom_headers:
  cross-origin-embedder-policy: credentialless
  cross-origin-opener-policy: same-origin
  cross-origin-resource-policy: cross-origin
tags:
- text-to-image
- pixel-art
- webgpu
- onnx
- rectified-flow
- lora
---

# Solstice 80M · WebGPU

[![Model on HF](https://huggingface.co/datasets/huggingface/badges/resolve/main/model-on-hf-md.svg)](https://huggingface.co/ThalisAI/solstice-80m)
[![GitHub: comfyui-pixel-art-nodes](https://img.shields.io/badge/GitHub-comfyui--pixel--art--nodes-181717?logo=github)](https://github.com/thalismind/comfyui-pixel-art-nodes)

In-browser sprite generation with [ThalisAI/solstice-80m](https://huggingface.co/ThalisAI/solstice-80m) and
[Bhoidy/nyx-image-36m](https://huggingface.co/Bhoidy/nyx-image-36m), based on the
[Nyx Image 36M space](https://huggingface.co/spaces/Bhoidy/nyx-image-36m). Everything runs locally with ONNX Runtime Web:
WebGPU when the browser has it, WASM otherwise.

## Features

- **Models:** the Solstice r80-1202 teacher (30 Heun steps, CFG, self-conditioning) and its 20-, 10- and 5-step students;
  the retired s80-1201 teacher and students; Nyx-2 36M. fp32 runs on WebGPU or WASM, dynamic int8 on WASM.
- **Precomputed prompts:** Solstice's text encoder (T5Gemma-2b, 64 × 2304) is too large for a browser, so 672 prompts are
  encoded ahead of time for both models (`data/`): the model-card showcase prompts, subjects, attributes,
  attribute + subject pairs, arithmetic and sweep terms, direction phrase pairs and LoRA trigger prompts. Nyx can also encode
  free text live with the quantised SigLIP text tower.
- **Prompt sweep:** interpolate from prompt A to B per token (slerp on the positions both have, linear fade on the rest,
  slerp on the pool) with fixed noise per row, as in pixel-art-training `scripts/embed_sheets.py`.
- **Arithmetic:** word arithmetic A − B + C, and an *averaged direction* A + mean_k(E["C obj_k"] − E["B obj_k"]) over a group
  of objects (`scripts/embed_arith_avg.py`), with a strength control and an optional strength sweep.
- **LoRAs** (r80-1202): the six released LoRAs or any `.safetensors` LoRA file, several at once with per-LoRA strength.

## How LoRAs run

LoRAs are added to the published models at run time; nothing LoRA-specific is hosted. ONNX Runtime Web cannot change a
session's weights, so instead of merging, the page rewrites the downloaded fp32 export once, in the browser
(`js/onnxlora.js`, under a second for 285 MB): each of the 160 target linears (attention and MLP in all 20 blocks), found by
the exporter's `pkg.torch.onnx.name_scopes` metadata, gets a low-rank branch fed from 48 extra inputs
(`lora_<stack>_<layer>_A` `[blocks, in, R]` and `_B` `[blocks, R, out]`, R dynamic). The rewrite happens when the first LoRA
is switched on; after that, changing LoRAs or strengths only changes the inputs. The page stacks the chosen LoRAs along R with
`strength · alpha / rank` folded into B, and feeds R = 1 zeros when none is on. This works for the teacher and every
r80-1202 student.

`tools/add_lora_inputs.py` is the same rewrite in Python, for checking: its `--check` compares against numpy-merged weights
(within 2e-5 on the teacher and students), and the browser rewrite gives bit-identical outputs to it.

```sh
pip install onnx onnxruntime
python tools/add_lora_inputs.py teacher/fp32.onnx /tmp/teacher-lora.onnx --check ghost/lora.safetensors
```

## Rebuilding the prompt library

Edit `tools/prompts.py`, then re-encode (needs torch, transformers with T5Gemma, sentencepiece; ~5 min on a 16-core CPU):

```sh
python tools/build_embeddings.py                 # -> data/library.json, data/{solstice,nyx}.{json,bin}
```

Tokens are stored as per-token int8 with float16 scales (as Solstice's training text cache), pools as float16; only the
attended positions are kept.

## Layout

| Path | |
|---|---|
| `index.html`, `style.css` | the page |
| `js/app.js` | UI, model loading, the three modes |
| `js/models.js` | model registry (URLs, samplers, LoRA spec) |
| `js/sampler.js` | Euler / Heun, CFG on t ≤ 0.75, guidance input for students, self-conditioning |
| `js/embedmath.js` | slerp sweeps and arithmetic on `ndarray`s |
| `js/embeddings.js` | precomputed embedding store |
| `js/lora.js` | safetensors parsing and LoRA input feeds |
| `js/onnxlora.js` | adds LoRA inputs to a loaded ONNX export (protobuf rewrite) |
| `js/runtime.js` | ONNX Runtime Web sessions and cached downloads |
| `tools/` | prompt library, embedding builder, LoRA-input rewrite (Python, for checks) |