--- license: apache-2.0 base_model: - Qwen/Qwen-Image base_model_relation: quantized library_name: diffusers tags: - sdnq - qwen_image - 4-bit --- 4 bit (UINT4 with SVD rank 32) quantization of [Qwen/Qwen-Image](https://huggingface.co/Qwen/Qwen-Image) using [SDNQ](https://github.com/vladmandic/sdnext/wiki/SDNQ-Quantization). Usage: ``` pip install git+https://github.com/Disty0/sdnq ``` ```py import torch import diffusers from sdnq import SDNQConfig # import sdnq to register it into diffusers and transformers pipe = diffusers.QwenImagePipeline.from_pretrained("Disty0/Qwen-Image-SDNQ-uint4-svd-r32", torch_dtype=torch.bfloat16) pipe.enable_model_cpu_offload() positive_magic = { "en": ", Ultra HD, 4K, cinematic composition.", # for english prompt "zh": ", 超清,4K,电影级构图." # for chinese prompt } # Generate image prompt = '''A coffee shop entrance features a chalkboard sign reading "Qwen Coffee 😊 $2 per cup," with a neon light beside it displaying "通义千问". Next to it hangs a poster showing a beautiful Chinese woman, and beneath the poster is written "π≈3.1415926-53589793-23846264-33832795-02384197". Ultra HD, 4K, cinematic composition''' negative_prompt = " " # using an empty string if you do not have specific concept to remove # Generate with different aspect ratios aspect_ratios = { "1:1": (1328, 1328), "16:9": (1664, 928), "9:16": (928, 1664), "4:3": (1472, 1140), "3:4": (1140, 1472), "3:2": (1584, 1056), "2:3": (1056, 1584), } width, height = aspect_ratios["16:9"] image = pipe( prompt=prompt + positive_magic["en"], negative_prompt=negative_prompt, width=width, height=height, num_inference_steps=50, true_cfg_scale=4.0, generator=torch.Generator(device="cpu").manual_seed(42) ).images[0] image.save("qwen-image-sdnq-uint4-svd-r32.png") ``` Original BF16 vs SDNQ quantization comparison: | Quantization | Model Size | Visualization | | --- | --- | --- | | Original BF16 | 40.9 GB | ![Original BF16](https://cdn-uploads.huggingface.co/production/uploads/6456af6195082f722d178522/XJcsK26_h5Y2eGhPzzGiA.png) | | SDNQ UINT4 | 11.6 GB | ![SDNQ UINT4](https://cdn-uploads.huggingface.co/production/uploads/6456af6195082f722d178522/bn3WPyxg55n9Sm7v1aPg4.png) |