# 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'

**URL:** <https://discuss.huggingface.co/t/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/133828>\
**Category:** Models\
**Created:** [January 1, 2025, 10:37am UTC](https://discuss.huggingface.co/t/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/133828 "2025-01-01T10:37:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiongxiao](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jiongxiao/32/38439_2.png) [@jiongxiao](https://discuss.huggingface.co/u/jiongxiao)\
**Post date:** [January 1, 2025, 10:37am UTC](https://discuss.huggingface.co/t/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/133828/1 "2025-01-01T10:37:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jiongxiao](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jiongxiao/32/38439_2.png) [@jiongxiao](https://discuss.huggingface.co/u/jiongxiao)\
**Post date:** [January 1, 2025, 10:38am UTC](https://discuss.huggingface.co/t/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/133828/2 "2025-01-01T10:38:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [January 1, 2025, 11:14am UTC](https://discuss.huggingface.co/t/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/133828/3 "2025-01-01T11:14:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](https://discuss.huggingface.co/u/system)\
**Post date:** [January 3, 2025, 4:44am UTC](https://discuss.huggingface.co/t/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/133828/4 "2025-01-03T04:44:00Z")

</div>

Closed on January 3, 2025, 4:44am UTC

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