Skip to content

Commit 5de6d0e

Browse files
committed
add docs.
1 parent f567f56 commit 5de6d0e

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

docs/source/en/api/pipelines/qwenimage.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,63 @@ Make sure to check out the Schedulers [guide](../../using-diffusers/schedulers)
2424

2525
</Tip>
2626

27+
## LoRA for faster inference
28+
29+
Use a LoRA from `lightx2v/Qwen-Image-Lightning` to speed up inference by reducing the
30+
number of steps. Refer to the code snippet below:
31+
32+
<details>
33+
<summary>Code</summary>
34+
35+
```py
36+
from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler
37+
import torch
38+
import math
39+
40+
ckpt_id = "Qwen/Qwen-Image"
41+
42+
# From
43+
# https://github.com/ModelTC/Qwen-Image-Lightning/blob/342260e8f5468d2f24d084ce04f55e101007118b/generate_with_diffusers.py#L82C9-L97C10
44+
scheduler_config = {
45+
"base_image_seq_len": 256,
46+
"base_shift": math.log(3), # We use shift=3 in distillation
47+
"invert_sigmas": False,
48+
"max_image_seq_len": 8192,
49+
"max_shift": math.log(3), # We use shift=3 in distillation
50+
"num_train_timesteps": 1000,
51+
"shift": 1.0,
52+
"shift_terminal": None, # set shift_terminal to None
53+
"stochastic_sampling": False,
54+
"time_shift_type": "exponential",
55+
"use_beta_sigmas": False,
56+
"use_dynamic_shifting": True,
57+
"use_exponential_sigmas": False,
58+
"use_karras_sigmas": False,
59+
}
60+
scheduler = FlowMatchEulerDiscreteScheduler.from_config(scheduler_config)
61+
pipe = DiffusionPipeline.from_pretrained(
62+
ckpt_id, scheduler=scheduler, torch_dtype=torch.bfloat16
63+
).to("cuda")
64+
pipe.load_lora_weights(
65+
"lightx2v/Qwen-Image-Lightning", weight_name="Qwen-Image-Lightning-8steps-V1.0.safetensors"
66+
)
67+
68+
prompt = "a tiny astronaut hatching from an egg on the moon, Ultra HD, 4K, cinematic composition."
69+
negative_prompt = " "
70+
image = pipe(
71+
prompt=prompt,
72+
negative_prompt=negative_prompt,
73+
width=1024,
74+
height=1024,
75+
num_inference_steps=8,
76+
true_cfg_scale=1.0,
77+
generator=torch.manual_seed(0),
78+
).images[0]
79+
image.save("qwen_fewsteps.png")
80+
```
81+
82+
</details>
83+
2784
## QwenImagePipeline
2885

2986
[[autodoc]] QwenImagePipeline

0 commit comments

Comments
 (0)