Qwen Image Lightning

提供商lightx2v
分类text-to-image
许可证apache-2.0
下载量35.1K
星标70

简介

Qwen Image Lightning 是一款主打极致生成速度的文本到图像模型。它针对中文语境进行了深度优化,能够精准理解复杂的中文提示词,有效解决了许多海外模型在处理中文意境时出现的“理解偏差”。该模型上手门槛极低,非常适合需要快速出图、进行创意脑暴或在实时应用场景中集成图像生成的开发者。相比于传统的重量级扩散模型,它在保证视觉质量的同时大幅降低了推理延迟,是追求效率与质量平衡的理想选择。

核心亮点

  • 原生支持中文,提示词理解精准且地道
  • 极速出图能力,显著降低推理等待时间
  • Apache-2.0 协议,对商业应用非常友好
  • 适用于实时生成、快速原型设计等场景

使用方法

安装依赖
# 安装 Hugging Face transformers
pip install transformers torch
SDK 使用
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("lightx2v/Qwen-Image-Lightning")
tokenizer = AutoTokenizer.from_pretrained("lightx2v/Qwen-Image-Lightning")

Hugging Face 下载

我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 huggingface_hub:

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download lightx2v/Qwen-Image-Lightning

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download lightx2v/Qwen-Image-Lightning config.json --local-dir ./dir

更多命令行下载选项,可参见官方文档

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('lightx2v/Qwen-Image-Lightning')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/lightx2v/Qwen-Image-Lightning

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/lightx2v/Qwen-Image-Lightning

模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。

PyTorch / Transformers 使用

安装 Transformers

安装 Transformers
pip install -U transformers torch

模型加载和推理

模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('lightx2v/Qwen-Image-Lightning')
tokenizer = AutoTokenizer.from_pretrained('lightx2v/Qwen-Image-Lightning')

模型下载

我们推荐使用命令行或者 ModelScope SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 ModelScope:

操作指引
pip install modelscope

命令行下载

下载完整模型库

下载完整模型库
modelscope download --model lightx2v/Qwen-Image-Lightning

下载单个文件到指定本地文件夹(以下载 README.md 到当前路径下 dir 目录为例)

下载单个文件到指定本地文件夹(以下载 README.md 到当前路径下 dir 目录为例)
modelscope download --model lightx2v/Qwen-Image-Lightning README.md --local_dir ./dir

更多更丰富的命令行下载选项,可参见具体文档

SDK 下载

SDK 下载
# 模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('lightx2v/Qwen-Image-Lightning')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://www.modelscope.cn/lightx2v/Qwen-Image-Lightning.git

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://www.modelscope.cn/lightx2v/Qwen-Image-Lightning.git

ModelScope 模型页直接下载模型文件;无需将模型文件放在本站服务器。

Notebook 快速开发

下载并安装 ModelScope library

下载并安装 ModelScope library
pip install "modelscope[audio,cv,nlp,multi-modal,science]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

模型加载和推理

模型加载和推理
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

p = pipeline('text-generation', 'lightx2v/Qwen-Image-Lightning')

完整文档

来源: HuggingFace

---
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)

code
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")