okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge main 7726f80cb (local, 11-10 14:08) into f-own-int714ff8242

main
6.2 KiB118 linesraw

Image generation (Qwen-Image-2.1-Turbo)

This page is for people who want Strata's server to make images through POST /v1/images/generations, OpenAI's images API. It is optional, off unless you ask for it, and separate from reading pictures in chat (for that, use strata launch --vision on with a supported model and reader).

It needs a source checkout and build tools. The steps below are not part of a normal app install.

The model is Qwen-Image-2.1-Turbo (8 steps, CFG 1) in Unsloth's GGUF quants, run by stable-diffusion.cpp (sd-cli), which setup compiles for your GPU. It is under the Qwen Research License, not Apache 2.0. Read its license before you use the images commercially.

Quick start

./setup.sh --setup --images qwen-image          # Linux
START-HERE.bat --setup --images qwen-image      # Windows

For an install that is already set up, without running the whole setup again:

.venv/bin/python tools/image/install.py --config strata-<model>.json

Then request an image:

curl http://127.0.0.1:8080/v1/images/generations -H "Content-Type: application/json" \
  -d '{"prompt": "a cartoon sloth mascot waving, flat vector illustration", "size": "1024x1024", "seed": 42}'

What setup does

Setup compiles sd-cli (stable-diffusion.cpp at a pinned commit) into engine-image/, downloads three files into the data folder's models/qwen-image-2.1-turbo/, checks each against its SHA-256 and writes an "images" section into the model's run config.

PieceFileSize
Denoiser, chosen by GPU memoryqwen-image-2.1-turbo-Q4_K_M.gguf up to 8 GB, Q6_K up to 12 GB, Q8_0 above4.2 / 6.3 / 7.6 GB
Text encoderQwen3-VL-8B-Instruct-UD-Q4_K_XL.gguf5.1 GB
VAEqwen_image_2.1_vae_bf16.safetensors0.7 GB

Setup options

OptionEffect
--image-quant Q4_K_M|Q6_K|Q8_0Picks the denoiser. A bigger one than recommended is kept, with a warning.
--image-backend cuda|hip|vulkan|cpuPicks the backend.
--image-gpu-policy auto|keep|shrink|unloadSets images.gpu_policy (below).
--images noTakes the section out of the config.

Backends

BackendUsed for
CUDANVIDIA. Needs the CUDA Toolkit.
HIPAMD cards with their own memory, on Linux, with the same ROCm as the engine.
VulkanAMD APUs and iGPUs (Radeon 780M, Strix Point and Halo), Intel Arc, and AMD under Windows.
CPUFallback.

A Linux PC without the Vulkan development files gets the LunarG Vulkan SDK unpacked into third_party/ (no sudo). On Windows, install the Vulkan SDK first. On Vulkan, setup adds --vae-tiling --vae-tile-overlap 0.25. An untiled 1024x1024 VAE decode on a Radeon 780M is one GPU job long enough to trip the kernel driver's job timeout, and the quarter overlap decodes in half the time of sd.cpp's default half overlap.

Request fields

FieldMeaning
promptThe description (required).
sizeWIDTHxHEIGHT, each side a multiple of 32 from 256 to 2048 (max_side). Default and auto: 1024x1024.
nImages, 1 to 4 (max_n). Image i uses seed + i.
response_formatb64_json (default) or url (/v1/images/files/<random name>.png; the server keeps the newest 64).
seedStrata's: a whole number for a repeatable image. Default: random; the answer says which.
stepsStrata's: 8 (Turbo's schedule). Another count uses stable-diffusion.cpp's own schedule, which Turbo was not made for.
backgroundauto (default) or opaque: the picture on white, as an 8-bit RGB PNG. transparent: the model's own transparency kept (an RGBA PNG).

The answer has OpenAI's shape (created, data[].b64_json or data[].url, revised_prompt = the prompt, background) plus data[].seed and a strata object with the seconds, steps, backend and flatten_s (the time spent putting the picture on white). The settings are the model card's for stable-diffusion.cpp: 8 steps, CFG 1, euler, Turbo's own sigmas, --diffusion-fa. The model can leave parts of a picture transparent; the API puts the picture on white and returns an 8-bit RGB PNG, with the PNG's text chunk (prompt and settings) unchanged. With "background": "transparent" you get the PNG exactly as plain sd-cli writes it, transparent areas included.

Sharing the GPU with the text model

One job runs at a time. An image job takes the same turn a chat request takes, so a chat request waits for the image and the other way round. The config's images.gpu_policy decides what the text model does meanwhile.

PolicyThe text model during an image job
auto (default)keep when the image job fits next to it (an APU always), else shrink when the engine was started with --vram-elastic, else unload.
keepStays loaded and idle.
shrinkGives VRAM from its expert cache (as POST /v1/vram) and takes it back afterwards. The conversation stays.
unloadIts conversation is saved to a file and the engine is stopped. The next start restores the conversation. "reload": "eager" starts it again right after the image; the default lazy starts it with the next chat request.

Each image runs its own sd-cli process, so no image memory stays on the GPU between images. Loading the three files takes a few seconds per image from the page cache.

History / older measurements

Measured on: seconds per image through the API, Q8_0, 8 steps, one sd-cli process per image with loading included. Strata version not recorded.

GPUBackend1024x1024512x512
RTX A4000 16 GBCUDA27 s8.8 s
Radeon 780M (iGPU)HIP131 s29 s
Radeon 780M (iGPU)Vulkan179 s43 s

On the 780M, HIP is faster but runs through the ROCm path whose queue evictions reset this GPU on the firmware tested (a driver or firmware defect, not this feature; no reset was seen in these image runs). Vulkan is setup's default there. --image-backend hip picks HIP.

1# Image generation (Qwen-Image-2.1-Turbo)
2
3This page is for people who want Strata's server to make images through `POST /v1/images/generations`, OpenAI's
4images API. It is optional, off unless you ask for it, and separate from reading pictures in chat (for that, use
5`strata launch --vision on` with a supported model and reader).
6
7It needs a [source checkout](SOURCE_INSTALL.md) and build tools. The steps below are not part of a normal app install.
8
9The model is [Qwen-Image-2.1-Turbo](https://huggingface.co/Qwen/Qwen-Image-2.1-Turbo) (8 steps, CFG 1) in
10[Unsloth's GGUF quants](https://huggingface.co/unsloth/Qwen-Image-2.1-Turbo-GGUF), run by
11[stable-diffusion.cpp](https://github.com/leejet/stable-diffusion.cpp) (`sd-cli`), which setup compiles for your GPU.
12It is under the **Qwen Research License**, not Apache 2.0. Read
13[its license](https://huggingface.co/Qwen/Qwen-Image-2.1-Turbo/blob/main/LICENSE) before you use the images
14commercially.
15
16## Quick start
17
18```sh
19./setup.sh --setup --images qwen-image          # Linux
20START-HERE.bat --setup --images qwen-image      # Windows
21```
22
23For an install that is already set up, without running the whole setup again:
24
25```sh
26.venv/bin/python tools/image/install.py --config strata-<model>.json
27```
28
29Then request an image:
30
31```sh
32curl http://127.0.0.1:8080/v1/images/generations -H "Content-Type: application/json" \
33  -d '{"prompt": "a cartoon sloth mascot waving, flat vector illustration", "size": "1024x1024", "seed": 42}'
34```
35
36## What setup does
37
38Setup compiles `sd-cli` (stable-diffusion.cpp at a pinned commit) into `engine-image/`, downloads three files into the
39data folder's `models/qwen-image-2.1-turbo/`, checks each against its SHA-256 and writes an `"images"` section into the
40model's run config.
41
42| Piece | File | Size |
43| --- | --- | --- |
44| Denoiser, chosen by GPU memory | `qwen-image-2.1-turbo-Q4_K_M.gguf` up to 8 GB, `Q6_K` up to 12 GB, `Q8_0` above | 4.2 / 6.3 / 7.6 GB |
45| Text encoder | `Qwen3-VL-8B-Instruct-UD-Q4_K_XL.gguf` | 5.1 GB |
46| VAE | `qwen_image_2.1_vae_bf16.safetensors` | 0.7 GB |
47
48### Setup options
49
50| Option | Effect |
51| --- | --- |
52| `--image-quant Q4_K_M\|Q6_K\|Q8_0` | Picks the denoiser. A bigger one than recommended is kept, with a warning. |
53| `--image-backend cuda\|hip\|vulkan\|cpu` | Picks the backend. |
54| `--image-gpu-policy auto\|keep\|shrink\|unload` | Sets `images.gpu_policy` ([below](#sharing-the-gpu-with-the-text-model)). |
55| `--images no` | Takes the section out of the config. |
56
57### Backends
58
59| Backend | Used for |
60| --- | --- |
61| CUDA | NVIDIA. Needs the CUDA Toolkit. |
62| HIP | AMD cards with their own memory, on Linux, with the same ROCm as the engine. |
63| Vulkan | AMD APUs and iGPUs (Radeon 780M, Strix Point and Halo), Intel Arc, and AMD under Windows. |
64| CPU | Fallback. |
65
66A Linux PC without the Vulkan development files gets the LunarG Vulkan SDK unpacked into `third_party/` (no sudo). On
67Windows, install the Vulkan SDK first. On Vulkan, setup adds `--vae-tiling --vae-tile-overlap 0.25`. An untiled
681024x1024 VAE decode on a Radeon 780M is one GPU job long enough to trip the kernel driver's job timeout, and the
69quarter overlap decodes in half the time of sd.cpp's default half overlap.
70
71## Request fields
72
73| Field | Meaning |
74| --- | --- |
75| `prompt` | The description (required). |
76| `size` | `WIDTHxHEIGHT`, each side a multiple of 32 from 256 to 2048 (`max_side`). Default and `auto`: `1024x1024`. |
77| `n` | Images, 1 to 4 (`max_n`). Image *i* uses seed + *i*. |
78| `response_format` | `b64_json` (default) or `url` (`/v1/images/files/<random name>.png`; the server keeps the newest 64). |
79| `seed` | Strata's: a whole number for a repeatable image. Default: random; the answer says which. |
80| `steps` | Strata's: 8 (Turbo's schedule). Another count uses stable-diffusion.cpp's own schedule, which Turbo was not made for. |
81| `background` | `auto` (default) or `opaque`: the picture on white, as an 8-bit RGB PNG. `transparent`: the model's own transparency kept (an RGBA PNG). |
82
83The answer has OpenAI's shape (`created`, `data[].b64_json` or `data[].url`, `revised_prompt` = the prompt,
84`background`) plus `data[].seed` and a `strata` object with the seconds, steps, backend and `flatten_s` (the time
85spent putting the picture on white). The settings are the model card's for stable-diffusion.cpp: 8 steps, CFG 1, euler,
86Turbo's own sigmas, `--diffusion-fa`. The model can leave parts of a picture transparent; the API puts the picture on
87white and returns an 8-bit RGB PNG, with the PNG's text chunk (prompt and settings) unchanged. With
88`"background": "transparent"` you get the PNG exactly as plain `sd-cli` writes it, transparent areas included.
89
90## Sharing the GPU with the text model
91
92One job runs at a time. An image job takes the same turn a chat request takes, so a chat request waits for the image
93and the other way round. The config's `images.gpu_policy` decides what the text model does meanwhile.
94
95| Policy | The text model during an image job |
96| --- | --- |
97| `auto` (default) | `keep` when the image job fits next to it (an APU always), else `shrink` when the engine was started with `--vram-elastic`, else `unload`. |
98| `keep` | Stays loaded and idle. |
99| `shrink` | Gives VRAM from its expert cache (as `POST /v1/vram`) and takes it back afterwards. The conversation stays. |
100| `unload` | Its conversation is saved to a file and the engine is stopped. The next start restores the conversation. `"reload": "eager"` starts it again right after the image; the default `lazy` starts it with the next chat request. |
101
102Each image runs its own `sd-cli` process, so no image memory stays on the GPU between images. Loading the three files
103takes a few seconds per image from the page cache.
104
105## History / older measurements
106
107> **Measured on:** seconds per image through the API, Q8_0, 8 steps, one `sd-cli` process per image with loading
108> included. Strata version not recorded.
109
110| GPU | Backend | 1024x1024 | 512x512 |
111| --- | --- | --- | --- |
112| RTX A4000 16 GB | CUDA | 27 s | 8.8 s |
113| Radeon 780M (iGPU) | HIP | 131 s | 29 s |
114| Radeon 780M (iGPU) | Vulkan | 179 s | 43 s |
115
116On the 780M, HIP is faster but runs through the ROCm path whose queue evictions reset this GPU on the firmware tested
117(a driver or firmware defect, not this feature; no reset was seen in these image runs). Vulkan is setup's default
118there. `--image-backend hip` picks HIP.