Skip to content

Commit 1ff8c47

Browse files
authored
feat: qwen-image-edit-2509 lightning support (#728)
* update * add qwen-image-edit-2509-lightning * avoid test for now
1 parent 438de9f commit 1ff8c47

4 files changed

Lines changed: 72 additions & 4 deletions

File tree

.github/workflows/pr-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: PR Tests
22
on:
33
pull_request:
4-
types: [opened, synchronize, reopened, ready_for_review]
4+
types: [opened, synchronize, reopened]
55
paths:
66
- "nunchaku/**"
77
- "src/**"

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ Join our user groups on [**Discord**](https://discord.gg/Wk6PnwX9Sm) and [**WeCh
1515

1616
## News
1717

18+
- **[2025-08-27]** 🔥 Release **4-bit [4/8-step lightning Qwen-Image-Edit-2509](https://huggingface.co/lightx2v/Qwen-Image-Lightning)**! Download on [Hugging Face](https://huggingface.co/nunchaku-tech/nunchaku-qwen-image-edit-2509) or [ModelScope](https://modelscope.cn/models/nunchaku-tech/nunchaku-qwen-image-edit-2509), and try it with our [example script](examples/v1/qwen-image-edit-2509-lightning.py).
1819
- **[2025-09-24]** 🔥 Released [**4-bit Qwen-Image-Edit-2509**](https://huggingface.co/Qwen/Qwen-Image-Edit-2509)! Models are available on [Hugging Face](https://huggingface.co/nunchaku-tech/nunchaku-qwen-image-edit-2509). Try them out with our [example script](examples/v1/qwen-image-edit-2509.py). Lightning models will follow up!
1920
- **[2025-09-09]** 🔥 Released [**4-bit Qwen-Image-Edit**](https://huggingface.co/Qwen/Qwen-Image-Edit) together with the [4/8-step Lightning](https://huggingface.co/lightx2v/Qwen-Image-Lightning) variants! Models are available on [Hugging Face](https://huggingface.co/nunchaku-tech/nunchaku-qwen-image-edit). Try them out with our [example script](examples/v1/qwen-image-edit.py).
2021
- **[2025-09-04]** 🚀 Official release of **Nunchaku v1.0.0**! Qwen-Image now supports **asynchronous offloading**, reducing VRAM usage to as little as **3 GiB** with no performance loss. Check out the [tutorial](https://nunchaku.tech/docs/nunchaku/usage/qwenimage.html) to get started.
2122
- **[2025-08-27]** 🔥 Release **4-bit [4/8-step lightning Qwen-Image](https://huggingface.co/lightx2v/Qwen-Image-Lightning)**! Download on [Hugging Face](https://huggingface.co/nunchaku-tech/nunchaku-qwen-image) or [ModelScope](https://modelscope.cn/models/nunchaku-tech/nunchaku-qwen-image), and try it with our [example script](examples/v1/qwen-image-lightning.py).
2223
- **[2025-08-15]** 🔥 Our **4-bit Qwen-Image** models are now live on [Hugging Face](https://huggingface.co/nunchaku-tech/nunchaku-qwen-image)! Get started with our [example script](examples/v1/qwen-image.py). *ComfyUI, LoRA, and CPU offloading support are coming soon!*
2324
- **[2025-08-15]** 🚀 The **Python backend** is now available! Explore our Pythonic FLUX models [here](nunchaku/models/transformers/transformer_flux_v2.py) and see the modular **4-bit linear layer** [here](nunchaku/models/linear.py).
24-
- **[2025-07-31]** 🚀 **[FLUX.1-Krea-dev](https://www.krea.ai/blog/flux-krea-open-source-release) is now supported!** Check out our new [example script](./examples/flux.1-krea-dev.py) to get started.
2525

2626
<details>
2727
<summary>More</summary>
2828

29+
- **[2025-07-31]** 🚀 **[FLUX.1-Krea-dev](https://www.krea.ai/blog/flux-krea-open-source-release) is now supported!** Check out our new [example script](./examples/flux.1-krea-dev.py) to get started.
2930
- **[2025-07-13]** 🚀 The official [**Nunchaku documentation**](https://nunchaku.tech/docs/nunchaku/) is now live! Explore comprehensive guides and resources to help you get started.
3031
- **[2025-06-29]** 🔥 Support **FLUX.1-Kontext**! Try out our [example script](./examples/flux.1-kontext-dev.py) to see it in action! Our demo is available at this [link](https://svdquant.mit.edu/kontext/)!
3132
- **[2025-06-01]** 🚀 **Release v0.3.0!** This update adds support for multiple-batch inference, [**ControlNet-Union-Pro 2.0**](https://huggingface.co/Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro-2.0), initial integration of [**PuLID**](https://github.com/ToTheBeginning/PuLID), and introduces [**Double FB Cache**](examples/flux.1-dev-double_cache.py). You can now load Nunchaku FLUX models as a single file, and our upgraded [**4-bit T5 encoder**](https://huggingface.co/nunchaku-tech/nunchaku-t5) now matches **FP8 T5** in quality!
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import math
2+
3+
import torch
4+
from diffusers import FlowMatchEulerDiscreteScheduler, QwenImageEditPlusPipeline
5+
from diffusers.utils import load_image
6+
7+
from nunchaku import NunchakuQwenImageTransformer2DModel
8+
from nunchaku.utils import get_gpu_memory, get_precision
9+
10+
# From https://github.com/ModelTC/Qwen-Image-Lightning/blob/342260e8f5468d2f24d084ce04f55e101007118b/generate_with_diffusers.py#L82C9-L97C10
11+
scheduler_config = {
12+
"base_image_seq_len": 256,
13+
"base_shift": math.log(3), # We use shift=3 in distillation
14+
"invert_sigmas": False,
15+
"max_image_seq_len": 8192,
16+
"max_shift": math.log(3), # We use shift=3 in distillation
17+
"num_train_timesteps": 1000,
18+
"shift": 1.0,
19+
"shift_terminal": None, # set shift_terminal to None
20+
"stochastic_sampling": False,
21+
"time_shift_type": "exponential",
22+
"use_beta_sigmas": False,
23+
"use_dynamic_shifting": True,
24+
"use_exponential_sigmas": False,
25+
"use_karras_sigmas": False,
26+
}
27+
scheduler = FlowMatchEulerDiscreteScheduler.from_config(scheduler_config)
28+
29+
num_inference_steps = 4 # you can also use the 8-step model to improve the quality
30+
rank = 32 # you can also use the rank=128 model to improve the quality
31+
model_path = f"nunchaku-tech/nunchaku-qwen-image-edit-2509-lightning/svdq-{get_precision()}_r{rank}-qwen-image-edit-2509-lightningv2.0-{num_inference_steps}steps.safetensors"
32+
33+
# Load the model
34+
transformer = NunchakuQwenImageTransformer2DModel.from_pretrained(model_path)
35+
36+
pipeline = QwenImageEditPlusPipeline.from_pretrained(
37+
"Qwen/Qwen-Image-Edit-2509", transformer=transformer, torch_dtype=torch.bfloat16
38+
)
39+
40+
if get_gpu_memory() > 18:
41+
pipeline.enable_model_cpu_offload()
42+
else:
43+
# use per-layer offloading for low VRAM. This only requires 3-4GB of VRAM.
44+
transformer.set_offload(
45+
True, use_pin_memory=False, num_blocks_on_gpu=1
46+
) # increase num_blocks_on_gpu if you have more VRAM
47+
pipeline._exclude_from_cpu_offload.append("transformer")
48+
pipeline.enable_sequential_cpu_offload()
49+
50+
image1 = load_image("https://huggingface.co/datasets/nunchaku-tech/test-data/resolve/main/inputs/man.png")
51+
image1 = image1.convert("RGB")
52+
image2 = load_image("https://huggingface.co/datasets/nunchaku-tech/test-data/resolve/main/inputs/puppy.png")
53+
image2 = image2.convert("RGB")
54+
image3 = load_image("https://huggingface.co/datasets/nunchaku-tech/test-data/resolve/main/inputs/sofa.png")
55+
image3 = image3.convert("RGB")
56+
57+
prompt = "Let the man in image 1 lie on the sofa in image 3, and let the puppy in image 2 lie on the floor to sleep."
58+
inputs = {
59+
"image": [image1, image2, image3],
60+
"prompt": prompt,
61+
"true_cfg_scale": 1.0,
62+
"num_inference_steps": num_inference_steps,
63+
}
64+
65+
output = pipeline(**inputs)
66+
output_image = output.images[0]
67+
output_image.save(f"qwen-image-edit-2509-lightning-r{rank}-{num_inference_steps}steps.png")

examples/v1/qwen-image-edit-lightning.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
}
2727
scheduler = FlowMatchEulerDiscreteScheduler.from_config(scheduler_config)
2828

29-
num_inference_steps = 8 # you can also use the 8-step model to improve the quality
30-
rank = 128 # you can also use the rank=128 model to improve the quality
29+
num_inference_steps = 4 # you can also use the 8-step model to improve the quality
30+
rank = 32 # you can also use the rank=128 model to improve the quality
3131
model_paths = {
3232
4: f"nunchaku-tech/nunchaku-qwen-image-edit/svdq-{get_precision()}_r{rank}-qwen-image-edit-lightningv1.0-4steps.safetensors",
3333
8: f"nunchaku-tech/nunchaku-qwen-image-edit/svdq-{get_precision()}_r{rank}-qwen-image-edit-lightningv1.0-8steps.safetensors",

0 commit comments

Comments
 (0)