How to use from the
Use from the
Diffusers library
pip install -U diffusers transformers accelerate
import torch
from diffusers import DiffusionPipeline

# switch to "mps" for apple devices
pipe = DiffusionPipeline.from_pretrained("Qwen/Qwen-Image-2.1", dtype=torch.bfloat16, device_map="cuda")
pipe.load_lora_weights("lightx2v/Qwen-Image-2.1-Lightning")

prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
image = pipe(prompt).images[0]

LightX2V Lightning for Qwen-Image-2.1

A 4-step distilled LoRA for 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.

For inference on heterogeneous hardware platforms, refer to the LightX2V platform scripts.

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:

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:

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 Coffee shop, 40 steps Coffee shop, 4 steps
Nine-Headed Fox Beast Fox beast, 40 steps Fox beast, 4 steps
Sheep Designer Toy Sheep toy, 40 steps Sheep toy, 4 steps
Office Cow Selfie Office cow, 40 steps Office cow, 4 steps
Floral Wine Advertisement Wine advertisement, 40 steps Wine advertisement, 4 steps

Image editing

Both models use the same reference images, shown below in prompt order.

Downloads last month
586
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for lightx2v/Qwen-Image-2.1-Lightning

Adapter
(127)
this model
Merges
1 model

Spaces using lightx2v/Qwen-Image-2.1-Lightning 2

Collection including lightx2v/Qwen-Image-2.1-Lightning