Instructions to use diffusers-modular/krea2-edit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use diffusers-modular/krea2-edit with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("diffusers-modular/krea2-edit", torch_dtype=torch.bfloat16, device_map="cuda") prompt = "Turn this cat into a dog" input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = pipe(image=input_image, prompt=prompt).images[0] - Notebooks
- Google Colab
- Kaggle
import torch
from diffusers import DiffusionPipeline
from diffusers.utils import load_image
# switch to "mps" for apple devices
pipe = DiffusionPipeline.from_pretrained("diffusers-modular/krea2-edit", torch_dtype=torch.bfloat16, device_map="cuda")
prompt = "Turn this cat into a dog"
input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png")
image = pipe(image=input_image, prompt=prompt).images[0]Krea 2 reference-image edit β Modular Diffusers blocks
Custom Modular Diffusers
blocks that reproduce the ostris/Krea2OstrisEdit
reference-image ("edit") workflow for Krea 2, loadable as remote code on top of stock diffusers.
import torch
from transformers import Qwen3VLProcessor
from diffusers import ClassifierFreeGuidance
from diffusers.modular_pipelines import ModularPipelineBlocks
blocks = ModularPipelineBlocks.from_pretrained("diffusers-modular/krea2-edit", trust_remote_code=True)
pipe = blocks.init_pipeline("krea/Krea-2-Turbo") # weights from the base repo
pipe.load_components(torch_dtype=torch.bfloat16)
pipe.update_components(processor=Qwen3VLProcessor.from_pretrained("Qwen/Qwen3-VL-4B-Instruct"))
pipe.update_components(guider=ClassifierFreeGuidance(guidance_scale=0.0, use_original_formulation=True))
pipe.to("cuda")
from PIL import Image
image = pipe(
prompt="a white yeti with horns reading a book",
image=Image.open("reference.png"), # one or more reference images
num_inference_steps=8, mu=1.15, output="images",
)[0]
What it does
Reference images condition generation two ways (matching how the Ostris AI-Toolkit edit LoRAs train):
- Qwen3-VL prompt embedding β a coarse view of each reference is embedded into the text conditioning through the vision tower.
- Clean VAE latents at flow time t=0 β each reference is VAE-encoded and appended to the transformer sequence as clean tokens on its own rotary frame axis, so the noisy image tokens attend to it at every block.
The bundled Krea2Transformer2DModel adds a small, backward-compatible ref_seq_len argument to the
Krea 2 transformer forward (t=0 modulation of the reference span; those tokens are excluded from the
predicted velocity). With ref_seq_len=0 it is numerically identical to plain Krea 2 text-to-image.
Files
block.pyβ entry point (Krea2EditBlocks), referenced byconfig.json'sauto_map.transformer_krea2.pyβ the Krea 2 transformer (with theref_seq_lenedit path).modular_blocks_krea2*.py,encoders.py,before_denoise.py,denoise.py,decoders.py,inputs.py,modular_pipeline.pyβ the modular blocks.
- Downloads last month
- -