Repository navigation
feat: add Nucleus-Image (Sparse MoE 17B) support #2315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+742
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.