Views
No views yet


pip install -U torchaopip install git+https://github.com/huggingface/diffusers.git@torchao-int4-serialization1from diffusers import FluxPipeline
2
3pipe = FluxPipeline.from_pretrained(
4 "diffusers/FLUX.1-dev-torchao-int4",
5 torch_dtype=torch.bfloat16,
6 use_safetensors=False,
7 device_map="balanced"
8)
9
10prompt = "Baroque style, a lavish palace interior with ornate gilded ceilings, intricate tapestries, and dramatic lighting over a grand staircase."
11
12pipe_kwargs = {
13 "prompt": prompt,
14 "height": 1024,
15 "width": 1024,
16 "guidance_scale": 3.5,
17 "num_inference_steps": 50,
18 "max_sequence_length": 512,
19}
20
21image = pipe(
22 **pipe_kwargs, generator=torch.manual_seed(0),
23).images[0]
24
25image.save("flux.png")1
2import torch
3from diffusers import FluxPipeline
4from diffusers.quantizers import PipelineQuantizationConfig
5from diffusers import TorchAoConfig as DiffusersTorchAoConfig
6from transformers import TorchAoConfig as TransformersTorchAoConfig
7
8pipeline_quant_config = PipelineQuantizationConfig(
9 quant_mapping={
10 "transformer": DiffusersTorchAoConfig("int4_weight_only"),
11 "text_encoder_2": TransformersTorchAoConfig("int4_weight_only"),
12 }
13)
14
15pipe = FluxPipeline.from_pretrained(
16 "black-forest-labs/FLUX.1-dev",
17 quantization_config=pipeline_quant_config,
18 torch_dtype=torch.bfloat16,
19 device_map="balanced"
20)
21
22# safe_serialization set to `False` as we can't save torchao quantized model to safetensors format
23pipe.save_pretrained("FLUX.1-dev-torchao-int4", safe_serialization=False)