README.md
| 1 | --- |
| 2 | base_model: Qwen/Qwen-Image-2.1 |
| 3 | tags: |
| 4 | - fp8 |
| 5 | - int8 |
| 6 | - unsloth |
| 7 | - quantized |
| 8 | - diffusers |
| 9 | - qwen |
| 10 | - image-generation |
| 11 | - image-editing |
| 12 | - rgba |
| 13 | - text-to-image |
| 14 | license: other |
| 15 | license_name: qwen-research |
| 16 | license_link: https://huggingface.co/Qwen/Qwen-Image-2.1/blob/main/LICENSE |
| 17 | language: |
| 18 | - en |
| 19 | - zh |
| 20 | library_name: diffusers |
| 21 | pipeline_tag: text-to-image |
| 22 | widget: |
| 23 | - text: Photorealistic photograph of an old movie theater with faded red seats, peeling walls, and a torn screen. |
| 24 | output: |
| 25 | url: samples/int8_2.png |
| 26 | - text: A rally car speeding across vast desert dunes, throwing a dramatic trail of sand behind it. |
| 27 | output: |
| 28 | url: samples/fp8_1.png |
| 29 | - text: Photorealistic editorial photograph of a woman barista making a latte in a modern, minimalist café on a sunny tropical morning. |
| 30 | output: |
| 31 | url: samples/int8_1.png |
| 32 | - text: A lone astronaut crossing a dark, frozen lake beneath enormous rings stretching across an alien sky. Fine cracks visible under the translucent ice, distant mountains, soft blue twilight, cinematic scale, photorealistic detail. |
| 33 | output: |
| 34 | url: samples/fp8_2.png |
| 35 | --- |
| 36 | # Read our How to [Run Qwen-Image-2.1 Guide!](https://unsloth.ai/docs/models/qwen-image-2.1) 💜 |
| 37 | |
| 38 | This is an FP8 / INT8 quantized version of [Qwen-Image-2.1](https://huggingface.co/Qwen/Qwen-Image-2.1), plus a pre-cast FP8 copy of its Qwen3-VL text encoder. <br> |
| 39 | - For higher quality, you can also run Dynamic FP8 on just 6GB of VRAM via offloading (<2x slower). |
| 40 | - Optimized for efficient inference with reduced memory footprint. Same-seed LPIPS vs the bf16 model (lower is better): 0.064 INT8, 0.112 FP8. INT8 is the shipped scheme. |
| 41 | - In [Unsloth Desktop](https://github.com/unslothai/unsloth) these are used automatically: pick Qwen-Image-2.1 and an INT8 or FP8 precision. |
| 42 | <div> |
| 43 | <div style="display: flex; gap: 5px; align-items: center; "> |
| 44 | <a href="https://github.com/unslothai/unsloth/"> |
| 45 | <img src="https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png" width="133"> |
| 46 | </a> |
| 47 | <a href="https://discord.gg/unsloth"> |
| 48 | <img src="https://github.com/unslothai/unsloth/raw/main/images/Discord%20button.png" width="173"> |
| 49 | </a> |
| 50 | <a href="https://unsloth.ai/docs/models/qwen-image-2.1"> |
| 51 | <img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="143"> |
| 52 | </a> |
| 53 | </div> |
| 54 | </div> |
| 55 | |
| 56 | | file | size | replaces | |
| 57 | |---|---|---| |
| 58 | | `Qwen-Image-2.1-INT8.safetensors` | 7.26 GB | the 14.23 GB bf16 `transformer` | |
| 59 | | `Qwen-Image-2.1-FP8.safetensors` | 7.12 GB | the 14.23 GB bf16 `transformer` | |
| 60 | | `Qwen-Image-2.1-text_encoder-FP8.safetensors` | 9.39 GB | the 17.5 GB bf16 `text_encoder` | |
| 61 | | `vae/qwen_image_2.1_vae_bf16.safetensors` | 0.63 GB | the fp32 `vae`, for [unsloth/Qwen-Image-2.1-GGUF](https://huggingface.co/unsloth/Qwen-Image-2.1-GGUF) | |
| 62 | |
| 63 | Everything here is safetensors rather than a pickle, so loading runs no arbitrary code. Needs a diffusers main build: Qwen-Image-2.1 support postdates the 0.40 release. |
| 64 | |
| 65 | --- |
| 66 | |
| 67 | ### Samples |
| 68 | |
| 69 | <table> |
| 70 | <tr> |
| 71 | <td align="center"><b>INT8</b></td> |
| 72 | <td align="center"><b>INT8</b></td> |
| 73 | </tr> |
| 74 | <tr> |
| 75 | <td><img src="samples/int8_2.png" width="300"></td> |
| 76 | <td><img src="samples/int8_1.png" width="300"></td> |
| 77 | </tr> |
| 78 | <tr> |
| 79 | <td align="center"><b>FP8</b></td> |
| 80 | <td align="center"><b>FP8</b></td> |
| 81 | </tr> |
| 82 | <tr> |
| 83 | <td><img src="samples/fp8_1.png" width="300"></td> |
| 84 | <td><img src="samples/fp8_2.png" width="300"></td> |
| 85 | </tr> |
| 86 | </table> |
| 87 | |
| 88 | --- |
| 89 | |
| 90 | <p align="center"> |
| 91 | <img src="https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-Image/image2.1/logo.png" width="400"/> |
| 92 | </p> |
| 93 | <p align="center"> |
| 94 | 🤖 <a href="https://modelscope.cn/models/Qwen/Qwen-Image-2.1">ModelScope</a> | |
| 95 | 🤗 <a href="https://huggingface.co/Qwen/Qwen-Image-2.1">HuggingFace</a> | |
| 96 | 📑 <a href="https://qwen.ai/blog?id=qwen-image-2.1">Blog</a> | |
| 97 | 🖥️ <a href="https://huggingface.co/spaces/Qwen/Qwen-Image-2.1">Demo</a> | |
| 98 | 🫨 <a href="https://discord.gg/BEYSk3pkSu">Discord</a> | |
| 99 | 💬 <a href="https://huggingface.co/Qwen/Qwen-Image-2.1/blob/main/assets/qr.png">WeChat</a> |
| 100 | </p> |
| 101 | |
| 102 | ## Introduction |
| 103 | |
| 104 | We are excited to open-source **Qwen-Image-2.1**, a unified text-to-image generation and image editing model in the Qwen family. With just **7B parameters in its visual generation component** (32 Single-Stream DiT layers), Qwen-Image-2.1 balances generation quality, inference efficiency, and versatility. |
| 105 | |
| 106 | Four key improvements define this release: |
| 107 | |
| 108 | - **Compact and Efficient**: a lightweight architecture with mixed-granularity attention and prefix KV cache reuse delivers strong image quality at low computational cost. |
| 109 | - **Native Transparency, Unified Creation and Editing**: generate regular or transparent (RGBA) images from text, edit transparent layers, and extract subjects from photographs, all in one model. |
| 110 | - **Versatile Editing**: support up to **10 reference images**, specify local edits via circles, painted annotations, or separate masks, and preserve identity for people and products. |
| 111 | - **Realistic Textures and Refined Aesthetics**: improved typography, portrait lighting, and fine details for more visually compelling results. |
| 112 | |
| 113 | <p align="center"> |
| 114 | <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-01.png" width="100%"/> |
| 115 | </p> |
| 116 | |
| 117 | For more details, see the [GitHub repo](https://github.com/QwenLM/Qwen-Image-2.1) and [Blog](https://qwen.ai/blog?id=qwen-image-2.1). |
| 118 | |
| 119 | ## Quick Start |
| 120 | |
| 121 | ### Installation |
| 122 | |
| 123 | ```bash |
| 124 | pip install torch>=2.4.0 |
| 125 | pip install transformers>=5.17 |
| 126 | pip install git+https://github.com/huggingface/diffusers |
| 127 | pip install accelerate pillow |
| 128 | ``` |
| 129 | |
| 130 | ### Text-to-Image |
| 131 | |
| 132 | ```python |
| 133 | import torch |
| 134 | from diffusers import QwenImage21Pipeline |
| 135 | |
| 136 | pipe = QwenImage21Pipeline.from_pretrained( |
| 137 | "Qwen/Qwen-Image-2.1", torch_dtype=torch.bfloat16 |
| 138 | ).to("cuda") |
| 139 | |
| 140 | image = pipe( |
| 141 | prompt="A neon shop sign that reads \"QWEN IMAGE 2.1\", rainy night, reflections on wet pavement", |
| 142 | width=2048, height=2048, |
| 143 | num_inference_steps=40, |
| 144 | generator=torch.Generator("cuda").manual_seed(42), |
| 145 | ).images[0] |
| 146 | |
| 147 | image.save("t2i_example.png") |
| 148 | ``` |
| 149 | |
| 150 | ### Image Editing |
| 151 | |
| 152 | ```python |
| 153 | import torch |
| 154 | from PIL import Image |
| 155 | from diffusers import QwenImage21Pipeline |
| 156 | |
| 157 | pipe = QwenImage21Pipeline.from_pretrained( |
| 158 | "Qwen/Qwen-Image-2.1", torch_dtype=torch.bfloat16 |
| 159 | ).to("cuda") |
| 160 | |
| 161 | input_image = Image.open("input.png") |
| 162 | |
| 163 | image = pipe( |
| 164 | prompt="Change the background to a sunset beach", |
| 165 | image=input_image, |
| 166 | num_inference_steps=40, |
| 167 | generator=torch.Generator("cuda").manual_seed(42), |
| 168 | ).images[0] |
| 169 | |
| 170 | image.save("edit_example.png") |
| 171 | ``` |
| 172 | |
| 173 | ### Transparent Image Generation (RGBA) |
| 174 | |
| 175 | Use the recommended prompt format for transparent images: |
| 176 | |
| 177 | ```python |
| 178 | image = pipe( |
| 179 | prompt="This is an RGBA image with transparency. A cute cartoon dragon sticker. The image has alpha channel and the background is transparent.", |
| 180 | width=2048, height=2048, |
| 181 | num_inference_steps=40, |
| 182 | generator=torch.Generator("cuda").manual_seed(42), |
| 183 | ).images[0] |
| 184 | |
| 185 | image.save("transparent_example.png") |
| 186 | ``` |
| 187 | |
| 188 | ### Supported Aspect Ratios |
| 189 | |
| 190 | ```python |
| 191 | aspect_ratios = { |
| 192 | "1:1": (2048, 2048), |
| 193 | "4:3": (2400, 1792), |
| 194 | "3:4": (1792, 2400), |
| 195 | "3:2": (2528, 1696), |
| 196 | "2:3": (1696, 2528), |
| 197 | "16:9": (2752, 1536), |
| 198 | "9:16": (1536, 2752), |
| 199 | } |
| 200 | ``` |
| 201 | |
| 202 | ### Memory Optimization |
| 203 | |
| 204 | ```python |
| 205 | pipe = QwenImage21Pipeline.from_pretrained( |
| 206 | "Qwen/Qwen-Image-2.1", torch_dtype=torch.bfloat16 |
| 207 | ) |
| 208 | pipe.enable_model_cpu_offload() |
| 209 | ``` |
| 210 | |
| 211 | ## Showcase |
| 212 | |
| 213 | <p align="center"> |
| 214 | <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-04.png" width="30%"/> |
| 215 | <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-05.png" width="30%"/> |
| 216 | <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-06.png" width="30%"/> |
| 217 | </p> |
| 218 | <p align="center"><em>Native transparent image generation</em></p> |
| 219 | |
| 220 | <p align="center"> |
| 221 | <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-15.png" width="100%"/> |
| 222 | </p> |
| 223 | <p align="center"><em>Group photograph generated from six portrait references</em></p> |
| 224 | |
| 225 | <p align="center"> |
| 226 | <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-43.png" width="48%"/> |
| 227 | <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen-Image/image2.1/images/example-44.png" width="48%"/> |
| 228 | </p> |
| 229 | <p align="center"><em>Text rendering</em></p> |
| 230 | |
| 231 | ## License |
| 232 | |
| 233 | This model is licensed under the [Qwen Research License Agreement](https://huggingface.co/Qwen/Qwen-Image-2.1/blob/main/LICENSE). |
| 234 | |