Update pipeline.py
Browse files- pipeline.py +22 -14
pipeline.py
CHANGED
@@ -1494,26 +1494,34 @@ class AnimateDiffPipeline(DiffusionPipeline, TextualInversionLoaderMixin, IPAdap
|
|
1494 |
|
1495 |
# sum the noise predictions for the unconditional and text conditioned noise
|
1496 |
start_guidance_time = time.time()
|
1497 |
-
|
1498 |
-
# if do_classifier_free_guidance:
|
1499 |
-
# noise_pred_uncond, noise_pred_text = noise_pred.chunk(2)
|
1500 |
-
|
1501 |
-
# # add the ending frames from noise_pred_uncond to the start of the noise_pred_uncond_sum
|
1502 |
-
# noise_pred_uncond_sum[:, :,current_context_indexes, :, :] += noise_pred_uncond
|
1503 |
-
# noise_pred_text_sum[:, :,current_context_indexes, :, :] += noise_pred_text
|
1504 |
-
# #increase the counter for the ending frames
|
1505 |
-
# latent_counter[current_context_indexes] += 1
|
1506 |
-
|
1507 |
|
1508 |
if do_classifier_free_guidance:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1509 |
# Split tensor along its first dimension
|
1510 |
noise_pred_uncond, noise_pred_text = torch.chunk(noise_pred, 2, dim=0)
|
1511 |
|
1512 |
-
#
|
1513 |
-
|
1514 |
-
|
|
|
|
|
|
|
|
|
|
|
1515 |
|
1516 |
-
#
|
|
|
|
|
1517 |
latent_counter[current_context_indexes] += 1
|
1518 |
|
1519 |
print("guidance time", time.time() - start_guidance_time)
|
|
|
1494 |
|
1495 |
# sum the noise predictions for the unconditional and text conditioned noise
|
1496 |
start_guidance_time = time.time()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1497 |
|
1498 |
if do_classifier_free_guidance:
|
1499 |
+
# # Split tensor along its first dimension
|
1500 |
+
# noise_pred_uncond, noise_pred_text = torch.chunk(noise_pred, 2, dim=0)
|
1501 |
+
|
1502 |
+
# # Efficient in-place addition using advanced indexing
|
1503 |
+
# noise_pred_uncond_sum[..., current_context_indexes, :, :] += noise_pred_uncond
|
1504 |
+
# noise_pred_text_sum[..., current_context_indexes, :, :] += noise_pred_text
|
1505 |
+
|
1506 |
+
# # Efficient in-place increment for latent_counter
|
1507 |
+
# latent_counter[current_context_indexes] += 1
|
1508 |
+
|
1509 |
+
|
1510 |
# Split tensor along its first dimension
|
1511 |
noise_pred_uncond, noise_pred_text = torch.chunk(noise_pred, 2, dim=0)
|
1512 |
|
1513 |
+
# Reshape or expand noise_pred_uncond and noise_pred_text to match the dimensions of the sum tensors
|
1514 |
+
# This step depends on the dimensions of your tensors and how they need to align for the operation
|
1515 |
+
expanded_noise_pred_uncond = noise_pred_uncond.expand_as(noise_pred_uncond_sum[..., current_context_indexes, :, :])
|
1516 |
+
expanded_noise_pred_text = noise_pred_text.expand_as(noise_pred_text_sum[..., current_context_indexes, :, :])
|
1517 |
+
|
1518 |
+
# Perform batch addition
|
1519 |
+
noise_pred_uncond_sum[..., current_context_indexes, :, :] += expanded_noise_pred_uncond
|
1520 |
+
noise_pred_text_sum[..., current_context_indexes, :, :] += expanded_noise_pred_text
|
1521 |
|
1522 |
+
# Batch increment for latent_counter
|
1523 |
+
# Here, you need to ensure that the addition is done correctly depending on how latent_counter is structured
|
1524 |
+
# If latent_counter is a tensor, you might use something like:
|
1525 |
latent_counter[current_context_indexes] += 1
|
1526 |
|
1527 |
print("guidance time", time.time() - start_guidance_time)
|