--- 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) | Coffee shop, 40 steps | Coffee shop, 4 steps | | [Nine-Headed Fox Beast](assets/t2i/02/prompt.txt) | Fox beast, 40 steps | Fox beast, 4 steps | | [Sheep Designer Toy](assets/t2i/03/prompt.txt) | Sheep toy, 40 steps | Sheep toy, 4 steps | | [Office Cow Selfie](assets/t2i/04/prompt.txt) | Office cow, 40 steps | Office cow, 4 steps | | [Floral Wine Advertisement](assets/t2i/05/prompt.txt) | Wine advertisement, 40 steps | Wine advertisement, 4 steps | ### 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) | Reference image 1 | Jacket recolor, 40 steps | Jacket recolor, 4 steps | | [Outfit and Night Scene](assets/edit/02/prompt.txt) | Reference image 1
Reference image 2
Reference image 3 | Outfit and night scene, 40 steps | Outfit and night scene, 4 steps | | [Person and Cat](assets/edit/03/prompt.txt) | Reference image 1
Reference image 2
Reference image 3 | Person and cat, 40 steps | Person and cat, 4 steps | | [Product Advertisement](assets/edit/04/prompt.txt) | Reference image 1
Reference image 2
Reference image 3 | Product advertisement, 40 steps | Product advertisement, 4 steps | | [Sofa and Pendant Lamp](assets/edit/05/prompt.txt) | Reference image 1
Reference image 2
Reference image 3 | Sofa and pendant lamp, 40 steps | Sofa and pendant lamp, 4 steps | | [Floor Material Transfer](assets/edit/06/prompt.txt) | Reference image 1
Reference image 2 | Floor material transfer, 40 steps | Floor material transfer, 4 steps | | [Mirror Reflection](assets/edit/07/prompt.txt) | Reference image 1
Reference image 2
Reference image 3 | Mirror reflection, 40 steps | Mirror reflection, 4 steps | | [Backpack Try-On](assets/edit/08/prompt.txt) | Reference image 1
Reference image 2
Reference image 3 | Backpack try-on, 40 steps | Backpack try-on, 4 steps |