mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-26 23:29:53 +00:00
282 lines
11 KiB
Markdown
282 lines
11 KiB
Markdown
# LLaDA-Image
|
|
|
|
LLaDA-Image is a 6B text-to-image and instruction-guided editing model using a
|
|
LLaDA2 text encoder and the FLUX.2 VAE. Choose the 50-step Base checkpoint or the
|
|
4-step Turbo checkpoint, keeping each variant's text encoder and connectors
|
|
together.
|
|
|
|
## Model files
|
|
|
|
| Component | Weights and downloads | CLI option | Requirement |
|
|
| --- | --- | --- | --- |
|
|
| Transformer | Choose the matching Base or Turbo weights below | `--diffusion-model` | Required |
|
|
| Text encoder | Use the text encoder from the same Base or Turbo checkpoint | `--llm` | Required; variants are not interchangeable |
|
|
| Tokenizer | `tokenizer/tokenizer.json` from either original repository below | `--tokenizer` | Required; shared by Base and Turbo |
|
|
| FLUX.2 VAE | `llada_vae.safetensors`, downloaded from either original repository below | `--vae` | Required; shared by Base and Turbo |
|
|
| Connectors | Matching `*-connectors.safetensors` or `*-connectors-edit.safetensors` below | `--embeddings-connectors` | Editing requires the file including SigVQ |
|
|
|
|
Four components are required: a transformer, a text encoder, a VAE, and a connectors file
|
|
holding the QueryFormer, the text projection and, for editing, the SigVQ image encoder.
|
|
|
|
The two published checkpoints are **not** interchangeable. LLaDA-Image-Turbo and LLaDA-Image
|
|
ship different transformers, text encoders, QueryFormers and text projections; only the VAE,
|
|
the SigVQ encoder and the tokenizer are shared. Mixing the two produces degraded output rather
|
|
than a clean error, so keep each checkpoint's files together.
|
|
|
|
Both need an external LLaDA2 `tokenizer.json`, which is not embedded in sd.cpp and is the same
|
|
file for either checkpoint. Take `tokenizer/tokenizer.json` from either repository and pass it
|
|
with `--tokenizer`. See [JSON tokenizers](../guides/tokenizers.md) for CLI and C API usage.
|
|
|
|
### LLaDA-Image-Turbo (4 steps)
|
|
|
|
Converted transformer, text encoder and pre-merged connectors are at
|
|
https://huggingface.co/fszontagh/LLaDA-Image-Turbo-GGUF:
|
|
|
|
- `llada-image-turbo-f16.gguf`
|
|
- `llada-image-turbo-text_encoder-q8_0.gguf`
|
|
- `llada-image-turbo-connectors.safetensors` for text to image, or
|
|
`llada-image-turbo-connectors-edit.safetensors`, which also carries the SigVQ encoder that
|
|
editing needs.
|
|
|
|
Other quantizations of the transformer and the text encoder are in the same repository.
|
|
|
|
The VAE comes from the original repository,
|
|
https://huggingface.co/inclusionAI/LLaDA-Image-Turbo: `vae/diffusion_pytorch_model.safetensors`,
|
|
referred to below as `llada_vae.safetensors`.
|
|
|
|
### LLaDA-Image (50 steps)
|
|
|
|
Converted transformer, text encoder and pre-merged connectors are at
|
|
https://huggingface.co/fszontagh/LLaDA-Image-GGUF:
|
|
|
|
- `llada-image-f16.gguf`
|
|
- `llada-image-text_encoder-q8_0.gguf`
|
|
- `llada-image-connectors.safetensors` for text to image, or
|
|
`llada-image-connectors-edit.safetensors`, which also carries the SigVQ encoder that editing
|
|
needs.
|
|
|
|
Other quantizations of the transformer and the text encoder are in the same repository.
|
|
|
|
The VAE comes from the original repository,
|
|
https://huggingface.co/inclusionAI/LLaDA-Image, and is the same file as the Turbo one.
|
|
|
|
### Optional conversion
|
|
|
|
Run executable conversion examples from the build directory using the
|
|
[shared path and shell conventions](README.md#example-conventions).
|
|
|
|
#### Converting the weights yourself
|
|
|
|
The transformer has to go in through `--diffusion-model` so that its tensor names keep the
|
|
prefix the loader expects, while the text encoder goes in through `-m`:
|
|
|
|
**Windows (PowerShell)**
|
|
|
|
```powershell
|
|
.\bin\Release\sd-cli.exe `
|
|
-M convert `
|
|
--diffusion-model ..\models\transformer\diffusion_pytorch_model.safetensors.index.json `
|
|
--type f16 `
|
|
-o llada-image-f16.gguf
|
|
.\bin\Release\sd-cli.exe `
|
|
-M convert `
|
|
-m ..\models\text_encoder\model.safetensors.index.json `
|
|
--type q8_0 `
|
|
-o llada-image-text_encoder-q8_0.gguf
|
|
```
|
|
|
|
**Linux/macOS**
|
|
|
|
```sh
|
|
./bin/sd-cli \
|
|
-M convert \
|
|
--diffusion-model ../models/transformer/diffusion_pytorch_model.safetensors.index.json \
|
|
--type f16 \
|
|
-o llada-image-f16.gguf
|
|
./bin/sd-cli \
|
|
-M convert \
|
|
-m ../models/text_encoder/model.safetensors.index.json \
|
|
--type q8_0 \
|
|
-o llada-image-text_encoder-q8_0.gguf
|
|
```
|
|
|
|
#### Building the connector file yourself
|
|
|
|
`--embeddings-connectors` takes one file, so the QueryFormer, the text projection and
|
|
(for editing) the SigVQ encoder have to be combined into a single Safetensors file, each
|
|
tensor name prefixed with its component name. Leaving `sigvq` out skips loading the 2.6 GB
|
|
encoder:
|
|
|
|
```python
|
|
from safetensors.torch import load_file, save_file
|
|
|
|
merged = {}
|
|
for prefix, path in [
|
|
("queryformer", "queryformer/diffusion_pytorch_model.safetensors"),
|
|
("text_projection", "text_projection/diffusion_pytorch_model.safetensors"),
|
|
("sigvq", "sigvq/diffusion_pytorch_model.safetensors"),
|
|
]:
|
|
for name, tensor in load_file(path).items():
|
|
merged[f"{prefix}.{name}"] = tensor
|
|
save_file(merged, "llada_connectors.safetensors")
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Web UI
|
|
|
|
Follow the [Web UI guide](../../examples/server/README.md#web-ui) to start the
|
|
server, then select the recipe matching your weights. Fill the component slots
|
|
below and click **Load models**.
|
|
Use the files and compatibility requirements in [Model files](#model-files).
|
|
|
|
| Recipe | Component slots |
|
|
| --- | --- |
|
|
| LLaDA Image Turbo (`llada-image-turbo`) | `diffusion_model`, `llm`, `tokenizer`, `embeddings_connectors`, `vae`, `tae` |
|
|
| LLaDA Image (base) (`llada-image`) | `diffusion_model`, `llm`, `tokenizer`, `embeddings_connectors`, `vae`, `tae` |
|
|
|
|
Slot IDs correspond to CLI component options: `diffusion_model` uses
|
|
`--diffusion-model`, `llm` uses `--llm`, and `model` uses `-m` / `--model`.
|
|
Select optional components when required by your checkpoint or task.
|
|
|
|
### DGL
|
|
|
|
| Example | Description |
|
|
| --- | --- |
|
|
| [Text to image](../dgl/llada_image/llada-image-turbo-txt2img.dgl) | LLaDA-Image Turbo. |
|
|
| [Image editing](../dgl/llada_image/llada-image-turbo-edit.dgl) | Edit a reference image. |
|
|
|
|
#### Run a script
|
|
|
|
Edit paths, prompts and settings in the script's `var` block, then run from
|
|
the build directory. Paths inside the script resolve from the working directory.
|
|
|
|
**Windows (PowerShell)**
|
|
|
|
```powershell
|
|
.\bin\Release\sd-cli.exe -M dgl --script ..\docs\dgl\llada_image\llada-image-turbo-txt2img.dgl
|
|
```
|
|
|
|
**Linux/macOS**
|
|
|
|
```sh
|
|
./bin/sd-cli -M dgl --script ../docs/dgl/llada_image/llada-image-turbo-txt2img.dgl
|
|
```
|
|
|
|
Choose another script from the table to run a different task. Add `--check`
|
|
to validate syntax and types without loading weights. See the
|
|
[shared run instructions](../dgl/README.md#run-an-example) for build paths
|
|
and the server's file-access rules.
|
|
|
|
### Legacy CLI
|
|
|
|
CLI examples use the [shared path and shell conventions](README.md#example-conventions).
|
|
|
|
#### Text to image
|
|
|
|
**Windows (PowerShell)**
|
|
|
|
```powershell
|
|
.\bin\Release\sd-cli.exe `
|
|
--diffusion-model ..\models\diffusion_models\llada-image-turbo-f16.gguf `
|
|
--llm ..\models\text_encoders\llada-image-turbo-text_encoder-q8_0.gguf `
|
|
--tokenizer ..\models\tokenizers\tokenizer.json `
|
|
--vae ..\models\vae\llada_vae.safetensors `
|
|
--embeddings-connectors ..\models\text_encoders\llada-image-turbo-connectors.safetensors `
|
|
--prompt "a lovely cat holding a sign says 'llada.cpp'" `
|
|
--steps 4 `
|
|
--cfg-scale 1.0 `
|
|
--width 1024 `
|
|
--height 1024 `
|
|
--seed 42 `
|
|
--output output.png
|
|
```
|
|
|
|
**Linux/macOS**
|
|
|
|
```sh
|
|
./bin/sd-cli \
|
|
--diffusion-model ../models/diffusion_models/llada-image-turbo-f16.gguf \
|
|
--llm ../models/text_encoders/llada-image-turbo-text_encoder-q8_0.gguf \
|
|
--tokenizer ../models/tokenizers/tokenizer.json \
|
|
--vae ../models/vae/llada_vae.safetensors \
|
|
--embeddings-connectors ../models/text_encoders/llada-image-turbo-connectors.safetensors \
|
|
--prompt "a lovely cat holding a sign says 'llada.cpp'" \
|
|
--steps 4 \
|
|
--cfg-scale 1.0 \
|
|
--width 1024 \
|
|
--height 1024 \
|
|
--seed 42 \
|
|
--output output.png
|
|
```
|
|
|
|
<img width="256" alt="LLaDA-Image example" src="../../assets/llada_image/example.png" />
|
|
|
|
#### Image editing
|
|
|
|
**Windows (PowerShell)**
|
|
|
|
```powershell
|
|
.\bin\Release\sd-cli.exe `
|
|
--diffusion-model ..\models\diffusion_models\llada-image-turbo-f16.gguf `
|
|
--llm ..\models\text_encoders\llada-image-turbo-text_encoder-q8_0.gguf `
|
|
--tokenizer ..\models\tokenizers\tokenizer.json `
|
|
--vae ..\models\vae\llada_vae.safetensors `
|
|
--embeddings-connectors ..\models\text_encoders\llada-image-turbo-connectors-edit.safetensors `
|
|
--ref-image ..\inputs\input.png `
|
|
--prompt "change the sign text to 'sd.cpp'" `
|
|
--steps 4 `
|
|
--cfg-scale 1.0 `
|
|
--width 1024 `
|
|
--height 1024 `
|
|
--output output.png
|
|
```
|
|
|
|
**Linux/macOS**
|
|
|
|
```sh
|
|
./bin/sd-cli \
|
|
--diffusion-model ../models/diffusion_models/llada-image-turbo-f16.gguf \
|
|
--llm ../models/text_encoders/llada-image-turbo-text_encoder-q8_0.gguf \
|
|
--tokenizer ../models/tokenizers/tokenizer.json \
|
|
--vae ../models/vae/llada_vae.safetensors \
|
|
--embeddings-connectors ../models/text_encoders/llada-image-turbo-connectors-edit.safetensors \
|
|
--ref-image ../inputs/input.png \
|
|
--prompt "change the sign text to 'sd.cpp'" \
|
|
--steps 4 \
|
|
--cfg-scale 1.0 \
|
|
--width 1024 \
|
|
--height 1024 \
|
|
--output output.png
|
|
```
|
|
|
|
<img width="256" alt="LLaDA-Image edit example" src="../../assets/llada_image/edit_example.png" />
|
|
|
|
See [edit.md](../guides/edit.md) for the shared reference-image options. The CLI and C API
|
|
resize the reference image to the output width and height before VAE encoding.
|
|
SigVQ uses bilinear resizing to half the output resolution and inputs
|
|
normalized to `[-1, 1]`. CFG keeps the source latent in both branches and uses SigVQ features
|
|
only in the positive branch. Editing requires connectors that include the SigVQ weights.
|
|
|
|
## Notes and limitations
|
|
|
|
- Use 4 steps and `--cfg-scale 1.0` for LLaDA-Image-Turbo; the guidance is distilled away, so
|
|
a higher CFG degrades output and doubles the text encoder cost. The 50-step base model uses
|
|
`--steps 50 --cfg-scale 5`.
|
|
- Width and height are rounded up to a multiple of 16. For editing the reference pipeline
|
|
requires them to be divisible by 32.
|
|
- Edit the 50-step base model at 1024x1024. At 512x512 it returns the reference image almost
|
|
unchanged instead of applying the instruction; LLaDA-Image-Turbo edits correctly at both.
|
|
- Editing runs the reference and the target in one sequence, so it needs roughly twice the
|
|
tokens of text to image at the same size. On 12 GB, editing at 1024x1024 needs
|
|
flash attention; without it the diffusion graph does not fit.
|
|
- The weights total about 16 GB, but segmented execution streams them, so a much smaller
|
|
budget works. At 512x512, `--max-vram 6` costs almost nothing over unconstrained execution,
|
|
and `--max-vram 3` still produces byte-identical output at roughly 2.5x the time.
|
|
- `--scheduler` defaults to `llada_image`, which reproduces the reference Kumaraswamy sigma
|
|
grid. `--extra-sample-args uniform=1` selects the uniform grid instead.
|
|
- Prompt templating is handled automatically; pass a plain description.
|
|
- Image editing uses the same target-sized reference pixels for VAE encoding
|
|
and the text encoder's image components.
|
|
- VQ-conditioned generation (`generation_mode="vq"`, where the text encoder decodes image
|
|
tokens before diffusion) is not implemented.
|