HuggingFace镜像/Qwen-Image-2.1-FP8
模型介绍
文件和版本
分析

阅读我们的《如何 运行 Qwen-Image-2.1 指南!》 💜

这是 Qwen-Image-2.1 的 FP8 / INT8 量化版本,并附带其 Qwen3-VL 文本编码器的预转换 FP8 副本。

  • 若追求更高质量,你还可以通过 offloading 在仅 6GB 显存(VRAM)上运行 Dynamic FP8(速度慢不到 2 倍)。
  • 为高效推理优化,同时降低内存占用。与 bf16 模型同种子 LPIPS(越低越好):INT8 为 0.064,FP8 为 0.112。INT8 为默认发布方案。
  • 在 Unsloth Desktop 中会自动使用这些权重:选择 Qwen-Image-2.1 以及 INT8 或 FP8 精度即可。
文件大小替代
Qwen-Image-2.1-INT8.safetensors7.26 GB14.23 GB bf16 transformer
Qwen-Image-2.1-FP8.safetensors7.12 GB14.23 GB bf16 transformer
Qwen-Image-2.1-text_encoder-FP8.safetensors9.39 GB17.5 GB bf16 text_encoder
vae/qwen_image_2.1_vae_bf16.safetensors0.63 GBfp32 vae,用于 unsloth/Qwen-Image-2.1-GGUF

这里所有内容均为 safetensors 而非 pickle,因此加载时不会执行任意代码。需要 diffusers 的 main 分支构建版本:Qwen-Image-2.1 支持是在 0.40 版本之后加入的。


示例

INT8INT8
FP8FP8

🤖 ModelScope  |   🤗 HuggingFace  |   📑 博客  |   🖥️ 演示  |   🫨 Discord  |   💬 WeChat

简介

我们很高兴开源 Qwen-Image-2.1,这是 Qwen 家族中统一的文生图与图像编辑模型。其视觉生成组件仅具有 7B 参数(32 个 Single-Stream DiT 层),即可在生成质量、推理效率和通用性之间取得平衡。

本次发布带来四项核心改进:

  • 紧凑高效:轻量级架构结合混合粒度注意力与前缀 KV 缓存复用,以较低计算成本输出高质量图像。
  • 原生透明,统一创作与编辑:同一模型即可从文本生成普通图像或透明(RGBA)图像、编辑透明图层,并从照片中提取主体。
  • 多样化编辑:最多支持 10 张参考图像,可通过圈选、手绘标注或独立掩码指定局部编辑区域,并保持人物与商品身份的一致性。
  • 真实质感与精细美学:在字体排版、人像布光和细节表现上进一步优化,让结果更具视觉吸引力。

如需了解更多,请查看 GitHub 仓库 和 博客。

快速开始

安装

pip install torch>=2.4.0
pip install transformers>=5.17
pip install git+https://github.com/huggingface/diffusers
pip install accelerate pillow

文生图

import torch
from diffusers import QwenImage21Pipeline

pipe = QwenImage21Pipeline.from_pretrained(
    "Qwen/Qwen-Image-2.1", torch_dtype=torch.bfloat16
).to("cuda")

image = pipe(
    prompt="A neon shop sign that reads \"QWEN IMAGE 2.1\", rainy night, reflections on wet pavement",
    width=2048, height=2048,
    num_inference_steps=40,
    generator=torch.Generator("cuda").manual_seed(42),
).images[0]

image.save("t2i_example.png")

图像编辑

import torch
from PIL import Image
from diffusers import QwenImage21Pipeline

pipe = QwenImage21Pipeline.from_pretrained(
    "Qwen/Qwen-Image-2.1", torch_dtype=torch.bfloat16
).to("cuda")

input_image = Image.open("input.png")

image = pipe(
    prompt="Change the background to a sunset beach",
    image=input_image,
    num_inference_steps=40,
    generator=torch.Generator("cuda").manual_seed(42),
).images[0]

image.save("edit_example.png")

透明图像生成 (RGBA)

请使用透明图像的推荐提示词格式:

image = pipe(
    prompt="This is an RGBA image with transparency. A cute cartoon dragon sticker. The image has alpha channel and the background is transparent.",
    width=2048, height=2048,
    num_inference_steps=40,
    generator=torch.Generator("cuda").manual_seed(42),
).images[0]

image.save("transparent_example.png")

支持的宽高比

aspect_ratios = {
    "1:1":  (2048, 2048),
    "4:3":  (2400, 1792),
    "3:4":  (1792, 2400),
    "3:2":  (2528, 1696),
    "2:3":  (1696, 2528),
    "16:9": (2752, 1536),
    "9:16": (1536, 2752),
}

内存优化

pipe = QwenImage21Pipeline.from_pretrained(
    "Qwen/Qwen-Image-2.1", torch_dtype=torch.bfloat16
)
pipe.enable_model_cpu_offload()

展示

原生透明图像生成

基于六张人像参考生成的合影

文本渲染

许可证

该模型基于 Qwen Research License Agreement 授权。