EditUtils: MOSS-Image Edit Apply (Model Patch) lrzjason
The model patch that teaches MOSS-Image to read your reference
- model
- model
This is the only node in the pack's MOSS-Image set that changes how the model computes. Everything else prepares inputs. MossImageEditApply_EditUtils rewrites the DiT's forward pass so reference latents can sit in the sequence at all - and it has four knobs that decide whether the references behave the way your LoRA expects.
What it's for
MOSS-Image is a text-to-image model. Its sequence is [target image | text] on a four-axis RoPE (r, f, h, w). There's no slot for a reference. The patch adds one:
[target image | text | ref1 | ref2 | ...]
Reference n gets r = n, f = text_len - the coordinate the base model leaves at zero - and its own centred h/w grid. Reference tokens are modulated at t = 0, i.e. treated as clean latents, while the target and text get the real timestep. The prediction is then sliced back to the target tokens, so the sampler still sees a normal image latent.
That's the mechanism. It matches ai-toolkit's MOSS-Image edit mode, which is the only reason it works: an edit LoRA trained on that exact layout is doing the actual learning. The patch, on its own, is a plumbing change - the base and SFT checkpoints will not magically acquire reference conditioning from it.
Inputs and outputs
Required: model. Wire UNETLoader into it. Only the model wire - reference latents arrive through the conditioning chain from EditTextEncode_EditUtils, not through this node. Nothing else should be connected here; that trips people up because every other edit node in their graph has a conditioning input.
ref_kv_cache (default on) is the one to get right. On is ai-toolkit's kv_cache reference mode: the references attend only to each other, their K/V are precomputed once in a single t=0 pass, then injected as extra keys on every sampling step. Off, the references ride along in the sequence and attend to the text and the noisy image too. Match this to how your LoRA was trained - a LoRA trained with kv_cache: false (UnifiedTrainer's reference-token forward, for instance) wants it off. The cost of the cache is real: roughly 2 GB of CPU RAM for 4096 reference tokens, held per distinct text length, up to four variants.
ref_strength (default 1.0) is how long the references keep constraining sampling. 1.0 is every step, 0.5 is the first half and then pure text-to-image, 0.0 means they never participate. Below 1.0 is a real creative control, not a debug switch: the reference shapes the composition and then the model finishes it from the prompt.
reset_cache (default on) clears cached K/V when the node runs. Leave it on unless you're deliberately reusing the same references across different prompts in one session.
debug_log (default off) prints what the patch is doing.
Output is model - same wire out, into your LoRA loader and then the sampler.
How it fits
UNETLoader (moss_image_sft_int8_convrot) ──► MossImageEditApply ──► [LoRA] ──► KSampler ──► VAEDecode ──► SaveImage
Put the patch straight after the loader and before any LoRA merge, as the pack's example does. Suggested starting point: euler/simple, 30 steps, CFG 3.0, ref_strength=1.0. MOSS's own reference sampling uses negative-branch layer skipping (SkipLayerGuidanceDiTSimple with single_layers: 22), and the patch honours that, so if you're copying a reference workflow that uses it, keep it.
Installing
cd ComfyUI/custom_nodes
git clone https://github.com/lrzjason/ComfyUI-EditUtils
# restart ComfyUI
Or ComfyUI Manager, search ComfyUI-EditUtils. No pip dependencies - pure ComfyUI core, no requirements file. You need a build with native MOSS-Image support (image_model="moss_image", CLIPLoader type moss_image), plus moss_image_sft_int8_convrot, qwen3.5_9b_w4a8_gptq, flux2-vae, and the edit LoRA.
Where people get burned
It fails silently on the wrong model. Point this at a Qwen, Flux or Krea2 model and it doesn't error - the node checks the architecture and returns the model unchanged. You then spend an hour wondering why your references do nothing while the log shows nothing wrong. Verify the UNET is actually a MOSS-Image checkpoint before you debug anything else.
ref_kv_cache mismatched to the LoRA. This produces "references are sort of there but mushy", which is much harder to diagnose than an error. If your LoRA card mentions a training forward, read it.
RAM creep on long prompts. The K/V cache is per distinct text length. Change the prompt a lot within a session with reset_cache off and you're holding several 2 GB caches. Turn it on unless you know why you turned it off.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| ref_kv_cacheopt | BOOLEAN | true | ON (default) is ai-toolkit's kv_cache reference mode: the references attend only to each other and their K/V are precomputed once at t=0, then injected as extra keys on every step. Turn it OFF for a LoRA trained without kv_cache (e.g. UnifiedTrainer's reference-token forward), where references attend to the text and noisy image too. |
| ref_strengthopt | FLOAT | 1.000–1 | How long references constrain sampling. 1.0 = all steps; 0.5 = the first half, then pure text-to-image; 0.0 = references never participate. |
| reset_cacheopt | BOOLEAN | true | Clear cached reference K/V when this node runs. Leave on unless you deliberately reuse the same references across prompts. |
| debug_logopt | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| model | MODEL | — |