Skip to content

Commit

Permalink
[dreambooth] fix multi on gpu. (open-mmlab#2088)
Browse files Browse the repository at this point in the history
unwrap model on multi gpu
  • Loading branch information
patil-suraj authored Jan 24, 2023
1 parent 31336da commit fc8afa3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions examples/dreambooth/train_dreambooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,16 @@ def main(args):
" doing mixed precision training. copy of the weights should still be float32."
)

if unet.dtype != torch.float32:
raise ValueError(f"Unet loaded as datatype {unet.dtype}. {low_precision_error_string}")
if accelerator.unwrap_model(unet).dtype != torch.float32:
raise ValueError(
f"Unet loaded as datatype {accelerator.unwrap_model(unet).dtype}. {low_precision_error_string}"
)

if args.train_text_encoder and text_encoder.dtype != torch.float32:
raise ValueError(f"Text encoder loaded as datatype {text_encoder.dtype}. {low_precision_error_string}")
if args.train_text_encoder and accelerator.unwrap_model(text_encoder).dtype != torch.float32:
raise ValueError(
f"Text encoder loaded as datatype {accelerator.unwrap_model(text_encoder).dtype}."
f" {low_precision_error_string}"
)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down

0 comments on commit fc8afa3

Please sign in to comment.