Views
No views yet
pip install sdnq>=0.1.91import os
2import json
3import requests
4
5import torch
6import diffusers
7from sdnq import SDNQConfig # import sdnq to register it into diffusers and transformers
8from sdnq.common import use_torch_compile as triton_is_available
9from sdnq.loader import apply_sdnq_options_to_model
10
11pipe = diffusers.Ideogram4Pipeline.from_pretrained("Disty0/Ideogram-4-SDNQ-4bit-dynamic-hadamard", torch_dtype=torch.bfloat16)
12
13# Enable INT8 and FP8 MatMul for AMD, Intel ARC and Nvidia GPUs:
14if triton_is_available and (torch.cuda.is_available() or torch.xpu.is_available()):
15 pipe.transformer = apply_sdnq_options_to_model(pipe.transformer, use_quantized_matmul=True)
16 pipe.unconditional_transformer = apply_sdnq_options_to_model(pipe.unconditional_transformer, use_quantized_matmul=True)
17 pipe.text_encoder = apply_sdnq_options_to_model(pipe.text_encoder, use_quantized_matmul=True)
18 # pipe.transformer = torch.compile(pipe.transformer) # optional for faster speeds
19 # pipe.unconditional_transformer = torch.compile(pipe.unconditional_transformer) # optional for faster speeds
20
21pipe.enable_model_cpu_offload()
22
23# Expand the prompt into a structured JSON caption with Ideogram's free hosted magic-prompt API.
24# Get a key at https://developer.ideogram.ai/ (set IDEOGRAM_API_KEY).
25resp = requests.post(
26 "https://api.ideogram.ai/v1/ideogram-v4/magic-prompt",
27 headers={"Api-Key": "your_ideogram_api_key"},
28 json={"text_prompt": "a ginger cat wearing a tiny wizard hat reading a spellbook", "aspect_ratio": "1x1"},
29).json()
30caption = json.dumps(resp["json_prompt"]) # or: token="hf_xxxxxxxxx", token is needed as the repo is gated
31
32# Pass the caption straight to the pipeline (no prompt_upsampling — it's already upsampled).
33image = pipe(
34 caption,
35 height=1024, # model supports up to 2048
36 width=1024, # model supports up to 2048
37 generator=torch.manual_seed(0),
38).images[0]
39image.save("ideogram4-sdnq-4bit-dynamic-hadamard.png")