Update pipeline.py
Browse files- pipeline.py +27 -16
pipeline.py
CHANGED
@@ -1006,22 +1006,33 @@ class AnimateDiffPipeline(DiffusionPipeline, TextualInversionLoaderMixin, IPAdap
|
|
1006 |
|
1007 |
# divide the initial latents into context groups
|
1008 |
|
1009 |
-
def context_scheduler(context_size, overlap, offset,
|
1010 |
-
|
1011 |
-
|
1012 |
-
for
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1025 |
|
1026 |
context_indexes = context_scheduler(context_size, overlap, step, num_frames, len(timesteps))
|
1027 |
|
|
|
1006 |
|
1007 |
# divide the initial latents into context groups
|
1008 |
|
1009 |
+
def context_scheduler(context_size, overlap, offset, total_frames, total_timesteps):
|
1010 |
+
# Calculate the number of context groups based on frame count and context size
|
1011 |
+
number_of_context_groups = (total_frames // (context_size - overlap)) + 1
|
1012 |
+
# Initialize a list to store context indexes for all timesteps
|
1013 |
+
all_context_indexes = []
|
1014 |
+
# Iterate over each timestep
|
1015 |
+
for timestep in range(total_timesteps):
|
1016 |
+
# Initialize a list to store groups of context indexes for this timestep
|
1017 |
+
timestep_context_groups = []
|
1018 |
+
# Iterate over each context group
|
1019 |
+
for group_index in range(number_of_context_groups):
|
1020 |
+
# Initialize a list to store context indexes for this group
|
1021 |
+
context_group_indexes = []
|
1022 |
+
# Iterate over each index in the context group
|
1023 |
+
for index in range(context_size):
|
1024 |
+
# Calculate the frame index
|
1025 |
+
frame_index = ((timestep + 1) * group_index * (context_size - overlap)) + (offset * timestep) + index
|
1026 |
+
# If frame index exceeds total frames, wrap around
|
1027 |
+
if frame_index >= total_frames:
|
1028 |
+
frame_index %= total_frames
|
1029 |
+
# Add the frame index to the group's list
|
1030 |
+
context_group_indexes.append(frame_index)
|
1031 |
+
# Add the group's indexes to the timestep's list
|
1032 |
+
timestep_context_groups.append(context_group_indexes)
|
1033 |
+
# Add the timestep's context groups to the overall list
|
1034 |
+
all_context_indexes.append(timestep_context_groups)
|
1035 |
+
return all_context_indexes
|
1036 |
|
1037 |
context_indexes = context_scheduler(context_size, overlap, step, num_frames, len(timesteps))
|
1038 |
|