---
title: FLUX.1-dev-bnb-4bit
canonical_url: "https://www.modelscope.cn/models/hf-diffusers/FLUX.1-dev-bnb-4bit"
md_url: "https://www.modelscope.cn/models/hf-diffusers/FLUX.1-dev-bnb-4bit.md"
repository: hf-diffusers/FLUX.1-dev-bnb-4bit
last_updated: 2025-05-21
pipeline_tag: text-to-image-synthesis
tasks:
  - text-to-image-synthesis
base_model:
  - black-forest-labs/FLUX.1-dev
base_model_relation: quantized
parameters: 9.4B
tensor_type:
  - U8
  - F32
  - BF16
library_name:
  - pytorch
  - transformer
  - safetensors
  - diffusers
frameworks:
  - pytorch
downloads: 419
stars: 1
tags:
  - quantization
---

# FLUX.1-dev-bnb-4bit

> FLUX.1-dev-bnb-4bit - hf-diffusers 在 ModelScope 开源的模型。Visual comparison of Flux-dev model outputs using BF16 and BnB 8-bit quantization

hf-diffusers/FLUX.1-dev-bnb-4bit 是 ModelScope 魔搭社区上的 9.4B 参数text-to-image-synthesis模型，基于 black-forest-labs/FLUX.1-dev 构建。

- **Repository**: hf-diffusers/FLUX.1-dev-bnb-4bit
- **Tasks**: text-to-image-synthesis
- **Parameters**: 9.4B
- **Base model**: black-forest-labs/FLUX.1-dev
- **Tags**: quantization
- **Downloads**: 419
- **Stars**: 1
- **Last updated**: 2025-05-21

Source: https://www.modelscope.cn/models/hf-diffusers/FLUX.1-dev-bnb-4bit

---

# Visual comparison of Flux-dev model outputs using BF16 and BnB 8-bit quantization

<td style="text-align: center;">
  BF16<br>
  <medium-zoom background="rgba(0,0,0,.7)"><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/quantization-backends-diffusers/combined_flux-dev_bf16_combined.png" alt="Flux-dev output with BF16: Baroque, Futurist, Noir styles"></medium-zoom>
</td>
<td style="text-align: center;">
  BnB 4-bit<br>
  <medium-zoom background="rgba(0,0,0,.7)"><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/quantization-backends-diffusers/combined_flux-dev_bnb_4bit_combined.png" alt="Flux-dev output with BnB 4-bit: Baroque, Futurist, Noir styles"></medium-zoom>
</td>


# Usage with Diffusers

To use this quantized FLUX.1 [dev] checkpoint, you need to install the 🧨 diffusers and bitsandbytes library:

```
pip install -U diffusers
pip install -U bitsandbytes
```

After installing the required library, you can run the following script: 

```python
from diffusers import FluxPipeline

pipe = FluxPipeline.from_pretrained(
    "diffusers/FLUX.1-dev-bnb-4bit",
    torch_dtype=torch.bfloat16
)
pipe.to("cuda")

prompt = "Baroque style, a lavish palace interior with ornate gilded ceilings, intricate tapestries, and dramatic lighting over a grand staircase."

pipe_kwargs = {
    "prompt": prompt,
    "height": 1024,
    "width": 1024,
    "guidance_scale": 3.5,
    "num_inference_steps": 50,
    "max_sequence_length": 512,
}

image = pipe(
    **pipe_kwargs, generator=torch.manual_seed(0),
).images[0]

image.save("flux.png")
```


# How to generate this quantized checkpoint ? 

This checkpoint was created with the following script using "black-forest-labs/FLUX.1-dev" checkpoint:

```python

import torch
from diffusers import FluxPipeline
from diffusers import BitsAndBytesConfig as DiffusersBitsAndBytesConfig
from diffusers.quantizers import PipelineQuantizationConfig
from transformers import BitsAndBytesConfig as TransformersBitsAndBytesConfig

pipeline_quant_config = PipelineQuantizationConfig(
    quant_mapping={
        "transformer": DiffusersBitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16),
        "text_encoder_2": TransformersBitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16),
    }
)

pipe = FluxPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-dev",
    quantization_config=pipeline_quant_config,
    torch_dtype=torch.bfloat16
)

pipe.save_pretrained("FLUX.1-dev-bnb-4bit")
```
