Upload usage.py with huggingface_hub
Browse files
usage.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Generate an image with the Q4_K Ideogram 4 DiT.
|
| 2 |
+
|
| 3 |
+
python download_deps.py # one time (gated base-repo access required)
|
| 4 |
+
python usage.py "a poster that says HELLO"
|
| 5 |
+
|
| 6 |
+
Memory: the FP8 pipeline is large; on a 24 GB card you may need an offload/
|
| 7 |
+
sequential-load recipe (see recipe-q8_0.json).
|
| 8 |
+
"""
|
| 9 |
+
import sys
|
| 10 |
+
import torch
|
| 11 |
+
from ideogram4 import Ideogram4Pipeline, Ideogram4PipelineConfig
|
| 12 |
+
from gguf_loader import load_gguf_tensors, swap_branch
|
| 13 |
+
|
| 14 |
+
GGUF = "ideogram4-q8_0.gguf"
|
| 15 |
+
prompt = sys.argv[1] if len(sys.argv) > 1 else 'a storefront sign that says "FRESH COFFEE"'
|
| 16 |
+
|
| 17 |
+
pipe = Ideogram4Pipeline.from_pretrained(
|
| 18 |
+
config=Ideogram4PipelineConfig(weights_repo="ideogram-ai/ideogram-4-fp8"),
|
| 19 |
+
device="cuda", dtype=torch.bfloat16)
|
| 20 |
+
|
| 21 |
+
g = load_gguf_tensors(GGUF)
|
| 22 |
+
print("linears swapped:",
|
| 23 |
+
swap_branch(pipe.conditional_transformer, g, "cond"),
|
| 24 |
+
swap_branch(pipe.unconditional_transformer, g, "uncond"))
|
| 25 |
+
|
| 26 |
+
img = pipe(prompt, num_steps=48, height=1024, width=1024, seed=1000)[0]
|
| 27 |
+
img.save("out.png")
|
| 28 |
+
print("saved out.png")
|