|
--- |
|
library_name: diffusers |
|
license: other |
|
license_name: flux-1-dev-non-commercial-license |
|
license_link: LICENSE.md |
|
--- |
|
|
|
## To run |
|
|
|
> [!TIP] |
|
> Check out [sayakpaul/flux.1-dev-nf4-pkg](https://huggingface.co/sayakpaul/flux.1-dev-nf4-pkg) that shows how to run this checkpoint along with an NF4 T5 in a free-tier Colab Notebook. |
|
|
|
Be mindful of the license of Flux.1-Dev here. |
|
|
|
Make sure you have the latest versions of `bitsandbytes` and `accelerate` installed. |
|
|
|
And then install `diffusers` from [this PR](https://github.com/huggingface/diffusers/pull/9213/): |
|
|
|
```bash |
|
pip install git+https://github.com/huggingface/diffusers@c795c82df39620e2576ccda765b6e67e849c36e7 |
|
``` |
|
|
|
```python |
|
import torch |
|
from diffusers import FluxTransformer2DModel, FluxPipeline |
|
|
|
model_id = "black-forest-labs/FLUX.1-dev" |
|
nf4_id = "sayakpaul/flux.1-dev-nf4-with-bnb-integration" |
|
model_nf4 = FluxTransformer2DModel.from_pretrained(nf4_id, torch_dtype=torch.bfloat16) |
|
print(model_nf4.dtype) |
|
print(model_nf4.config.quantization_config) |
|
|
|
pipe = FluxPipeline.from_pretrained(model_id, transformer=model_nf4, torch_dtype=torch.bfloat16) |
|
pipe.enable_model_cpu_offload() |
|
|
|
prompt = "A mystic cat with a sign that says hello world!" |
|
image = pipe(prompt, guidance_scale=3.5, num_inference_steps=50, generator=torch.manual_seed(0)).images[0] |
|
image.save("flux-nf4-dev-loaded.png") |
|
``` |
|
|
|
![image/png](https://cdn-uploads.huggingface.co/production/uploads/5f7fbd813e94f16a85448745/lBpug2CXhXU5_GEgjl-cJ.png) |
|
|