---
title: flux2-modular
canonical_url: "https://www.modelscope.cn/models/hf-diffusers/flux2-modular"
md_url: "https://www.modelscope.cn/models/hf-diffusers/flux2-modular.md"
repository: hf-diffusers/flux2-modular
last_updated: 2025-12-11
pipeline_tag: text-to-image-synthesis
tasks:
  - text-to-image-synthesis
library_name:
  - pytorch
frameworks:
  - pytorch
downloads: 45
stars: 0
---

# flux2-modular

> flux2-modular - hf-diffusers 在 ModelScope 开源的模型。Install the latest version of diffusers

- **Repository**: hf-diffusers/flux2-modular
- **Tasks**: text-to-image-synthesis
- **Downloads**: 45
- **Stars**: 0
- **Last updated**: 2025-12-11

Source: https://www.modelscope.cn/models/hf-diffusers/flux2-modular

---

## Setup

Install the latest version of `diffusers`

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

Login to your Hugging Face account

```shell
hf auth login
```

## How to use

The following code snippet demonstrates how to use the [Flux2](https://huggingface.co/black-forest-labs/FLUX.2-dev) modular pipeline with a remote text encoder and group offloading. It requires approximately 8GB of VRAM and 64GB of CPU RAM to generate an image.

```python
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-modular")
pipe.load_components(torch_dtype=torch.bfloat16, device_map="cpu")
pipe.vae.to("cuda")
pipe.transformer.enable_group_offload(
    offload_type="leaf_level",
    onload_device=torch.device("cuda"),
    offload_device=torch.device("cpu"),
    use_stream=True,
    low_cpu_mem_usage=True,
)

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