Identity-preserving image editing for Krea 2 in Diffusers
Python
4
0 commits
updated Jul 21, 2026
A self-contained π€ Diffusers pipeline that brings the
conradlocke/krea2-identity-edit
v1.2 identity-preserving instruction-edit recipe to Diffusers, running on top of the
Krea-2-Turbo flow-matching model.
Given a source image and a natural-language edit instruction (e.g. "change the suit jacket to a red leather jacket"), the pipeline edits the image while holding the subject's identity / likeness. It also works as a plain Krea 2 text-to-image pipeline when no source image is supplied.
| Source | Instruction | Output |
|---|---|---|
![]() | "change the suit jacket to a red leather jacket" | ![]() |
conradlocke/krea2-identity-edit v1.2 recipe.Krea2Transformer2DModel
(single-stream MMDiT) whose module tree and state-dict keys match the Krea 2 checkpoints,
so the sharded weights load directly. The forward pass is extended with clean reference /
source tokens that the stock upstream class does not support.diffusion_model.blocks... with lora_down/lora_up) as well as already-converted
diffusers-format state dicts. Alpha folding and key remapping are handled automatically.DiffusionPipeline.from_pretrained with
trust_remote_code=True resolves it on stock diffusers releases.guidance_scale=0.0), thanks to
the Krea-2-Turbo distilled checkpoint.Install the pinned dependencies:
pip install -r requirements.txt
python inference.py
The two dials that matter most for identity edits:
| Argument | Default | Effect |
|---|---|---|
ref_boost | 4.0 | Likeness dial. How hard the edit holds the reference. 1.0 = off (maskless fast path), ~4 = strong likeness (release preset), 8+ tends to over-copy. Implemented as an additive log(ref_boost) bias on the targetβsource attention logits. |
grounding_px | 768 | Longest side fed to the Qwen3-VL vision tower when grounding the instruction. Lower = stronger edit adherence; higher = stronger identity. The LoRA was trained with 384β768 px jitter. |
Other useful arguments to pipe(...):
image = pipe(
"change the suit jacket to a red leather jacket",
image=Image.open("example.png"),
num_inference_steps=10, # Turbo recipe; more rarely helps
guidance_scale=0.0, # Krea convention: 0.0 disables CFG
ref_boost=4.0, # bump up for tougher identity holds
grounding_px=768, # 384β768
height=1024, # defaults to source AR, capped at ~1 MP,
width=768, # snapped to a multiple of 16
generator=torch.Generator("cuda").manual_seed(0), # for reproducibility
).images[0]
Output resolution for edits defaults to the source aspect ratio, capped at ~1 megapixel (
MAX_EDIT_MEGAPIXELS = 1.0) and snapped to a multiple ofvae_scale_factor * patch_size(= 16). The edit path doubles the transformer token count (it prepends the source latent), so the area cap keeps memory in check.
The identity-edit recipe (mirrors conradlocke/krea2-identity-edit v1.2 /
ComfyUI-Krea2Edit) has two parts:
The edit instruction is grounded on the source image through the Qwen3-VL chat
template. A <|vision_start|><|image_pad|><|vision_end|> block is inserted before the
instruction so the VLM grounds the edit semantics on the source. The system prefix is
byte-identical to the text-only Krea 2 template:
<|im_start|>system
Describe the image by detailing the color, shape, size, texture, quantity, text,
spatial relationships of the objects and background:<|im_end|>
<|im_start|>user
<|vision_start|><|image_pad|><|vision_end|>{instruction}<|im_end|>
<|im_start|>assistant
The Qwen3-VL text encoder produces a stack of hidden states tapped from several layers, which the transformer's text-fusion stage collapses into one text sequence.
The source image is VAE-encoded into a latent and prepended to the transformer
sequence as a clean token block. The combined sequence is
[text | source (frame=1) | target (frame=0)]. Source and target are distinguished purely
by the 3-axis RoPE frame index (source frame = 1, target = 0) β not by timestep β so the
target tokens can attend back to the clean source to preserve identity.
The ref_boost likeness dial then adds log(ref_boost) to the target-on-source attention
logits, multiplicatively boosting how strongly the target copies the source before softmax
renormalization. The float bias is applied chunk-wise by the memory-efficient SDPA backend,
so the full seq Γ seq score matrix is never materialized.
See the module and method docstrings in krea2_edit_pipeline.py
for the full detail (notably _grounded_encode, _encode_source_latent,
_edit_position_ids, _ref_boost_bias, and _edit_transformer_forward).
Model: krea/Krea-2-Turbo.
Identity-edit LoRA: conradlocke/krea2-identity-edit(v1.2).
Edit Pipeline: ostris/Krea2OstrisEdit and conradlocke/krea2-identity-edit
Framework: π€ Diffusers.
Identity-preserving image editing for Krea 2 in Diffusers
Python
4
0 commits
updated Jul 21, 2026
A self-contained π€ Diffusers pipeline that brings the
conradlocke/krea2-identity-edit
v1.2 identity-preserving instruction-edit recipe to Diffusers, running on top of the
Krea-2-Turbo flow-matching model.
Given a source image and a natural-language edit instruction (e.g. "change the suit jacket to a red leather jacket"), the pipeline edits the image while holding the subject's identity / likeness. It also works as a plain Krea 2 text-to-image pipeline when no source image is supplied.
| Source | Instruction | Output |
|---|---|---|
![]() | "change the suit jacket to a red leather jacket" | ![]() |
conradlocke/krea2-identity-edit v1.2 recipe.Krea2Transformer2DModel
(single-stream MMDiT) whose module tree and state-dict keys match the Krea 2 checkpoints,
so the sharded weights load directly. The forward pass is extended with clean reference /
source tokens that the stock upstream class does not support.diffusion_model.blocks... with lora_down/lora_up) as well as already-converted
diffusers-format state dicts. Alpha folding and key remapping are handled automatically.DiffusionPipeline.from_pretrained with
trust_remote_code=True resolves it on stock diffusers releases.guidance_scale=0.0), thanks to
the Krea-2-Turbo distilled checkpoint.Install the pinned dependencies:
pip install -r requirements.txt
python inference.py
The two dials that matter most for identity edits:
| Argument | Default | Effect |
|---|---|---|
ref_boost | 4.0 | Likeness dial. How hard the edit holds the reference. 1.0 = off (maskless fast path), ~4 = strong likeness (release preset), 8+ tends to over-copy. Implemented as an additive log(ref_boost) bias on the targetβsource attention logits. |
grounding_px | 768 | Longest side fed to the Qwen3-VL vision tower when grounding the instruction. Lower = stronger edit adherence; higher = stronger identity. The LoRA was trained with 384β768 px jitter. |
Other useful arguments to pipe(...):
image = pipe(
"change the suit jacket to a red leather jacket",
image=Image.open("example.png"),
num_inference_steps=10, # Turbo recipe; more rarely helps
guidance_scale=0.0, # Krea convention: 0.0 disables CFG
ref_boost=4.0, # bump up for tougher identity holds
grounding_px=768, # 384β768
height=1024, # defaults to source AR, capped at ~1 MP,
width=768, # snapped to a multiple of 16
generator=torch.Generator("cuda").manual_seed(0), # for reproducibility
).images[0]
Output resolution for edits defaults to the source aspect ratio, capped at ~1 megapixel (
MAX_EDIT_MEGAPIXELS = 1.0) and snapped to a multiple ofvae_scale_factor * patch_size(= 16). The edit path doubles the transformer token count (it prepends the source latent), so the area cap keeps memory in check.
The identity-edit recipe (mirrors conradlocke/krea2-identity-edit v1.2 /
ComfyUI-Krea2Edit) has two parts:
The edit instruction is grounded on the source image through the Qwen3-VL chat
template. A <|vision_start|><|image_pad|><|vision_end|> block is inserted before the
instruction so the VLM grounds the edit semantics on the source. The system prefix is
byte-identical to the text-only Krea 2 template:
<|im_start|>system
Describe the image by detailing the color, shape, size, texture, quantity, text,
spatial relationships of the objects and background:<|im_end|>
<|im_start|>user
<|vision_start|><|image_pad|><|vision_end|>{instruction}<|im_end|>
<|im_start|>assistant
The Qwen3-VL text encoder produces a stack of hidden states tapped from several layers, which the transformer's text-fusion stage collapses into one text sequence.
The source image is VAE-encoded into a latent and prepended to the transformer
sequence as a clean token block. The combined sequence is
[text | source (frame=1) | target (frame=0)]. Source and target are distinguished purely
by the 3-axis RoPE frame index (source frame = 1, target = 0) β not by timestep β so the
target tokens can attend back to the clean source to preserve identity.
The ref_boost likeness dial then adds log(ref_boost) to the target-on-source attention
logits, multiplicatively boosting how strongly the target copies the source before softmax
renormalization. The float bias is applied chunk-wise by the memory-efficient SDPA backend,
so the full seq Γ seq score matrix is never materialized.
See the module and method docstrings in krea2_edit_pipeline.py
for the full detail (notably _grounded_encode, _encode_source_latent,
_edit_position_ids, _ref_boost_bias, and _edit_transformer_forward).
Model: krea/Krea-2-Turbo.
Identity-edit LoRA: conradlocke/krea2-identity-edit(v1.2).
Edit Pipeline: ostris/Krea2OstrisEdit and conradlocke/krea2-identity-edit
Framework: π€ Diffusers.