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

Fix setting fp16 dtype in AnimateDiff convert script. #7127

Merged
merged 2 commits into from
Feb 29, 2024

Conversation

DN6
Copy link
Collaborator

@DN6 DN6 commented Feb 28, 2024

What does this PR do?

save_pretrained doesn't actually use torch_dtype to convert the checkpoint to fp16 before saving. This PR adds a fix to the convert script so that fp16 weights are saved correctly for AnimateDiff models

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 sayakpaul February 28, 2024 06:24
@@ -48,4 +48,4 @@ def get_args():
# skip loading position embeddings
adapter.load_state_dict(conv_state_dict, strict=False)
adapter.save_pretrained(args.output_path)
adapter.save_pretrained(args.output_path, variant="fp16", torch_dtype=torch.float16)
adapter.to(torch.float16).save_pretrained(args.output_path, variant="fp16")
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be made configurable? Folks might not want to serialize the model in fp16.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated

@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.

@DN6 DN6 merged commit 8f2d13c into main Feb 29, 2024
10 checks passed
@@ -48,4 +49,6 @@ def get_args():
# skip loading position embeddings
adapter.load_state_dict(conv_state_dict, strict=False)
adapter.save_pretrained(args.output_path)
adapter.save_pretrained(args.output_path, variant="fp16", torch_dtype=torch.float16)

if args.save_fp16:
Copy link
Collaborator

Choose a reason for hiding this comment

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

are we missing an else statement here?

Copy link
Member

Choose a reason for hiding this comment

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

IIUC the scrtipt always serializes in the full precision. I think the script additionally serializes in FP16 when args.save_fp16 is True.

@sayakpaul sayakpaul deleted the animatediff-conversion-script branch March 5, 2024 03:00
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.

4 participants