Run this model with HF Jobs

Run diffusers/flux2-bnb-4bit-modular on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/diffusers/flux2-bnb-4bit-modular. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/diffusers/flux2-bnb-4bit-modular on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
dn6's picture
dn6 HF Staff
Upload Flux2ModularPipeline (#2)
438f096
|
Raw History Blame Contribute Delete
1.14 kB
metadata
pipeline_tag: text-to-image
library_name: diffusers
tags:
  - modular-diffusers
  - diffusers
  - flux2
  - text-to-image
  - modular-diffusers
  - diffusers
  - flux2
  - text-to-image

Setup

Install the latest version of diffusers

pip install git+https://github.com/huggingface/diffusers.git

Login to your Hugging Face account

hf auth login

How to use

The following code snippet demonstrates how to use the Flux2 modular pipeline with a remote text encoder and a 4bit quantized version of the DiT. It requires approximately 19GB of VRAM to generate an image.

import torch
from diffusers.modular_pipelines.flux2 import ALL_BLOCKS
from diffusers.modular_pipelines import SequentialPipelineBlocks

blocks = SequentialPipelineBlocks.from_blocks_dict(ALL_BLOCKS['remote'])
pipe = blocks.init_pipeline("diffusers/flux2-bnb-4bit-modular")
pipe.load_components(torch_dtype=torch.bfloat16, device_map="cuda")

prompt = "a photo of a cat"
outputs = pipe(prompt=prompt, num_inference_steps=28, output="images")
outputs[0].save("flux2-bnb-modular.png")