KV_Edit_Sampler
The edit engine, and the two modes hiding under the defaults
- model
- condition
- image
This is where the actual edit happens. KV_Edit_Sampler takes the model from KV_Edit_Load (optionally LoRA'd) and the condition bundle from KV_Edit_PreData, runs the whole inversion-and-edit dance, and hands you a finished IMAGE you can preview and save like any other output. Everything else in the pack is setup; this node is the show.
The two modes
That use_inf toggle on KV_Edit_Load didn't just feel like a checkbox - it selects which engine this node runs, and the defaults are set the way they are for a reason.
use_inf on (default) is the fast single pass. It's built on RF-Solver-Edit, per the README's acknowledgements. Instead of doing a full separate inversion then a full denoise, it constructs a source path (your image toward noise) and a target path in parallel and solves the flow ODE by taking velocity differences between the source and target prompts, updating only the masked latents. Roughly one Flux pass's worth of compute, which is why the example workflow runs 10 steps with the turbo LoRA and still looks right.
use_inf off is the original two-stage method the paper is named for. First an inversion pass that runs your image backwards through the model, and at every block stores the attention keys and values of the image tokens in a cache (you can read it in layers.py - img_k/img_v saved per step). Then a denoise pass toward the target prompt where the background's K/V are pulled straight from that cache instead of recomputed, and only the masked region gets regenerated. That cache reuse is "precise background preservation." It costs a full extra pass and a lot of RAM for the cached features, but it's the most faithful option.
The knobs that matter
The sampler exposes eleven inputs; most have sane defaults, so here are the ones you'll actually touch:
- denoise_steps (28) and denoise_guidance (5) - the main quality/speed dial, used in both modes. The example runs 10 steps at 3.5 guidance.
- inversion_steps (28) and inversion_guidance (1.5) - only read in the non-inf two-stage mode; the fast path ignores them, so don't chase them if
use_infis on. - skip_step (1) - skips early timesteps of the schedule, a coarse "how much of the original survives" control.
- attn_scale (1.0) - scales background attention strength; drop toward 0 if the edit is leaving too much of the original untouched.
- attn_mask (off) - enables the custom boolean attention mask that restricts which tokens attend to each other; mostly useful when a background-bleed problem is really an attention problem.
- re_init (off) - re-initializes the masked region from noise instead of reusing the inversion latents; flip it on if masked content feels too locked to the source.
Plus seed and the wired-in model/condition. Output: image (IMAGE).
What to expect when it goes wrong
OOM is normal on small cards. This is a 12B model plus, in non-inf mode, a pile of cached feature tensors. The code literally wraps the run in an OOM retry - expect a "get OOM, try again" line in the console on 16 GB cards. Switch to the fp8 flux checkpoint, leave offload on, use the inf mode, and lower resolution.
The seed dial is more decorative than you'd think. Inside the fast path the noise schedule uses a fixed seed (torch.manual_seed(0)) regardless of your seed input, so don't expect dramatic variation from changing it.
The background staying put is the feature, not a bug. When nothing seems to change except the masked region, that's the point - it's the "bit-identical unmasked pixels" that instruction-edit models can't promise. If you want the whole image to shift, KV-Edit is the wrong tool.
It's a demanding node - heavy models, heavy memory, 10–28 steps of full Flux passes - but it's the one that makes background-preserving edits actually work, and once it's set up it's a one-button workflow.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL_KVEDIT | — | |
| condition | CONDITION_KV | — | |
| seed | INT | 00–2147483647 | — |
| inversion_steps | INT | 281–1024 | — |
| inversion_guidance | FLOAT | 1.50–10 | — |
| denoise_steps | INT | 281–1024 | — |
| denoise_guidance | FLOAT | 5.00–10 | — |
| skip_step | INT | 10–30 | — |
| attn_scale | FLOAT | 1.00–5 | — |
| re_init | BOOLEAN | false | — |
| attn_mask | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |