Skip to content

Commit f8b4215

Browse files
committed
Hoist the autocast out of the loop.
1 parent 56c2e7c commit f8b4215

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

examples/text_to_image/train_text_to_image.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,10 @@ def collate_fn(examples):
732732
# run inference
733733
prompt = [args.validation_prompt]
734734
images = []
735-
for _ in range(args.num_validation_images):
736-
with torch.autocast(
737-
str(accelerator.device), enabled=accelerator.mixed_precision == "fp16"
738-
):
735+
with torch.autocast(
736+
str(accelerator.device), enabled=accelerator.mixed_precision == "fp16"
737+
):
738+
for _ in range(args.num_validation_images):
739739
images.append(pipeline(prompt).images[0])
740740

741741
for i, image in enumerate(images):

0 commit comments

Comments
 (0)