Deprecated β This issue has been fixed in the latest Nunchaku release. See nunchaku-tech/ComfyUI-nunchaku#406.
A single-file Python utility that patches .safetensors LoRA models missing adaLN (Adaptive Layer Normalization) weights in their final layer β restoring compatibility with the Nunchaku LoRA loader in ComfyUI.
Based on: lym00/comfyui_nunchaku_lora_patch
Some LoRA models are trained without final_layer.adaLN_modulation_1 weights. The Nunchaku loader strictly requires these keys and fails with a key mismatch error when they are absent.
- Scans
lora/directory for all.safetensorsfiles (skips_patchedfiles) - For each file: detects
final_layer.linearweights and checks for missingadaLN_modulation_1counterparts - Generates zero-filled dummy tensors matching the shape of the linear weights
- Saves a new
_patched.safetensorsfile β original is never modified
The patched model produces identical visual output to the original. The dummy weights are zero-filled placeholders purely for loader compatibility β they have no functional effect.
| Dependency | Purpose |
|---|---|
| Python 3.8+ | Runtime |
torch |
Tensor creation and shape introspection |
safetensors |
Read / write .safetensors model files |
pip install torch safetensors- Place LoRA models to patch in the
lora/directory - Run the script:
python patch_comfyui_nunchaku_lora.py
- Patched files are saved as
lora/<original_name>_patched.safetensors
Example output:
π Universal final_layer.adaLN LoRA patcher (.safetensors)
Found 1 file(s) to process.
Processing: lora\fal-Realism-Detailer-Kontext.safetensors
β
Loaded 130 tensors.
β
Patch applied using prefix 'lora_unet_final_layer'.
β
Patched file saved to: lora\fal-Realism-Detailer-Kontext_patched.safetensors
β
Verification successful: adaLN keys are present.
π Done. Patched 1 file(s).
MIT