| 仓库中的 LoRA 已移除其中的 Norm 块,使其兼容 InvokeAI 5.6.0 及以上的版本,避免`AttributeError: 'LayerNorm' object has no attribute 'get_num_patches'`。 | |
| 移除 Norm 层代码。 | |
| ```python | |
| import os | |
| from safetensors.torch import load_file, save_file | |
| lora_path = "D:/Downloads/BaiduNetdiskDownload/ill-xl-01-rurudo_3-000034.safetensors" | |
| save_path = os.path.join( | |
| os.path.dirname(lora_path), | |
| os.path.splitext(os.path.basename(lora_path))[0] + "_without_norm_block.safetensors" | |
| ) | |
| norm_block_list = [] | |
| model_weights = load_file(lora_path) | |
| for block, _ in model_weights.items(): | |
| if "norm" in block: | |
| norm_block_list.append(block) | |
| for block in norm_block_list: | |
| del model_weights[block] | |
| save_file(model_weights, save_path) | |
| ``` | |