---
base_model: Qwen/Qwen-Image-2.1
base_model_relation: adapter
library_name: diffusers
pipeline_tag: text-to-image
tags:
- lora
- diffusion
- distillation
- image-generation
- image-editing
- lightx2v
---
# LightX2V Lightning for Qwen-Image-2.1
A **4-step distilled LoRA for [Qwen-Image-2.1](https://huggingface.co/Qwen/Qwen-Image-2.1)**, supporting text-to-image generation and image editing. Training was performed entirely on **16 Huawei Ascend 910B NPUs**, using DMD in [LightX2V](https://github.com/ModelTC/LightX2V).
For inference on heterogeneous hardware platforms, refer to the [LightX2V platform scripts](https://github.com/ModelTC/LightX2V/tree/main/scripts/platforms).
Both examples use the training noise schedule: four steps with dynamic exponential shifting and no terminal stretching. Training and LightX2V inference keep latents in FP32; these BF16 Diffusers examples can produce different numerical results.
## Text-to-image
Run this example from the directory containing `pytorch_lora_weights.safetensors`:
```python
import torch
from diffusers import FlowMatchEulerDiscreteScheduler, QwenImage21Pipeline
pipe = QwenImage21Pipeline.from_pretrained(
"Qwen/Qwen-Image-2.1", torch_dtype=torch.bfloat16
).to("cuda")
pipe.load_lora_weights(
".", weight_name="pytorch_lora_weights.safetensors", adapter_name="lightning"
)
pipe.scheduler = FlowMatchEulerDiscreteScheduler.from_config(
pipe.scheduler.config,
num_train_timesteps=1000,
use_dynamic_shifting=True,
time_shift_type="exponential",
base_image_seq_len=256,
max_image_seq_len=8192,
base_shift=0.5,
max_shift=0.9,
shift_terminal=None,
)
image = pipe(
prompt='A coffee shop entrance with a chalkboard reading "Qwen Coffee, $2 per cup" and a neon sign displaying "通义千问".',
width=1024,
height=1024,
num_inference_steps=4,
sigmas=[1.0, 0.75, 0.5, 0.25],
true_cfg_scale=1.0,
use_kv_cache=False,
generator=torch.Generator("cuda").manual_seed(42),
).images[0]
image.save("t2i.png")
```
## Image editing
Run this example from the directory containing `pytorch_lora_weights.safetensors` and `input.png`:
```python
import torch
from PIL import Image
from diffusers import FlowMatchEulerDiscreteScheduler, QwenImage21Pipeline
pipe = QwenImage21Pipeline.from_pretrained(
"Qwen/Qwen-Image-2.1", torch_dtype=torch.bfloat16
).to("cuda")
pipe.load_lora_weights(
".", weight_name="pytorch_lora_weights.safetensors", adapter_name="lightning"
)
pipe.scheduler = FlowMatchEulerDiscreteScheduler.from_config(
pipe.scheduler.config,
num_train_timesteps=1000,
use_dynamic_shifting=True,
time_shift_type="exponential",
base_image_seq_len=256,
max_image_seq_len=8192,
base_shift=0.5,
max_shift=0.9,
shift_terminal=None,
)
image = pipe(
prompt="Change the red jacket to dark blue. Keep the person's identity, pose, background and lighting unchanged.",
image=Image.open("input.png"),
width=1024,
height=1024,
num_inference_steps=4,
sigmas=[1.0, 0.75, 0.5, 0.25],
true_cfg_scale=1.0,
use_kv_cache=False,
generator=torch.Generator("cuda").manual_seed(42),
).images[0]
image.save("edit.png")
```
For multiple references, use `image=[Image.open("reference_1.png"), Image.open("reference_2.png")]`.
## Comparison
Same prompts, seeds and output sizes; CFG is disabled for both models. The 40-step base-model images are from an earlier run. Click an example name to view its prompt.
### Text-to-image
| Example | Qwen-Image-2.1 · 40 steps | Lightning LoRA · 4 steps |
| --- | --- | --- |
| [Coffee Shop Signage](assets/t2i/01/prompt.txt) |
|
|
| [Nine-Headed Fox Beast](assets/t2i/02/prompt.txt) |
|
|
| [Sheep Designer Toy](assets/t2i/03/prompt.txt) |
|
|
| [Office Cow Selfie](assets/t2i/04/prompt.txt) |
|
|
| [Floral Wine Advertisement](assets/t2i/05/prompt.txt) |
|
|
### Image editing
Both models use the same reference images, shown below in prompt order.
| Example | Reference images | Qwen-Image-2.1 · 40 steps | Lightning LoRA · 4 steps |
| --- | --- | --- | --- |
| [Jacket Recolor](assets/edit/01/prompt.txt) |
|
|
|
| [Outfit and Night Scene](assets/edit/02/prompt.txt) | 

|
|
|
| [Person and Cat](assets/edit/03/prompt.txt) | 

|
|
|
| [Product Advertisement](assets/edit/04/prompt.txt) | 

|
|
|
| [Sofa and Pendant Lamp](assets/edit/05/prompt.txt) | 

|
|
|
| [Floor Material Transfer](assets/edit/06/prompt.txt) | 
|
|
|
| [Mirror Reflection](assets/edit/07/prompt.txt) | 

|
|
|
| [Backpack Try-On](assets/edit/08/prompt.txt) | 

|
|
|