Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed saving for models that don't have _name_or_path in config #1440

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

kovalexal
Copy link
Contributor

Hi, PEFT team!

I noticed a small bug when I was trying to save LoRA for SDXL UNet model, loaded with from_single_file method.
Apparently, from_single_file does not add _name_or_path to the child model config (at least for diffusers==0.26.0).

from diffusers import StableDiffusionXLPipeline
from peft import get_peft_model, LoraConfig

pipe = StableDiffusionXLPipeline.from_single_file(
    "/data/checkpoints/civitai/sdxl/realvisxlV30Turbo_v30Bakedvae.safetensors"
)


config = LoraConfig(
    target_modules=["conv_in"],
    lora_alpha=8,
    r=8
)

pipe.unet = get_peft_model(pipe.unet, config, adapter_name="default")
pipe.unet.save_pretrained("./unet")
...
File /opt/conda/envs/peft/lib/python3.8/site-packages/peft/peft_model.py:782, in PeftModel.create_or_update_model_card(self, output_dir)
    780     model_config = model_config.to_dict()
    781 if model_config is not None:
--> 782     card.data["base_model"] = model_config["_name_or_path"]
    784 lines = card.text.splitlines()
    786 quantization_config = None

KeyError: '_name_or_path'

This specific PR fixes this issue.

@BenjaminBossan your review is kindly appreciated.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much appreciated, LGTM.

@BenjaminBossan BenjaminBossan merged commit 9350ab8 into huggingface:main Feb 6, 2024
14 checks passed
BenjaminBossan pushed a commit to BenjaminBossan/peft that referenced this pull request Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants