Skip to content

Conversation

DN6
Copy link
Collaborator

@DN6 DN6 commented Jul 2, 2024

What does this PR do?

There seems to be an issue with

  1. Saving Kohya style weights in the dreambooth advanced lora script. The save path can output a weird directory when using a relative path. e.g. setting output_dir=../checkpoints/my-dog-model will result in the following line creating a path like
    '../checkpoints/my-dog-model/../checkpoints/my-dog-model.safetensors'
    save_file(kohya_state_dict, f"{args.output_dir}/{args.output_dir}.safetensors")

I've changed this to save the kohya weight as args.output_dir/kohya_lora_weights.safetensors but I'm open to any better naming.

  1. When passing in the train_text_encoder argument, I believe there is a missing else statement resulting in an ValueError always being raised.

Fixes # (issue)

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@DN6 DN6 requested a review from linoytsaban July 2, 2024 06:40
@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.

@@ -2413,7 +2413,7 @@ def get_sigmas(timesteps, n_dim=4, dtype=torch.float32):
lora_state_dict = load_file(f"{args.output_dir}/pytorch_lora_weights.safetensors")
peft_state_dict = convert_all_state_dict_to_peft(lora_state_dict)
kohya_state_dict = convert_state_dict_to_kohya(peft_state_dict)
save_file(kohya_state_dict, f"{args.output_dir}/{args.output_dir}.safetensors")
save_file(kohya_state_dict, f"{args.output_dir}/kohya_lora_weights.safetensors")
Copy link
Collaborator

@linoytsaban linoytsaban Jul 2, 2024

Choose a reason for hiding this comment

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

maybe we can use Path(args.output_dir).name ? so it'll be -

save_file(kohya_state_dict, f"{args.output_dir}/{Path(args.output_dir).name}.safetensors")

cc @apolinario

Copy link
Collaborator

@linoytsaban linoytsaban left a comment

Choose a reason for hiding this comment

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

Thanks @DN6!

@DN6 DN6 merged commit 85c4a32 into main Jul 5, 2024
sayakpaul pushed a commit that referenced this pull request Dec 23, 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