EditUtils: Krea2 Edit Apply (Model Patch) lrzjason
The Node That Turns Krea 2 Into an Instruction Editor
- model
- model
Krea 2 was released as a text-to-image model; nothing in the stock ComfyUI path turns it into an editor. Krea2EditApply_EditUtils is the patch that does. You connect only the model wire - no image inputs, no refs, nothing else - and the node rewires the model so reference latents that arrived inside the conditioning (the pack's reference_latents key, laid down by EditTextEncode_EditUtils) are read back out and injected into the attention stack. One wire in, one wire out, and your Krea 2 can suddenly edit.
How it works matters because it explains the tuning knobs. The patch mirrors UnifiedTrainer's training geometry: the token sequence becomes [text | target | ref₁ | ref₂ | …], position IDs are assigned so the target sits at (0, h, w) and each reference at (+n, h, w), and the reference tokens are modulated as clean latents (timestep 0) while the text and target get the real timestep. The model forward's output is sliced back to just the target tokens - so the refs steer the generation without becoming part of it. The patch installs via add_object_patch on a cloned model instance, which is ComfyUI's clean way of keeping the patch isolated: your original model object is never touched, and the patch uninstalls properly with the model's lifecycle.
Three settings do the real work.
ref_pos_match_target (default True): center-aligns reference position IDs to cover the target token grid, so each reference token represents the center of the target region it corresponds to. Leave it on when reference and target resolutions differ - with it off, a smaller reference only aligns to the target's top-left corner, which is a classic "why is my ref content stuck in one corner" symptom.
ref_kv_cache (default True): caches the reference images' attention K/V at the first denoise step and reuses them for every later step - and across repeated generations with identical references. That's roughly 2× faster, and the node is honest that it's a frozen-reference approximation, not bit-exact. For most edits the speed win beats the tiny fidelity delta; turn it off if you're chasing pixel-perfect repeatability.
ref_strength (default 1.0): controls how long references constrain sampling. 1.0 = refs attend every step; 0.5 = refs attend the first half, then sampling continues as pure text-to-image; 0.0 = refs never participate (straight to the no-reference forward). It requires ref_kv_cache on, and the author's own notes suggest experimenting in the 0.5–0.7 range when a reference is over-constraining the output - the intuition being refs lock in structure/identity early and you release them for detail and creativity later. It's out-of-distribution behavior, so eyeball results rather than trusting it blindly.
And mode (default editutils) exists for one specific situation: if you trained a LoRA with the comfyui-krea2edit toolchain, switch it to krea2edit so references get the real timestep (ai-toolkit's predict_velocity_edit geometry) instead of the t=0 convention - that's how a krea2edit-trained LoRA runs on its native inference geometry. reset_cache clears the KV cache each execution, and debug_log prints cache hits/misses to the console, which is the first thing to flip when sampling looks wrong.
Big caveat that's not the node's fault: the README flags Krea 2 edit support as still in development - interfaces may change. And remember the model itself: the open weights carry an alignment pass, so edits involving bodies, expressions, or violence may come back flattened or silently ignored; the community workarounds (an uncensor LoRA, mostly) cost a little quality. Install: ComfyUI Manager (search "EditUtils") or git clone https://github.com/lrzjason/ComfyUI-EditUtils into custom_nodes, restart. Krea 2, Qwen3-VL encoder, and Qwen-Image VAE are yours to provide.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| modeopt | COMBO | editutils | Reference-token timestep convention. 'editutils' modulates reference tokens as clean latents (t=0, UnifiedTrainer recipe). 'krea2edit' gives references the real timestep (ai-toolkit predict_velocity_edit) — select this to run a comfyui-krea2edit-trained LoRA on its native inference geometry. |
| ref_pos_match_targetopt | BOOLEAN | true | Center-align ref position ids to cover the target token grid. Each ref token is placed at the center of the target region it represents. Enable when reference and target resolutions differ — otherwise a smaller ref only aligns to the target's top-left region. |
| ref_kv_cacheopt | BOOLEAN | true | Cache reference-image attention K/V at the first denoise step and reuse them for all later steps and repeated generations with identical refs (~2x faster). Frozen-reference approximation, not bit-exact. |
| ref_strengthopt | FLOAT | 1.000–1 | How long references constrain sampling. 1.0 = refs attend all steps; 0.5 = refs attend the first half of steps, then generation continues as pure text-to-image; 0.0 = refs never participate. Requires ref_kv_cache. |
| reset_cacheopt | BOOLEAN | true | — |
| debug_logopt | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| model | MODEL | — |