deep1401 commited on
Commit
7527d53
·
verified ·
1 Parent(s): 40f7c5c

Upload usage.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. usage.py +26 -0
usage.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Generate an image with the INT8 W8A8 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.json).
8
+ """
9
+ import sys
10
+ import torch
11
+ from ideogram4 import Ideogram4Pipeline, Ideogram4PipelineConfig
12
+ from safetensors_loader import load_int8
13
+
14
+ WEIGHTS = "ideogram4-int8-w8a8.safetensors"
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
+ sw, pr = load_int8(pipe, WEIGHTS)
22
+ print(f"loaded INT8: {sw} quantized + {pr} protected linears")
23
+
24
+ img = pipe(prompt, num_steps=48, height=1024, width=1024, seed=1000)[0]
25
+ img.save("out.png")
26
+ print("saved out.png")