VOOZH about

URL: https://huggingface.co/prithivMLmods/Flux.1-Krea-Merged-Dev

⇱ prithivMLmods/Flux.1-Krea-Merged-Dev Β· Hugging Face


Flux.1-Krea-Merged-Dev (Flux.1-Dev + Flux.1-Krea-Dev)

The Flux.1-Krea-Merged-Dev repository contains merged parameters combining two advanced image generation models: black-forest-labs/FLUX.1-dev and black-forest-labs/FLUX.1-Krea-dev. This merged model integrates the capabilities of the rectified flow transformer FLUX.1-dev, known for competitive prompt following and high-quality outputs, with FLUX.1-Krea-dev, a guidance distilled model emphasizing aesthetics and photorealism. The result is a unified model that balances quality, aesthetic control, and efficiency for text-to-image generation tasks. The repository includes instructions for loading, merging, and using the fused parameters via the Diffusers library, enabling users to generate images from text prompts through the FluxPipeline with enhanced performance and visual quality. This merge facilitates leveraging strengths from both base models in a single, accessible implementation for research and creative workflows.

prompt : a tiny astronaut hatching from an egg on the moon


FLUX.1-dev (28 steps) FLUX.1-Krea-dev (28 steps) Flux.1-Krea-Merged-Dev (28 steps)
πŸ‘ Sample 1
πŸ‘ Sample 1
πŸ‘ Sample 1
πŸ‘ Sample 2
πŸ‘ Sample 2
πŸ‘ Sample 2

prompt : cute anime illustration of a colorful sushi platter featuring nigiri, maki rolls, sashimi, and wasabi on a wooden tray with decorative two chopsticks.


Sub-Memory-efficient merging code (Flux.1-Dev + 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-dev", subfolder="transformer")
 model = FluxTransformer2DModel.from_config(config)

# Download checkpoints
dev_ckpt = snapshot_download(repo_id="black-forest-labs/FLUX.1-dev", allow_patterns="transformer/*")
krea_ckpt = snapshot_download(repo_id="black-forest-labs/FLUX.1-Krea-dev", allow_patterns="transformer/*")

# Get sorted shard paths
dev_shards = sorted(glob.glob(f"{dev_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 dev_shard, krea_shard in zip(dev_shards, krea_shards):
 state_dict_dev = safetensors.torch.load_file(dev_shard)
 state_dict_krea = safetensors.torch.load_file(krea_shard)

 # Process keys from dev model
 for k in list(state_dict_dev.keys()):
 if "guidance" in k:
 # Keep guidance weights from dev model
 guidance_state_dict[k] = state_dict_dev.pop(k)
 else:
 # Average non-guidance weights if key exists in krea
 if k in state_dict_krea:
 merged_state_dict[k] = (state_dict_dev.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_dev) > 0:
 raise ValueError(f"Residue in dev shard: {list(state_dict_dev.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-Dev"

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-Dev", 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-Dev (Flux.1-Dev + 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
24

Model tree for prithivMLmods/Flux.1-Krea-Merged-Dev

Collections including prithivMLmods/Flux.1-Krea-Merged-Dev