krea2edit trainer — ai-toolkit extension
Community project — not affiliated with or endorsed by Krea.ai. "Krea" is used
descriptively to identify the base model this trainer targets.
☕ Support on Ko-fi — all tips go straight to GPU
compute for future versions.
This is the actual training code behind the released
krea2-identity-edit LoRAs —
not a reimplementation. Its reference geometry is geometry-matched to the
comfyui-krea2edit inference nodes
(v1.2.4+), so what you train is what the nodes run. "Geometry-matched" is exact about
the things that misregister — fit dimensions, crop rectangles, and the centered
fractional RoPE offsets are identical — but the two stacks do not use the same
resample kernel, so reference pixels differ slightly below the geometry: the fit
path resizes with bilinear + antialias here vs bicubic + antialias in the node, the
legacy fit_refs: false crop path uses bilinear without antialias, and the
grounding downscale uses PIL LANCZOS here vs common_upscale(..., "area") in the
node. Geometry is exact; kernels are not.
It adds one model architecture to ai-toolkit:
krea2_edit — instruction-based, reference-conditioned editing (the identity-edit
recipe): in-context reference tokens + image-grounded text conditioning
(Plain Krea 2 text-to-image training is already built into upstream ai-toolkit as
arch: "krea2" — this extension doesn't duplicate it.)
Note on upstream's own edit mode: ai-toolkit's built-in krea2 arch also offers
an edit mode (model_kwargs: {edit: true}). It is a different training contract —
a "Picture N:"-labeled grounding template and an area-budget reference resize —
whereas this extension implements the exact grounding template and fit-to-target-grid
reference geometry that the comfyui-krea2edit nodes (and the released
krea2-identity-edit LoRAs) use. Both are valid trainers; they are not interchangeable.
If you want LoRAs that pair with the identity-edit inference stack, train with
arch: "krea2_edit" from this extension.
Install
cd ai-toolkit/extensions
git clone https://github.com/lbouaraba/krea2edit-trainer krea2_edit
That's it — ai-toolkit discovers extensions in that folder.