Skip to content

Commit

Permalink
Free some resources after each step to avoid OOM
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmoise committed Aug 12, 2022
1 parent beb2f2d commit b25168e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion denoising_diffusion_pytorch/denoising_diffusion_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,10 @@ def train(self):
with self.accelerator.autocast():
loss = self.model(data)
loss = loss / self.gradient_accumulate_every
total_loss += loss.item()
total_loss += float(loss.item())

self.accelerator.backward(loss)
del loss

pbar.set_description(f'loss: {total_loss:.4f}')

Expand All @@ -847,6 +848,11 @@ def train(self):
utils.save_image(all_images, str(self.results_folder / f'sample-{milestone}.png'), nrow = int(math.sqrt(self.num_samples)))
self.save(milestone)

del milestone
del batches
del all_images_list
del all_images

self.step += 1
pbar.update(1)

Expand Down

0 comments on commit b25168e

Please sign in to comment.