Instructions to use OzzyGT/ideogram4_custom_blocks with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use OzzyGT/ideogram4_custom_blocks with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("OzzyGT/ideogram4_custom_blocks", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Delete example_differential.py
Browse files- example_differential.py +0 -94
example_differential.py
DELETED
|
@@ -1,94 +0,0 @@
|
|
| 1 |
-
"""Run the Ideogram4 Differential Diffusion custom blocks on the SDNQ 4-bit checkpoint with diffusers-mm.
|
| 2 |
-
|
| 3 |
-
Same component-injection pattern as example_img2img.py: load the standard SDNQ-4bit pipeline (quantized
|
| 4 |
-
components + diffusers-mm memory management), build `Ideogram4DiffDiffAutoBlocks`, inject the managed modules.
|
| 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 (registers sdnq into diffusers/transformers)
|
| 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 Ideogram4DiffDiffAutoBlocks # noqa: E402
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
MODEL_ID = "Disty0/Ideogram-4-SDNQ-4bit-dynamic-hadamard"
|
| 24 |
-
HEIGHT = 1024
|
| 25 |
-
WIDTH = 1024
|
| 26 |
-
STEPS = 20
|
| 27 |
-
SEED = 0
|
| 28 |
-
# exx8 differential-diffusion test assets (grayscale gradient change map + its reference image).
|
| 29 |
-
REFERENCE = (
|
| 30 |
-
"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/20240329211129_4024911930.png"
|
| 31 |
-
)
|
| 32 |
-
CHANGE_MAP = "https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/gradient_mask.png"
|
| 33 |
-
|
| 34 |
-
PROMPT = "a photo of a snowy mountain landscape at sunset, dramatic clouds, alpenglow on the peaks"
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
def main():
|
| 38 |
-
pipe_std = diffusers.Ideogram4Pipeline.from_pretrained(MODEL_ID, torch_dtype=torch.bfloat16)
|
| 39 |
-
|
| 40 |
-
if triton_is_available and (torch.cuda.is_available() or torch.xpu.is_available()):
|
| 41 |
-
pipe_std.transformer = apply_sdnq_options_to_model(pipe_std.transformer, use_quantized_matmul=True)
|
| 42 |
-
pipe_std.unconditional_transformer = apply_sdnq_options_to_model(
|
| 43 |
-
pipe_std.unconditional_transformer, use_quantized_matmul=True
|
| 44 |
-
)
|
| 45 |
-
pipe_std.text_encoder = apply_sdnq_options_to_model(pipe_std.text_encoder, use_quantized_matmul=True)
|
| 46 |
-
|
| 47 |
-
from diffusers_mm import managed
|
| 48 |
-
|
| 49 |
-
pipe_std = managed(pipe_std, strategy="auto", device="cuda")
|
| 50 |
-
print(f"diffusers-mm applied strategy: {getattr(pipe_std.mm, 'applied_strategy', None)}")
|
| 51 |
-
|
| 52 |
-
pipe = Ideogram4DiffDiffAutoBlocks().init_pipeline()
|
| 53 |
-
pipe.update_components(
|
| 54 |
-
text_encoder=pipe_std.text_encoder,
|
| 55 |
-
tokenizer=pipe_std.tokenizer,
|
| 56 |
-
transformer=pipe_std.transformer,
|
| 57 |
-
unconditional_transformer=pipe_std.unconditional_transformer,
|
| 58 |
-
vae=pipe_std.vae,
|
| 59 |
-
scheduler=pipe_std.scheduler,
|
| 60 |
-
)
|
| 61 |
-
if torch.cuda.is_available():
|
| 62 |
-
type(pipe)._execution_device = property(lambda self: torch.device("cuda"))
|
| 63 |
-
print("modular execution device:", pipe._execution_device)
|
| 64 |
-
|
| 65 |
-
reference = load_image(REFERENCE)
|
| 66 |
-
change_map = load_image(CHANGE_MAP)
|
| 67 |
-
|
| 68 |
-
if torch.cuda.is_available():
|
| 69 |
-
torch.cuda.reset_peak_memory_stats()
|
| 70 |
-
|
| 71 |
-
images = pipe(
|
| 72 |
-
prompt=PROMPT,
|
| 73 |
-
image=reference,
|
| 74 |
-
diffdiff_map=change_map,
|
| 75 |
-
height=HEIGHT,
|
| 76 |
-
width=WIDTH,
|
| 77 |
-
num_inference_steps=STEPS,
|
| 78 |
-
guidance_schedule=[7.0] * STEPS,
|
| 79 |
-
generator=torch.manual_seed(SEED),
|
| 80 |
-
output="images",
|
| 81 |
-
)[0]
|
| 82 |
-
images.save("ideogram4-modular-diffdiff.png")
|
| 83 |
-
print("saved ideogram4-modular-diffdiff.png")
|
| 84 |
-
|
| 85 |
-
# Save the resized reference/map next to the output for side-by-side polarity inspection.
|
| 86 |
-
reference.resize((WIDTH, HEIGHT)).save("ideogram4-diffdiff-reference.png")
|
| 87 |
-
change_map.resize((WIDTH, HEIGHT)).save("ideogram4-diffdiff-map.png")
|
| 88 |
-
|
| 89 |
-
if torch.cuda.is_available():
|
| 90 |
-
print(f"peak VRAM: {torch.cuda.max_memory_allocated() / 1024**3:.2f} GB")
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
if __name__ == "__main__":
|
| 94 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|