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

Remove autocast for v2.1 #144

Merged
merged 1 commit into from
Jan 21, 2023
Merged
Changes from all commits
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
35 changes: 17 additions & 18 deletions stable_diffusion_videos/image_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def generate_input_batches(pipeline, prompts, seeds, batch_size, height, width):
batch_is_ready = embeds_batch.shape[0] == batch_size or i + 1 == len(prompts)
if not batch_is_ready:
continue
yield batch_idx, embeds_batch, noise_batch
yield batch_idx, embeds_batch.type(torch.cuda.HalfTensor), noise_batch.type(torch.cuda.HalfTensor)
batch_idx += 1
del embeds_batch, noise_batch
torch.cuda.empty_cache()
Expand Down Expand Up @@ -181,23 +181,22 @@ def generate_images(
for batch_idx, embeds, noise in generate_input_batches(pipeline, [prompt] * num_images, seeds, batch_size, height, width):
print(f"Generating batch {batch_idx}")

with torch.autocast('cuda'):
outputs = pipeline(
text_embeddings=embeds,
latents=noise,
num_inference_steps=num_inference_steps,
guidance_scale=guidance_scale,
eta=eta,
height=height,
width=width,
output_type="pil" if not upsample else "numpy",
)['images']
if upsample:
images = []
for output in outputs:
images.append(pipeline.upsampler(output))
else:
images = outputs
outputs = pipeline(
text_embeddings=embeds,
latents=noise,
num_inference_steps=num_inference_steps,
guidance_scale=guidance_scale,
eta=eta,
height=height,
width=width,
output_type="pil" if not upsample else "numpy",
)['images']
if upsample:
images = []
for output in outputs:
images.append(pipeline.upsampler(output))
else:
images = outputs

for image in images:
frame_filepath = save_path / f"{seeds[frame_index]}{image_file_ext}"
Expand Down