fffiloni commited on
Commit
e720880
1 Parent(s): 74d58ef

Update imagic.py

Browse files
Files changed (1) hide show
  1. imagic.py +6 -3
imagic.py CHANGED
@@ -272,8 +272,10 @@ class ImagicStableDiffusionPipeline(DiffusionPipeline):
272
  loss = F.mse_loss(noise_pred, noise, reduction="none").mean([1, 2, 3]).mean()
273
  accelerator.backward(loss)
274
 
275
- optimizer.step()
276
- optimizer.zero_grad()
 
 
277
 
278
  # Checks if the accelerator has performed an optimization step behind the scenes
279
  if accelerator.sync_gradients:
@@ -314,7 +316,8 @@ class ImagicStableDiffusionPipeline(DiffusionPipeline):
314
  loss = F.mse_loss(noise_pred, noise, reduction="none").mean([1, 2, 3]).mean()
315
  accelerator.backward(loss)
316
 
317
- with torch.no_grad():
 
318
  optimizer.step()
319
  optimizer.zero_grad()
320
 
 
272
  loss = F.mse_loss(noise_pred, noise, reduction="none").mean([1, 2, 3]).mean()
273
  accelerator.backward(loss)
274
 
275
+ with torch.no_grad()
276
+ torch.cuda.empty_cache()
277
+ optimizer.step()
278
+ optimizer.zero_grad()
279
 
280
  # Checks if the accelerator has performed an optimization step behind the scenes
281
  if accelerator.sync_gradients:
 
316
  loss = F.mse_loss(noise_pred, noise, reduction="none").mean([1, 2, 3]).mean()
317
  accelerator.backward(loss)
318
 
319
+ with torch.no_grad()
320
+ torch.cuda.empty_cache()
321
  optimizer.step()
322
  optimizer.zero_grad()
323