When I use convert_lora_safetensor_to_diffusers.py to convert lora trained weights to diffusers format, I got errors:AttributeError: 'UNet2DConditionModel' object has no attribute 'unet'

python scripts/convert_lora_safetensor_to_diffusers.py --base_model_path /usr/AI/training/models/diffusers_model --checkpoint_path /usr/AI/training/models/model_genie_lora/pytorch_lora_weights.safetensors --dump_path /usr/AI/training/models/model_genie_lora_diffusers


Loading pipeline components…: 0%| | 0/7 [00:00<?, ?it/s]An error occurred while trying to fetch /usr/AI/training/models/diffusers_model/unet: Error no file named diffusion_pytorch_model.safetensors found in directory /usr/AI/training/models/diffusers_model/unet.
Defaulting to unsafe serialization. Pass allow_pickle=False to raise an error instead.
Loading pipeline components…: 14%|████████▌ | 1/7 [00:20<02:05, 20.93s/it]/usr/local/python3.10.11/lib/python3.10/site-packages/transformers/models/clip/feature_extraction_clip.py:28: FutureWarning: The class CLIPFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please use CLIPImageProcessor instead.
warnings.warn(
Loading pipeline components…: 57%|██████████████████████████████████▎ | 4/7 [00:21<00:12, 4.03s/it]An error occurred while trying to fetch /usr/AI/training/models/diffusers_model/vae: Error no file named diffusion_pytorch_model.safetensors found in directory /usr/AI/training/models/diffusers_model/vae.
Defaulting to unsafe serialization. Pass allow_pickle=False to raise an error instead.
Loading pipeline components…: 100%|████████████████████████████████████████████████████████████| 7/7 [00:23<00:00, 3.35s/it]
Traceback (most recent call last):
File “/usr/AI/diffusers/scripts/convert_lora_safetensor_to_diffusers.py”, line 55, in convert
curr_layer = curr_layer.getattr(temp_name)
File “/usr/AI/diffusers/src/diffusers/models/modeling_utils.py”, line 173, in getattr
return super().getattr(name)
File “/usr/local/python3.10.11/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1931, in getattr
raise AttributeError(
AttributeError: ‘UNet2DConditionModel’ object has no attribute ‘unet’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/AI/diffusers/scripts/convert_lora_safetensor_to_diffusers.py”, line 125, in
pipe = convert(base_model_path, checkpoint_path, lora_prefix_unet, lora_prefix_text_encoder, alpha)
File “/usr/AI/diffusers/scripts/convert_lora_safetensor_to_diffusers.py”, line 62, in convert
temp_name += “_” + layer_infos.pop(0)
IndexError: pop from empty list

1 Like

This is the trainling scripts:

export MODEL_NAME=“/usr/AI/checkpoints/stable-diffusion-v1-5”
export DATASET_DIR=“./datasets/genie_lora”
export OUTPUT_DIR=“./models/model_genie_lora”
export LOG_DIR=“./logs”

rm -rf $LOG_DIR/*

accelerate launch /usr/AI/diffusers/examples/text_to_image/train_text_to_image_lora.py
–mixed_precision=“fp16”
–pretrained_model_name_or_path=$MODEL_NAME
–dataset_name=$DATASET_DIR
–dataloader_num_workers=8
–resolution=512
–center_crop
–random_flip
–train_batch_size=1
–gradient_accumulation_steps=4
–max_train_steps=1000
–learning_rate=1e-04
–max_grad_norm=1
–lr_scheduler=“cosine”
–lr_warmup_steps=0
–output_dir=$OUTPUT_DIR
–checkpointing_steps=500

1 Like

That script was created for a very limited version of LoRA. With the current Diffusers, you can use it in the same format as the LoRA for the normal WebUI and ComfyUI.
Basically, there is no need to convert it.

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.