1Cris commited on
Commit
032314e
·
verified ·
1 Parent(s): c37d862

Create convert_lora.py

Browse files
Files changed (1) hide show
  1. convert_lora.py +21 -0
convert_lora.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from safetensors.torch import load_file, save_file
2
+ import torch
3
+
4
+ # --- Input and output file paths ---
5
+ src = "hlpvWkBrqzopjecZbuVIA_pytorch_lora_weights.safetensors"
6
+ dst = "hlpvWkBrqzopjecZbuVIA_pytorch_lora_weights_sdxl.safetensors"
7
+
8
+ # --- Load original LoRA weights ---
9
+ weights = load_file(src)
10
+ new_weights = {}
11
+
12
+ # --- Simple rename mapping for SDXL ---
13
+ for k, v in weights.items():
14
+ k2 = k.replace("lora_unet_", "unet.") \
15
+ .replace("lora_te_", "text_encoder.") \
16
+ .replace("lora_te2_", "text_encoder_2.")
17
+ new_weights[k2] = v.clone()
18
+
19
+ # --- Save as SDXL-compatible LoRA ---
20
+ save_file(new_weights, dst)
21
+ print(f"✅ Converted and saved as {dst}")