Instructions to use diffusers/FLUX.2-klein-4B-modular with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use diffusers/FLUX.2-klein-4B-modular with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("diffusers/FLUX.2-klein-4B-modular", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
| library_name: diffusers | |
| # Flux2 Klein 4b Modular repo | |
| This contains mellon config for A single-node Mellon block for the FLUX.2-klein-4B pipeline. | |
| ## How to create a modular repo like this one? | |
| load the pipeline and save it to a new Hub repository: | |
| ```python | |
| from diffusers import ModularPipeline | |
| pipe = ModularPipeline.from_pretrained("black-forest-labs/FLUX.2-klein-4B") | |
| pipe.save_pretrained( | |
| "local/dir", | |
| repo_id="your-username/flux2-klein-auto-blocks", | |
| push_to_hub=True | |
| ) | |
| ``` | |
| ## Generate the Mellon Config | |
| Create and push the Mellon configuration with your desired UI types: | |
| ```python | |
| from diffusers.modular_pipelines.mellon_node_utils import MellonPipelineConfig | |
| mellon_config = MellonPipelineConfig.from_custom_block( | |
| pipe.blocks, | |
| input_types={ | |
| "prompt": "textbox", | |
| "image": "image", | |
| "num_inference_steps": "number", | |
| }, | |
| output_types={ | |
| "images": "image" | |
| } | |
| ) | |
| mellon_config.save( | |
| "local/dir", | |
| repo_id="your-username/flux2-klein-auto-blocks", | |
| push_to_hub=True | |
| ) | |
| ``` | |
| ## Review and Adjust | |
| The generated `mellon_pipeline_config.json` may need adjustments. You can: | |
| - Remove inputs you don't want exposed in the UI | |
| - Add slider ranges for numeric inputs | |
| - Add dropdown options for string inputs | |
| - update default value for numeric inputs | |
| ## Use in Mellon | |
| 1. Drag a **Dynamic Block Node** from the ModularDiffusers section | |
| 2. Enter `diffusers/FLUX.2-klein-4B-modular` and click "LOAD CUSTOM BLOCK" | |
| 3. The node will show your configured inputs (prompt, image, num_inference_steps) and outputs (images) | |
| ## Supported Mellon Types | |
| | Type | Input/Output | Description | | |
| |------|--------------|-------------| | |
| | `image` | Both | Image (PIL Image) | | |
| | `textbox` | Input | Text input | | |
| | `number` | Input | Numeric input | | |
| | `slider` | Input | Slider for numeric values | | |
| | `dropdown` | Input | Dropdown selection | | |
| | `checkbox` | Input | Boolean toggle | | |
| | `text` | Both | Text display | |