Spaces:
Running on Zero
Fix LoRA load failure for Wan-native diff_b format files
Browse filesProduction log: 'iGoon - Blink_Front_Doggystyle_I2V' and 'Ultimate
Deepthroat' failed to load with 'TorchaoLoraLinear does not support
lora_bias yet', and generation proceeded WITHOUT their weights while the
prompt tags still claimed they were active.
Root cause: these LoRAs are saved in the Wan-native diff_b format (447
'diffusion_model.*.diff_b' learned-bias keys per file). diffusers'
_convert_non_diffusers_wan_lora_to_diffusers maps each diff_b key to
'lora_B.bias', which flips lora_bias=True, which peft's TorchaoLoraLinear
hard-rejects on torchao-quantized layers. The previous strip only removed
literal 'lora_B...bias' keys from already-converted dicts, missing the
Wan-native form entirely.
Fix: _strip_lora_bias now also drops keys ending in '.diff_b'. Verified
against the real production files (447/447 bias terms stripped, weights
preserved) and added a mock-pipe test case for the Wan-native format.
Regression: 5/5 mock-pipe cases, 18/18 auto-activation matrix, py_compile
all pass.
- lora_loader.py +13 -8
|
@@ -1008,17 +1008,22 @@ def download_lora(group_name):
|
|
| 1008 |
|
| 1009 |
|
| 1010 |
def _strip_lora_bias(state_dict):
|
| 1011 |
-
"""Drop
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
"lora_B"
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1018 |
"""
|
| 1019 |
return {
|
| 1020 |
k: v for k, v in state_dict.items()
|
| 1021 |
-
if not ("lora_B" in k and k.endswith(".bias"))
|
| 1022 |
}
|
| 1023 |
|
| 1024 |
|
|
|
|
| 1008 |
|
| 1009 |
|
| 1010 |
def _strip_lora_bias(state_dict):
|
| 1011 |
+
"""Drop keys that would make peft's TorchaoLoraLinear reject the adapter.
|
| 1012 |
+
|
| 1013 |
+
Two sources of a learned bias term:
|
| 1014 |
+
1. Already-converted dicts: keys containing "lora_B" ending in ".bias"
|
| 1015 |
+
(diffusers' lora_bias auto-detect looks for these in
|
| 1016 |
+
src/diffusers/utils/peft_utils.py).
|
| 1017 |
+
2. Wan-native dicts: keys ending in ".diff_b". diffusers'
|
| 1018 |
+
_convert_non_diffusers_wan_lora_to_diffusers maps every diff_b key to a
|
| 1019 |
+
"lora_B.bias" key, tripping the same lora_bias=True path.
|
| 1020 |
+
|
| 1021 |
+
Both are dropped so lora_bias stays False; only the (small) learned bias
|
| 1022 |
+
delta is discarded.
|
| 1023 |
"""
|
| 1024 |
return {
|
| 1025 |
k: v for k, v in state_dict.items()
|
| 1026 |
+
if not (k.endswith(".diff_b") or ("lora_B" in k and k.endswith(".bias")))
|
| 1027 |
}
|
| 1028 |
|
| 1029 |
|