Skip to content

fix vae dtype when accelerate config using --mixed_precision="fp16" #9601

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

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/controlnet/train_controlnet_sd3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ def load_model_hook(models, input_dir):
weight_dtype = torch.bfloat16

# Move vae, transformer and text_encoder to device and cast to weight_dtype
vae.to(accelerator.device, dtype=torch.float32)
vae.to(accelerator.device, dtype=weight_dtype)
Copy link
Member

Choose a reason for hiding this comment

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

I think it should be like:

if args.upcast_vae:
    vae.to(accelerator.device, dtype=torch.float32)
else:
    vae.to(accelerator.device, dtype=weight_dtype)

With upcast_vae being added to the arguments?

transformer.to(accelerator.device, dtype=weight_dtype)
text_encoder_one.to(accelerator.device, dtype=weight_dtype)
text_encoder_two.to(accelerator.device, dtype=weight_dtype)
Expand Down