Views
No views yet
pip install sdnq1import torch
2import diffusers
3from sdnq import SDNQConfig # import sdnq to register it into diffusers and transformers
4from sdnq.common import use_torch_compile as triton_is_available
5from sdnq.loader import apply_sdnq_options_to_model
6
7pipe = diffusers.QwenImagePipeline.from_pretrained("Disty0/Qwen-Image-SDNQ-uint4-svd-r32", torch_dtype=torch.bfloat16)
8
9# Enable INT8 MatMul for AMD, Intel ARC and Nvidia GPUs:
10if triton_is_available and (torch.cuda.is_available() or torch.xpu.is_available()):
11 pipe.transformer = apply_sdnq_options_to_model(pipe.transformer, use_quantized_matmul=True)
12 pipe.text_encoder = apply_sdnq_options_to_model(pipe.text_encoder, use_quantized_matmul=True)
13 # pipe.transformer = torch.compile(pipe.transformer) # optional for faster speeds
14
15pipe.enable_model_cpu_offload()
16
17positive_magic = {
18 "en": ", Ultra HD, 4K, cinematic composition.", # for english prompt
19 "zh": ", 超清,4K,电影级构图." # for chinese prompt
20}
21
22# Generate image
23prompt = '''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'''
24
25negative_prompt = " " # using an empty string if you do not have specific concept to remove
26
27
28# Generate with different aspect ratios
29aspect_ratios = {
30 "1:1": (1328, 1328),
31 "16:9": (1664, 928),
32 "9:16": (928, 1664),
33 "4:3": (1472, 1140),
34 "3:4": (1140, 1472),
35 "3:2": (1584, 1056),
36 "2:3": (1056, 1584),
37}
38
39width, height = aspect_ratios["16:9"]
40
41image = pipe(
42 prompt=prompt + positive_magic["en"],
43 negative_prompt=negative_prompt,
44 width=width,
45 height=height,
46 num_inference_steps=50,
47 true_cfg_scale=4.0,
48 generator=torch.Generator(device="cpu").manual_seed(42)
49).images[0]
50
51image.save("qwen-image-sdnq-uint4-svd-r32.png")| Quantization | Model Size | Visualization |
|---|---|---|
| Original BF16 | 40.9 GB | ![]() |
| SDNQ UINT4 | 11.6 GB | ![]() |