Update imagic.py
Browse files
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 |
-
|
276 |
-
|
|
|
|
|
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 |
|