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-2512-SDNQ-4bit-dynamic", 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
17prompt = '''A 20-year-old East Asian girl with delicate, charming features and large, bright brown eyes—expressive and lively, with a cheerful or subtly smiling expression. Her naturally wavy long hair is either loose or tied in twin ponytails. She has fair skin and light makeup accentuating her youthful freshness. She wears a modern, cute dress or relaxed outfit in bright, soft colors—lightweight fabric, minimalist cut. She stands indoors at an anime convention, surrounded by banners, posters, or stalls. Lighting is typical indoor illumination—no staged lighting—and the image resembles a casual iPhone snapshot: unpretentious composition, yet brimming with vivid, fresh, youthful charm.'''
18
19negative_prompt = "低分辨率,低画质,肢体畸形,手指畸形,画面过饱和,蜡像感,人脸无细节,过度光滑,画面具有AI感。构图混乱。文字模糊,扭曲。"
20
21# Generate with different aspect ratios
22aspect_ratios = {
23 "1:1": (1328, 1328),
24 "16:9": (1664, 928),
25 "9:16": (928, 1664),
26 "4:3": (1472, 1104),
27 "3:4": (1104, 1472),
28 "3:2": (1584, 1056),
29 "2:3": (1056, 1584),
30}
31
32width, height = aspect_ratios["16:9"]
33
34image = pipe(
35 prompt=prompt,
36 negative_prompt=negative_prompt,
37 width=width,
38 height=height,
39 num_inference_steps=50,
40 true_cfg_scale=4.0,
41 generator=torch.Generator(device="cpu").manual_seed(42)
42).images[0]
43
44image.save("qwen-image-2512-sdnq-4bit-dynamic.png")| Quantization | Model Size | Visualization |
|---|---|---|
| Original BF16 | 40.9 GB | ![]() |
| SDNQ 4 Bit | 12.0 GB | ![]() |