Flux.1-Krea-Merged-Schnell (FLUX.1-schnell + FLUX.1-Krea-dev)
The Flux.1-Krea-Merged-Schnell repository features merged parameters that combine two leading image generation models: black-forest-labs/FLUX.1-schnell, renowned for its ultra-fast, precision prompt following and efficient 1β4 step professional image production, and black-forest-labs/FLUX.1-Krea-dev, celebrated for guidance-distilled training, aesthetic curation, and photorealistic output. The resulting unified model empowers users to generate visually striking, high-quality images at remarkable speed, balancing sharp style consistency and realism with creative flexibility, and is fully compatible with the Diffusers libraryβs FluxPipeline for streamlined, accessible text-to-image workflows in both research and creative settings.
| FLUX.1-schnell [4 steps] | FLUX.1-Krea-dev [28 steps] | Flux.1-Krea-Merged-Schnell [28 steps] |
|---|---|---|
| π FS1 |
π Kear1 |
π Schenell1 |
| π FS2 |
π Krea3 |
π Schnell3 |
| π FS3 |
π Krea2 |
π Schnell2 |
prompt : a tiny astronaut hatching from an egg on mars
| FLUX.1-schnell [4 steps] | FLUX.1-Krea-dev [28 steps] | Flux.1-Krea-Merged-Schnell [28 steps] |
|---|---|---|
| π S |
π Kera1 |
π FSS1 |
| π SSS |
π Kera2 |
π FSS2 |
| π SSS1 |
π Kera3 |
π FSS3 |
prompt : a tiny astronaut hatching from an egg on the moon
Sub-Memory-efficient merging code (FLUX.1-schnell + FLUX.1-Krea-dev)
Installing Required Packages
%%capture
!pip install git+https://github.com/huggingface/transformers.git
!pip install git+https://github.com/huggingface/diffusers.git
!pip install git+https://github.com/huggingface/peft.git
!pip install git+https://github.com/huggingface/accelerate.git
!pip install safetensors huggingface_hub hf_xet
hf-login
from huggingface_hub import notebook_login, HfApi
notebook_login()
merge.py
from diffusers import FluxTransformer2DModel
from huggingface_hub import snapshot_download
from accelerate import init_empty_weights
from diffusers.models.model_loading_utils import load_model_dict_into_meta
import safetensors.torch
import glob
import torch
# Initialize model with empty weights
with init_empty_weights():
config = FluxTransformer2DModel.load_config("black-forest-labs/FLUX.1-schnell", subfolder="transformer")
model = FluxTransformer2DModel.from_config(config)
# Download checkpoints
schnell_ckpt = snapshot_download(repo_id="black-forest-labs/FLUX.1-schnell", allow_patterns="transformer/*")
krea_ckpt = snapshot_download(repo_id="black-forest-labs/FLUX.1-Krea-dev", allow_patterns="transformer/*")
# Get sorted shard paths
schnell_shards = sorted(glob.glob(f"{schnell_ckpt}/transformer/*.safetensors"))
krea_shards = sorted(glob.glob(f"{krea_ckpt}/transformer/*.safetensors"))
# Initialize dictionaries for merged and guidance weights
merged_state_dict = {}
guidance_state_dict = {}
# Merge shards
for schnell_shard, krea_shard in zip(schnell_shards, krea_shards):
state_dict_schnell = safetensors.torch.load_file(schnell_shard)
state_dict_krea = safetensors.torch.load_file(krea_shard)
# Process keys from schnell model
for k in list(state_dict_schnell.keys()):
if "guidance" in k:
# Keep guidance weights from schnell model
guidance_state_dict[k] = state_dict_schnell.pop(k)
else:
# Average non-guidance weights if key exists in krea
if k in state_dict_krea:
merged_state_dict[k] = (state_dict_schnell.pop(k) + state_dict_krea.pop(k)) / 2
else:
raise ValueError(f"Key {k} missing in krea shard.")
# Check for residual keys in krea (e.g., extra guidance keys)
for k in list(state_dict_krea.keys()):
if "guidance" in k:
# Skip extra guidance keys in krea
state_dict_krea.pop(k)
else:
raise ValueError(f"Unexpected non-guidance key in krea shard: {k}")
# Verify no unexpected residue
if len(state_dict_schnell) > 0:
raise ValueError(f"Residue in schnell shard: {list(state_dict_schnell.keys())}")
if len(state_dict_krea) > 0:
raise ValueError(f"Residue in krea shard: {list(state_dict_krea.keys())}")
# Combine merged and guidance state dictionaries
merged_state_dict.update(guidance_state_dict)
# Load merged state dictionary into model
load_model_dict_into_meta(model, merged_state_dict)
# Convert to bfloat16 and save
model.to(torch.bfloat16).save_pretrained("merged/transformer")
api = HfApi()
repo_id = "prithivMLmods/Flux.1-Krea-Merged-Schnell"
api.upload_folder(
folder_path="merged/",
path_in_repo=".",
repo_id=repo_id,
repo_type="model",
revision="main"
)
Inference Codeπ§¨
from diffusers import FluxPipeline
import torch
pipeline = FluxPipeline.from_pretrained(
"prithivMLmods/Flux.1-Krea-Merged-Schnell", torch_dtype=torch.bfloat16
).to("cuda")
image = pipeline(
prompt="a tiny astronaut hatching from an egg on the moon",
guidance_scale=3.5,
num_inference_steps=28,
height=1024,
width=1024,
max_sequence_length=512,
generator=torch.manual_seed(0),
).images[0]
image.save("img0.png")
Quick Start with Gradio and Transformersπ€
COMPARATOR : FLUX.1-Dev(Realism) and Flux.1-Krea-Merged-Schnell (FLUX.1-schnell + FLUX.1-Krea-dev)
Installing Required Packages
%%capture
!pip install git+https://github.com/huggingface/transformers.git
!pip install git+https://github.com/huggingface/diffusers.git
!pip install git+https://github.com/huggingface/peft.git
!pip install git+https://github.com/huggingface/accelerate.git
!pip install safetensors huggingface_hub hf_xet
hf-login
from huggingface_hub import notebook_login, HfApi
notebook_login()
Recommended runtime type
@hardware-accelerator : H200
For more information, visit the documentation.
Flux is a suite of state-of-the-art text-to-image generation models based on diffusion transformers, developed by Black Forest Labs. The models are designed for high-quality generative image tasks, including text-to-image, inpainting, outpainting, and advanced structure or depth-controlled workflows. Flux is available through the Hugging Face diffusers library.
For detailed guides, examples, and API refer to:
- Downloads last month
- 14
