Set grad enabled if is_train and train_text_encoder

We only want to be enabling grad if we are training.
This commit is contained in:
rockerBOO
2023-11-07 11:59:30 -05:00
parent 9c591bdb12
commit 569ca72fc4

View File

@@ -145,7 +145,7 @@ class NetworkTrainer:
latents = latents * self.vae_scale_factor latents = latents * self.vae_scale_factor
b_size = latents.shape[0] b_size = latents.shape[0]
with torch.set_grad_enabled(train_text_encoder), accelerator.autocast(): with torch.set_grad_enabled(is_train and train_text_encoder), accelerator.autocast():
# Get the text embedding for conditioning # Get the text embedding for conditioning
if args.weighted_captions: if args.weighted_captions:
text_encoder_conds = get_weighted_text_embeddings( text_encoder_conds = get_weighted_text_embeddings(