Created
April 7, 2025 17:16
-
-
Save DN6/7fcdd50610285ae375ecd3f3d4e740ff to your computer and use it in GitHub Desktop.
GGUF + Torch Compile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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