Skip to content

Instantly share code, notes, and snippets.

from safetensors import safe_open
from safetensors.torch import save_file
def layer_name(i):
if i.startswith('lora_te_text_model_encoder_layers_'):
idx = int(i[34:].split('_')[0])
return f'text'
elif i.startswith('lora_unet_down_blocks_'):
idx0 = int(i[22:].split('_')[0])
idx1 = int(i[22:].split('_')[2])
@akii-i
akii-i / lora_convert.py
Last active July 18, 2023 19:13
LORA format conversion from cloneofsimo lora format to AUTOMATIC1111 webui format (kohya's format)
# Convert cloneofsimo lora format to AUTOMATIC1111 webui format (kohya's format)
# Will generate extra embedding files along with the converted lora
# Usage: python lora_convert.py path_to_lora output_folder [--overwrite]
# path_to_lora_file : path to lora safetensors in cloneofsimo lora format
# output_folder : path to folder for results in AUTOMATIC1111 webui format
# overwrite : overwrite the results in output_folder
# Example: python lora_convert.py .\lora_krk.safetensors .\
from safetensors import safe_open
from safetensors.torch import save_file