Z-Image Comfy Uninjector
Bake your LoRA-patched model back into raw weights
- model
- clip
- RAW_MODEL
- RAW_CLIP
ZImageComfyInjector turns raw weights into a model. This is the reverse trip: take a normal ComfyUI MODEL and CLIP - including any LoRA patches already applied to them - and flatten the whole thing back into a raw state dict. It's the "freeze the current state" node, and it's what lets you take a model that's been patched the normal ComfyUI way and move it into the Zlycoris raw pipeline for merging, saving, or further surgery.
How it works
Three steps per side:
- Read the state dict -
model.model.state_dict()for the diffusion model, and the CLIP'scond_stage_modelstate dict for the encoder. - Bake the patches - if the model carries a
patcherwith LoRA patches, the node adds each patch's weights (times its strength) directly into the tensor. That's what "bake" means: the LoRA stops being a patch and becomes part of the weights. - Sanitize the keys - strips the
model.diffusion_model.prefix from model keys andcond_stage_model.from clip keys, so they match the raw-pipeline naming.
Both inputs are optional. Outputs are RAW_MODEL and RAW_CLIP, ready for ZImageRawModelMerge, ZImageRawClipMerge, ZImageSaveTransformer, ZImageSaveTextEncoder, or a round trip back through the injector.
Why you'd do this
Three genuinely useful patterns:
- Bake and save. Apply LoRAs with the standard nodes, uninject, and write the result to disk with the pack's save nodes. Your character LoRA becomes a permanent checkpoint file - no load-time patching ever again, and the workflow becomes portable.
- Bake and merge. Take two differently-patched models, uninject them both to raw, and blend with
ZImageRawModelMerge- the only way to weight-average two patched states rather than two checkpoints. - Key consistency. The sanitizer exists so raw and non-raw nodes speak the same key language. It's the plumbing that makes the two halves of the pack interoperate.
Install
ComfyUI Manager (search ComfyUI-Zlycoris) or:
cd ComfyUI/custom_nodes
git clone https://github.com/TripleHeadedMonkey/ComfyUI-Zlycoris.git
Restart ComfyUI. No models, pure tooling.
Where people get burned
- Patch baking is best-effort. The bake loop catches exceptions per key and silently keeps the original weight when a patch doesn't fit - mostly a shape mismatch. A half-baked model is a subtle failure: it renders, but the LoRA's effect is partial. Check the console for skipped patches.
- Sanitizing is one-way. After
cond_stage_model./model.diffusion_model.prefixes are stripped, the dict is in raw format. Feeding it anywhere that expects the ComfyUI-native prefixing will fail - that's expected, but it surprises people who wire uninject output straight back into standard nodes. - It's a full model read and patch pass - not free. Uninjecting a 6B model plus the 4B Qwen encoder takes a moment and a chunk of RAM. Do it once, save the result, don't run it per-frame.
- Both inputs optional means a partially-plugged graph silently returns half a result. Wire both sockets when you want both halves.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| modelopt | MODEL | — | |
| clipopt | CLIP | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| RAW_MODEL | RAW_MODEL | — |
| RAW_CLIP | RAW_CLIP | — |