smoothieAI commited on
Commit
c133361
·
verified ·
1 Parent(s): 40a8b93

Update pipeline.py

Browse files
Files changed (1) hide show
  1. 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, num_frames, num_timesteps):
1010
- num_context_groups = (num_frames // (context_size-overlap))+1
1011
- context_indexes = []
1012
- for t in range(num_timesteps):
1013
- context_groups = []
1014
- for context_group_index in range(num_context_groups):
1015
- context_group = []
1016
- for i in range(context_size):
1017
- # calculate the frame index
1018
- frame_index = ((t+1) * context_group_index * (context_size-overlap)) + (offset * t) + i
1019
- # wrap around at the end
1020
- if frame_index >= num_frames:frame_index = frame_index % num_frames
1021
- context_group.append(frame_index)
1022
- context_groups.append(context_groups)
1023
- context_indexes.append(context_groups)
1024
- return context_indexes
 
 
 
 
 
 
 
 
 
 
 
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