Qwen Image Lightning
Overview
Highlights
- Rapid inference speeds for real-time image generation
- Permissive Apache-2.0 license for commercial use
- Low latency suitable for scalable production environments
- Strong prompt adherence for precise visual control
Usage
# Install Hugging Face transformers
pip install transformers torch
# Load model with transformers
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained("lightx2v/Qwen-Image-Lightning")
tokenizer = AutoTokenizer.from_pretrained("lightx2v/Qwen-Image-Lightning")
Hugging Face Download
We recommend downloading the model via the Hugging Face CLI or Hub SDK.
Guidance:Before downloading, install huggingface_hub with:
pip install -U huggingface_hub
CLI Download
Download the full repository
huggingface-cli download lightx2v/Qwen-Image-Lightning
Download a single file to a local folder (e.g. config.json into ./dir)
huggingface-cli download lightx2v/Qwen-Image-Lightning config.json --local-dir ./dir
See the official docs for more CLI options
SDK Download
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('lightx2v/Qwen-Image-Lightning')
Git Download
Make sure git-lfs is installed first
git lfs install
git clone https://huggingface.co/lightx2v/Qwen-Image-Lightning
To skip LFS large-file downloads, use:
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/lightx2v/Qwen-Image-Lightning
Model files are hosted on the Hugging Face Hub — download directly via HF CLI / SDK / Git, not through this site.
PyTorch / Transformers Usage
Install Transformers
pip install -U transformers torch
Load the model and run inference
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained('lightx2v/Qwen-Image-Lightning')
tokenizer = AutoTokenizer.from_pretrained('lightx2v/Qwen-Image-Lightning')
Model Download
We recommend downloading the model via the ModelScope CLI or SDK.
Guidance:Before downloading, install ModelScope with:
pip install modelscope
CLI Download
Download the full repository
modelscope download --model lightx2v/Qwen-Image-Lightning
Download a single file to a local folder (e.g. README.md into ./dir)
modelscope download --model lightx2v/Qwen-Image-Lightning README.md --local_dir ./dir
See the docs for more CLI options
SDK Download
# 模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('lightx2v/Qwen-Image-Lightning')
Git Download
Make sure git-lfs is installed first
git lfs install
git clone https://www.modelscope.cn/lightx2v/Qwen-Image-Lightning.git
To skip LFS large-file downloads, use:
GIT_LFS_SKIP_SMUDGE=1 git clone https://www.modelscope.cn/lightx2v/Qwen-Image-Lightning.git
ModelScope 模型页直接下载模型文件;无需将模型文件放在本站服务器。
Notebook Quickstart
Install the ModelScope library
pip install "modelscope[audio,cv,nlp,multi-modal,science]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html
Load the model and run inference
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
p = pipeline('text-generation', 'lightx2v/Qwen-Image-Lightning')
Full Documentation
---
license: apache-2.0
language:
- en
- zh
base_model:
- Qwen/Qwen-Image
pipeline_tag: text-to-image
tags:
- Qwen-Image
- distillation
- LoRA
- lora
library_name: diffusers
---
Please refer to Qwen-Image-Lightning github to learn how to use the models.
use with diffusers 🧨:
make sure to install diffusers from main (pip install git+https://github.com/huggingface/diffusers.git)
from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler
import torch
import math
From https://github.com/ModelTC/Qwen-Image-Lightning/blob/342260e8f5468d2f24d084ce04f55e101007118b/generate_with_diffusers.py#L82C9-L97C10
scheduler_config = {
"base_image_seq_len": 256,
"base_shift": math.log(3), # We use shift=3 in distillation
"invert_sigmas": False,
"max_image_seq_len": 8192,
"max_shift": math.log(3), # We use shift=3 in distillation
"num_train_timesteps": 1000,
"shift": 1.0,
"shift_terminal": None, # set shift_terminal to None
"stochastic_sampling": False,
"time_shift_type": "exponential",
"use_beta_sigmas": False,
"use_dynamic_shifting": True,
"use_exponential_sigmas": False,
"use_karras_sigmas": False,
}
scheduler = FlowMatchEulerDiscreteScheduler.from_config(scheduler_config)
pipe = DiffusionPipeline.from_pretrained(
"Qwen/Qwen-Image", scheduler=scheduler, torch_dtype=torch.bfloat16
).to("cuda")
pipe.load_lora_weights(
"lightx2v/Qwen-Image-Lightning", weight_name="Qwen-Image-Lightning-8steps-V1.0.safetensors"
)
prompt = "a tiny astronaut hatching from an egg on the moon, Ultra HD, 4K, cinematic composition."
negative_prompt = " "
image = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
width=1024,
height=1024,
num_inference_steps=8,
true_cfg_scale=1.0,
generator=torch.manual_seed(0),
).images[0]
image.save("qwen_fewsteps.png")