Diffusers
Safetensors
How to use from the
Use from the
Diffusers library
pip install -U diffusers transformers accelerate
import torch
from diffusers import DiffusionPipeline

# switch to "mps" for apple devices
pipe = DiffusionPipeline.from_pretrained("hf-internal-testing/flux.1-dev-int8-pkg", dtype=torch.bfloat16, device_map="cuda")

prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
image = pipe(prompt).images[0]

Running Flux.1-dev under 12GBs

This repository contains the mixed int8 params for the T5 and transformer of Flux.1-Dev.

This is how the checkpoints were obtained:

import torch
from diffusers import BitsAndBytesConfig, FluxTransformer2DModel
from transformers import T5EncoderModel, BitsAndBytesConfig
from huggingface_hub import create_repo, upload_folder
import tempfile

model_id = "black-forest-labs/FLUX.1-dev"

config = BitsAndBytesConfig(load_in_8bit=True)
transformer = FluxTransformer2DModel.from_pretrained(
    model_id, subfolder="transformer", quantization_config=config, torch_dtype=torch.float16
)

config = BitsAndBytesConfig(load_in_8bit=True)
t5 = T5EncoderModel.from_pretrained(
    model_id, subfolder="text_encoder_2", quantization_config=config, torch_dtype=torch.float16
)

repo_id = create_repo("sayakpaul/flux.1-dev-int8-pkg", exist_ok=True).repo_id

with tempfile.TemporaryDirectory() as tmpdirname:
    transformer.save_pretrained(tmpdirname)
    upload_folder(repo_id=repo_id, folder_path=tmpdirname, path_in_repo="transformer")

with tempfile.TemporaryDirectory() as tmpdirname:
    t5.save_pretrained(tmpdirname)
    upload_folder(repo_id=repo_id, folder_path=tmpdirname, path_in_repo="text_encoder_2")

Respective diffusers PR: https://github.com/huggingface/diffusers/pull/9213/.

The checkpoints of this repository were optimized to run on a T4 notebook. More specifically, the compute datatype of the quantized checkpoints was kept to FP16. In practice, if you have a GPU card that supports BF16, you should change the compute datatype to BF16 (bnb_4bit_compute_dtype).

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support