Views
No views yet
diffusion_model.* keys, lora_A/lora_B or lora_down/lora_up + alpha) as well as diffusers-format state dicts.pipeline.py, so it works on diffusers releases that don't ship Krea 2 yet. Without a reference image it is a plain Krea 2 text-to-image sampler.| Reference | Output | Same seed, no reference |
|---|---|---|
![]() | ![]() | ![]() |
1import torch
2from diffusers import DiffusionPipeline
3from PIL import Image
4
5pipe = DiffusionPipeline.from_pretrained(
6 "krea/Krea-2-Turbo",
7 custom_pipeline="ostris/Krea2OstrisEdit",
8 torch_dtype=torch.bfloat16,
9)
10pipe.enable_model_cpu_offload() # or pipe.to("cuda") with ~40+ GB of VRAM
11
12# An AI-Toolkit Krea 2 LoRA, e.g. the style reference LoRA
13pipe.load_lora_weights(
14 "ostris/krea2_turbo_style_reference", weight_name="krea2_style_reference.safetensors"
15)
16
17image = pipe(
18 "a white yeti with horns reading a book",
19 image=Image.open("style_reference.png"), # one reference image or a list of them
20 # kv_cache=True, # reference K/V computed once and reused every step; only for
21 # # LoRAs trained with AI-Toolkit's kv_cache model kwarg
22).images[0]
23image.save("output.png")krea/Krea-2-Raw (the non-distilled base model); sampling defaults adapt automatically (see below).prompt, negative_prompt, height, width, num_inference_steps, guidance_scale, generator, ...):| Argument | Default | Description |
|---|---|---|
image | None | Reference image(s): a PIL image, numpy array, [0,1] CHW tensor, or a list of them. References keep their own aspect ratio; output size is set by height/width independently. |
reference_max_pixels | 1024 * 1024 | Pixel budget each reference is downscaled to fit (never upscaled) before VAE encoding. |
vl_image_max_pixels | 384 * 384 | Pixel budget for the coarse Qwen3-VL view of each reference. |
encode_reference_in_prompt | True | Also embed references into the text conditioning through the Qwen3-VL vision tower (matches AI-Toolkit edit training). |
kv_cache | False | Cache the reference tokens' attention K/V: precomputed in a single t=0 pass and reused on every denoising step, so the references never ride along in the per-step sequence (faster, especially with CFG or many steps). The LoRA must be trained with AI Toolkit's kv_cache model kwarg for this to work properly; leave off for normally trained edit LoRAs. |
max_sequence_length | 512 | Maximum prompt token length (truncation only; prompts are encoded at natural length, not padded). |
num_inference_steps / guidance_scale follow the loaded checkpoint: 8 / 0.0 for the distilled Turbo model, 28 / 4.5 for the base model. Guidance uses the Krea 2 convention cond + scale * (cond - uncond), enabled whenever scale > 0 (this equals standard CFG with scale 1 + scale).Picture N: <|vision_start|><|image_pad|><|vision_end|> placeholders, so the text embeddings "see" the references.t=0 (they are never noised) and sit on rotary-position frame axis i + 1 — the Kontext-style "index" placement.kv_cache option, the reference tokens attend only to each other, which makes their per-block attention K/V independent of the timestep and of everything else in the sequence. Passing kv_cache=True then computes those K/V once in a reference-only precompute pass and injects them as extra attention keys on every denoising step, instead of recomputing the full reference tokens each step (OminiControl2-style conditioning feature reuse). The LoRA must be trained with kv_cache enabled for this to work properly.pipe.load_lora_weights(...) accepts a hub repo id (+ weight_name), a local .safetensors file or directory, or a state dict, in any of these formats:diffusion_model.blocks.N.attn.wq.lora_A.weight, ...lora_down.weight / lora_up.weight with optional .alpha tensors (folded into the effective scale)transformer.transformer_blocks.N.attn.to_q.lora_A.weight, ...unload_lora_weights(), fuse_lora() / unfuse_lora(), set_adapters(), and per-call scaling via attention_kwargs={"scale": 0.8} are also available.pipe.enable_model_cpu_offload() on cards with less than ~40 GB of VRAM. On a 32 GB RTX 5090 a 1024×1024 Turbo image takes ~40–50 s with offloading.Qwen/Qwen3-VL-4B-Instruct.