Repository: huggingface/peft

Issue:
Create_or_update_model_card
Hello!
### System Info

peft @ git+https://github.com/huggingface/peft@0c16918c347bf32ad9532823068441f5fb76197a
accelerate==0.23.0
transformers==4.34.0
diffusers==0.20.0
running on Google Colab V100, Python 3.10

I've also attached my Google Drive and named my instance, class, and output directories on MyDrive. I'm using MODEL_NAME = "runwayml/stable-diffusion-v1-5".

### Who can help?

_No response_

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder
- [ ] My own task or dataset (give details below)

### Reproduction

I'm trying to follow this example 

[https://huggingface.co/docs/peft/task_guides/dreambooth_lora](https://colab.research.google.com/corgiredirector?site=https%3A%2F%2Fhuggingface.co%2Fdocs%2Fpeft%2Ftask_guides%2Fdreambooth_lora)

to reproduce the multi-adapter inference but during training I get this error:

Traceback (most recent call last):
  File "/content/peft/examples/lora_dreambooth/train_dreambooth.py", line 1086, in <module>
    main(args)
  File "/content/peft/examples/lora_dreambooth/train_dreambooth.py", line 1060, in main
    unwarpped_unet.save_pretrained(
  File "/usr/local/lib/python3.10/dist-packages/peft/peft_model.py", line 178, in save_pretrained
    self.create_or_update_model_card(save_directory)
  File "/usr/local/lib/python3.10/dist-packages/peft/peft_model.py", line 676, in create_or_update_model_card
    if model_config["model_type"] != "custom":
KeyError: 'model_type'
Steps: 100% 800/800 [16:16<00:00,  1.22s/it, loss=0.0921, lr=0.0001]
Traceback (most recent call last):
  File "/usr/local/bin/accelerate", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/dist-packages/accelerate/commands/accelerate_cli.py", line 47, in main
    args.func(args)
  File "/usr/local/lib/python3.10/dist-packages/accelerate/commands/launch.py", line 986, in launch_command
    simple_launcher(args)
  File "/usr/local/lib/python3.10/dist-packages/accelerate/commands/launch.py", line 628, in simple_launcher
    raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python3', '/content/peft/examples/lora_dreambooth/train_dreambooth.py', '--pretrained_model_name_or_path=runwayml/stable-diffusion-v1-5', '--instance_data_dir=/content/drive/MyDrive/bori', '--class_data_dir=/content/drive/MyDrive/stable_diffusion_weights/bori_sdv1-5_2/class_images', '--output_dir=/content/drive/MyDrive//content/drive/MyDrive/stable_diffusion_weights/bori_sdv1-5_2', '--train_text_encoder', '--with_prior_preservation', '--prior_loss_weight=1.0', '--instance_prompt=a photo of sks dog', '--class_prompt=a photo of dog', '--resolution=512', '--train_batch_size=1', '--lr_scheduler=constant', '--lr_warmup_steps=0', '--num_class_images=200', '--use_lora', '--lora_r', '16', '--lora_alpha', '27', '--lora_text_encoder_r', '16', '--lora_text_encoder_alpha', '17', '--learning_rate=1e-4', '--gradient_accumulation_steps=1', '--max_train_steps=800']' returned non-zero exit status 1.


### Expected behavior

I want it to save my weights after training, but it gets stuck... Please help!


Discussion:

Resolving patch:
diff --git a/src/peft/peft_model.py b/src/peft/peft_model.py
--- a/src/peft/peft_model.py
+++ b/src/peft/peft_model.py
@@ -673,7 +673,7 @@ def create_or_update_model_card(self, output_dir: str):
         model_config = self.config
         if hasattr(model_config, "to_dict"):
             model_config = model_config.to_dict()
-        if model_config["model_type"] != "custom":
+        if model_config.get("model_type", "custom") != "custom":
             card.data["base_model"] = model_config["_name_or_path"]
 
         lines = card.text.splitlines()


Test patch: