Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ API and command-line option may change frequently.***
- [Ming-Image Design](./docs/models/ming_image.md)
- [PixArt](./docs/models/pixart.md)
- [Iris-3B](./docs/models/iris.md)
- [Nucleus-Image](./docs/models/nucleus_image.md)
- [Image Edit Models](./docs/guides/edit.md)
- [FLUX.1-Kontext-dev](./docs/models/kontext.md)
- [Qwen Image Edit series](./docs/models/qwen_image_edit.md)
Expand Down
1 change: 1 addition & 0 deletions docs/dgl-builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,4 @@ Pass the ID as the component loader's `family` argument. The default is `"auto"`
| `relayvsr` | RelayVSR |
| `seedvr2` | SeedVR2 |
| `kandinsky_imagesr` | Kandinsky ImageSR 2.0 |
| `nucleus_image` | Nucleus-Image |
1 change: 1 addition & 0 deletions docs/dgl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ and [NumPy tensor files](../dgl.md#tensor-files).
| [MiniMax-H3-Image](../models/minimax_h3_image.md) | [Text to image](minimax_h3_image/minimax-h3-image-txt2img.dgl) · [Image editing](minimax_h3_image/minimax-h3-image-edit.dgl) |
| [MiniT2I](../models/minit2i.md) | [CUDA](minit2i/minit2i-cuda-txt2img.dgl) · [Metal](minit2i/minit2i-metal-txt2img.dgl) (`--threads 8`) |
| [MOSS-Image](../models/moss_image.md) | [Base: text to image](moss_image/moss-image-base-txt2img.dgl) · [SFT: text to image](moss_image/moss-image-sft-txt2img.dgl) · [Inline images](moss_image/moss-image-sft-inline-images.dgl) · [Image editing (HQ)](moss_image/moss-image-edit.dgl) · [Image editing (chinoll)](moss_image/moss-image-edit-chinoll.dgl) |
| [Nucleus-Image](../models/nucleus_image.md) | [Text to image](nucleus_image/nucleus-image-txt2img.dgl) |
| [Ovis-Image](../models/ovis_image.md) | [Text to image](ovis_image/ovis-image-txt2img.dgl) |
| [P-H3-Image](../models/p_h3_image.md) | [Text to image](p_h3_image/p-h3-image-txt2img.dgl) · [Image editing](p_h3_image/p-h3-image-edit.dgl) |
| [PiD](../models/pid.md) | [512 to 2048 pixels](pid/pid-flux1-512-to-2048-txt2img.dgl) |
Expand Down
43 changes: 43 additions & 0 deletions docs/dgl/nucleus_image/nucleus-image-txt2img.dgl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# version: 0.0.0
# docs/models/nucleus_image.md — Nucleus-Image

var {
model_path = "../models/diffusion_models/Nucleus-Image-Q8_0.safetensors"
text_path = "../models/text_encoders/Qwen3VL-8B-Instruct-Q4_K_M.gguf"
vae_path = "../models/vae/qwen_image_vae.safetensors"

output_path = "output.png"

prompt = "a lovely cat holding a sign says 'nucleus.cpp'"
negative_prompt = ""

seed = 42
rng_type = "cuda"
width = 768
height = 768

steps = 24
cfg_scale = 4.5
method = "euler"
scheduler = "discrete"
}

fn main() {
model = load_dit(model_path, family = "nucleus_image", params_backend = "cpu")
text = load_text_encoder(text_path, family = "nucleus_image", params_backend = "cpu")
vae = load_vae(vae_path, family = "nucleus_image", params_backend = "cpu")

base = tensor::zeros(latent_shape(vae, width = width, height = height))
positive = encode_prompt(text, prompt, width = width, height = height)
negative = encode_prompt(text, negative_prompt, width = width, height = height)
pos = predictor(model, positive)
neg = predictor(model, negative)
guided = cfg(pos, neg, scale = cfg_scale)
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
rng = make_rng(rng_type, seed = seed)
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
image::save(output_path, image)
return {image = image, latent = latent}
}
1 change: 1 addition & 0 deletions docs/models/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ variant; a VAE or TAE selection must match that model.
- [MiniMax-H3-Image](minimax_h3_image.md)
- [MiniT2I](minit2i.md)
- [MOSS-Image](moss_image.md)
- [Nucleus-Image](nucleus_image.md)
- [Ovis-Image](ovis_image.md)
- [P-H3-Image](p_h3_image.md)
- [PiD](pid.md)
Expand Down
106 changes: 106 additions & 0 deletions docs/models/nucleus_image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Nucleus-Image

Nucleus-Image is a text-to-image diffusion transformer with sparse mixture-of-experts
layers: 17B total parameters, about 2B active per step. It uses Qwen3-VL-8B-Instruct as
the LLM text encoder and the Qwen-Image VAE.

## Model files

| Component | Weights and downloads | CLI option | Requirement |
| --- | --- | --- | --- |
| Nucleus-Image | [Safetensors](https://huggingface.co/stduhpf/Nucleus-Image-sdcpp/tree/main): `Nucleus-Image-Q8_0.safetensors` (18 GB) or `Nucleus-Image-Q5_1.safetensors` (12.7 GB) | `--diffusion-model` | Required |
| Qwen3-VL-8B-Instruct | [GGUF](https://huggingface.co/Qwen/Qwen3-VL-8B-Instruct-GGUF/tree/main): `Qwen3VL-8B-Instruct-Q4_K_M.gguf` | `--llm` | Required |
| vae | [Safetensors](https://huggingface.co/Comfy-Org/Qwen-Image_ComfyUI/tree/main/split_files/vae): `qwen_image_vae.safetensors` | `--vae` | Required |

No separate tokenizer file is needed.

## 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 |
| --- | --- |
| Nucleus Image (`nucleus-image`) | `diffusion_model`, `llm`, `vae` |

Slot IDs correspond to CLI component options: `diffusion_model` uses
`--diffusion-model` and `llm` uses `--llm`.

### DGL

| Example | Description |
| --- | --- |
| [Text to image](../dgl/nucleus_image/nucleus-image-txt2img.dgl) | Nucleus-Image Q8_0. |

#### 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\nucleus_image\nucleus-image-txt2img.dgl
```

**Linux/macOS**

```sh
./bin/sd-cli -M dgl --script ../docs/dgl/nucleus_image/nucleus-image-txt2img.dgl
```

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).

**Windows (PowerShell)**

```powershell
.\bin\Release\sd-cli.exe `
--diffusion-model ..\models\diffusion_models\Nucleus-Image-Q8_0.safetensors `
--llm ..\models\text_encoders\Qwen3VL-8B-Instruct-Q4_K_M.gguf `
--vae ..\models\vae\qwen_image_vae.safetensors `
-p "a lovely cat holding a sign says 'nucleus.cpp'" `
--cfg-scale 4.5 `
--steps 24 `
--sampling-method euler `
-H 768 `
-W 768 `
--seed 42 `
-v
```

**Linux/macOS**

```sh
./bin/sd-cli \
--diffusion-model ../models/diffusion_models/Nucleus-Image-Q8_0.safetensors \
--llm ../models/text_encoders/Qwen3VL-8B-Instruct-Q4_K_M.gguf \
--vae ../models/vae/qwen_image_vae.safetensors \
-p "a lovely cat holding a sign says 'nucleus.cpp'" \
--cfg-scale 4.5 \
--steps 24 \
--sampling-method euler \
-H 768 \
-W 768 \
--seed 42 \
-v
```

## Notes and limitations

- Text-to-image only. Reference-image editing is not supported.
- The default flow shift is 1.0, matching the authors' scheduler configuration.
- The model card reports benchmark settings of 1024×1024, 50 steps and CFG 8.0 with
renormalized guidance in diffusers. This integration applies standard classifier-free
guidance.
- The checkpoints are 12.7 GB (Q5_1) and 18 GB (Q8_0) before the text encoder and VAE.
On GPUs that cannot hold them, add `--offload-to-cpu`.
33 changes: 33 additions & 0 deletions examples/server/recipes/nucleus-image.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"schema_version": 1,
"id": "nucleus-image",
"name": "Nucleus Image (Sparse MoE)",
"description": "Nucleus-Image text-to-image with the Qwen3-VL-8B-Instruct text encoder and the Qwen-Image VAE.",
"model_url": "https://huggingface.co/NucleusAI/Nucleus-Image",
"slots": [
{
"id": "diffusion_model",
"required": true
},
{
"id": "llm",
"required": true,
"label": "Qwen 3 VL 8B Text Encoder"
},
{
"id": "vae",
"required": true,
"label": "Qwen Image VAE"
}
],
"defaults": {
"sampling_method": "euler",
"cfg_scale": 4.5,
"steps": 24,
"width": 768,
"height": 768
},
"features": [
"flow_shift"
]
}
12 changes: 12 additions & 0 deletions src/conditioning/llm_conditioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct LLMEmbedder : public Conditioner {
arch = LLM::LLMArch::GEMMA2_2B;
} else if (version == VERSION_FIBO2 ||
version == VERSION_QWEN_IMAGE_2_1 ||
version == VERSION_NUCLEUS_IMAGE ||
sd_version_is_flux3(version) ||
sd_version_is_lingbot_video(version) ||
sd_version_is_ideogram4(version) ||
Expand Down Expand Up @@ -1290,6 +1291,17 @@ struct LLMEmbedder : public Conditioner {
prompt += conditioner_params.text;
prompt_attn_range.second = static_cast<int>(prompt.size());
prompt += "<|im_end|>\n<|im_start|>assistant\n<think>\n";
} else if (version == VERSION_NUCLEUS_IMAGE) {
prompt_template_encode_start_idx = 0;
out_layers = {static_cast<int>(llm->config.num_layers) - 7}; // -8

prompt = system_prefix("<|im_start|>system\nYou are an image generation assistant. Follow the user's prompt literally. Pay careful attention to spatial layout: objects described as on the left must appear on the left, on the right on the right. Match exact object counts and assign colors to the correct objects.<|im_end|>\n<|im_start|>user\n");

prompt_attn_range.first = static_cast<int>(prompt.size());
prompt += conditioner_params.text;
prompt_attn_range.second = static_cast<int>(prompt.size());

prompt += "<|im_end|>\n<|im_start|>assistant\n";
} else if (sd_version_is_flux3(version)) {
prompt_template_encode_start_idx = 0;
max_length = 4096;
Expand Down
1 change: 1 addition & 0 deletions src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ enum SDVersion {
VERSION_RELAY_VSR,
VERSION_SEEDVR2,
VERSION_KANDINSKY_IMAGESR,
VERSION_NUCLEUS_IMAGE,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
VERSION_COUNT,
};

Expand Down
Loading
Loading