Skip to content

Instantly share code, notes, and snippets.

@DN6
Created April 7, 2025 17:16
Show Gist options
  • Save DN6/7fcdd50610285ae375ecd3f3d4e740ff to your computer and use it in GitHub Desktop.
Save DN6/7fcdd50610285ae375ecd3f3d4e740ff to your computer and use it in GitHub Desktop.
GGUF + Torch Compile
# Setup
# ----------------------
# Install torch from nightly
# `pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu126`
# Install diffusers
# `pip install diffusers`
import torch
from diffusers import FluxPipeline, FluxTransformer2DModel, GGUFQuantizationConfig
ckpt_path = (
"https://huggingface.co/city96/FLUX.1-dev-gguf/blob/main/flux1-dev-Q2_K.gguf"
)
transformer = FluxTransformer2DModel.from_single_file(
ckpt_path,
quantization_config=GGUFQuantizationConfig(compute_dtype=torch.bfloat16),
torch_dtype=torch.bfloat16,
)
transformer = torch.compile(transformer, mode="max-autotune", fullgraph=True)
pipe = FluxPipeline.from_pretrained(
"black-forest-labs/FLUX.1-dev",
transformer=transformer,
generator=torch.manual_seed(0),
torch_dtype=torch.bfloat16,
)
pipe.to("cuda")
prompt = "A cat holding a sign that says hello world"
image = pipe(prompt=prompt).images[0]
image.save("flux-gguf-compile.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment