OzzyGT HF Staff commited on
Commit
464fb1d
·
verified ·
1 Parent(s): 2a45c19

Delete example_unified.py

Browse files
Files changed (1) hide show
  1. example_unified.py +0 -97
example_unified.py DELETED
@@ -1,97 +0,0 @@
1
- """Exercise all three workflows of the unified Ideogram4 AutoBlocks from ONE pipeline instance.
2
-
3
- This is the integration check: t2i / img2img / differential share a single scheduler + components, so we run
4
- them in sequence to confirm there's no state leakage (e.g. begin_index) between workflows.
5
- """
6
-
7
- import sys
8
-
9
- import torch
10
-
11
-
12
- sys.path.insert(0, r"C:\projects\modular_diffusers")
13
-
14
- from sdnq import SDNQConfig # noqa: E402,F401
15
- from sdnq.common import use_torch_compile as triton_is_available # noqa: E402
16
- from sdnq.loader import apply_sdnq_options_to_model # noqa: E402
17
-
18
- import diffusers # noqa: E402
19
- from diffusers.utils import load_image # noqa: E402
20
- from ideogram4_custom_blocks import Ideogram4AutoBlocks # noqa: E402
21
-
22
-
23
- MODEL_ID = "Disty0/Ideogram-4-SDNQ-4bit-dynamic-hadamard"
24
- H = W = 1024
25
- STEPS = 20
26
- SEED = 0
27
- REFERENCE = (
28
- "https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/20240329211129_4024911930.png"
29
- )
30
- CHANGE_MAP = "https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/gradient_mask.png"
31
-
32
- T2I_PROMPT = "a photo of a red apple on a black background, studio lighting, water droplets"
33
- EDIT_PROMPT = "a photo of a snowy mountain landscape at sunset, dramatic clouds, alpenglow on the peaks"
34
-
35
-
36
- def main():
37
- pipe_std = diffusers.Ideogram4Pipeline.from_pretrained(MODEL_ID, torch_dtype=torch.bfloat16)
38
- if triton_is_available and (torch.cuda.is_available() or torch.xpu.is_available()):
39
- pipe_std.transformer = apply_sdnq_options_to_model(pipe_std.transformer, use_quantized_matmul=True)
40
- pipe_std.unconditional_transformer = apply_sdnq_options_to_model(
41
- pipe_std.unconditional_transformer, use_quantized_matmul=True
42
- )
43
- pipe_std.text_encoder = apply_sdnq_options_to_model(pipe_std.text_encoder, use_quantized_matmul=True)
44
-
45
- from diffusers_mm import managed
46
-
47
- pipe_std = managed(pipe_std, strategy="auto", device="cuda")
48
- print(f"diffusers-mm applied strategy: {getattr(pipe_std.mm, 'applied_strategy', None)}")
49
-
50
- pipe = Ideogram4AutoBlocks().init_pipeline()
51
- pipe.update_components(
52
- text_encoder=pipe_std.text_encoder,
53
- tokenizer=pipe_std.tokenizer,
54
- transformer=pipe_std.transformer,
55
- unconditional_transformer=pipe_std.unconditional_transformer,
56
- vae=pipe_std.vae,
57
- scheduler=pipe_std.scheduler,
58
- )
59
- if torch.cuda.is_available():
60
- type(pipe)._execution_device = property(lambda self: torch.device("cuda"))
61
-
62
- reference = load_image(REFERENCE)
63
- change_map = load_image(CHANGE_MAP)
64
- common = {
65
- "height": H,
66
- "width": W,
67
- "num_inference_steps": STEPS,
68
- "guidance_schedule": [7.0] * STEPS,
69
- "output": "images",
70
- }
71
-
72
- # Run in an order that stresses scheduler state: img2img (sets begin_index) -> differential (full schedule)
73
- # -> text2image. If state leaked, t2i/differential would start from a trimmed schedule and look wrong.
74
- print("running img2img...")
75
- pipe(prompt=T2I_PROMPT, image=reference, strength=0.6, generator=torch.manual_seed(SEED), **common)[0].save(
76
- "ideogram4-unified-img2img.png"
77
- )
78
-
79
- print("running differential...")
80
- pipe(
81
- prompt=EDIT_PROMPT,
82
- image=reference,
83
- diffdiff_map=change_map,
84
- generator=torch.manual_seed(SEED),
85
- **common,
86
- )[0].save("ideogram4-unified-diffdiff.png")
87
-
88
- print("running text2image...")
89
- pipe(prompt=T2I_PROMPT, generator=torch.manual_seed(SEED), **common)[0].save("ideogram4-unified-t2i.png")
90
-
91
- if torch.cuda.is_available():
92
- print(f"peak VRAM: {torch.cuda.max_memory_allocated() / 1024**3:.2f} GB")
93
- print("done: saved ideogram4-unified-{img2img,diffdiff,t2i}.png")
94
-
95
-
96
- if __name__ == "__main__":
97
- main()