(self, pipeline, step_index, timestep, callback_kwargs)
| 106 | tensor_inputs = ["prompt_embeds", "add_text_embeds", "add_time_ids"] |
| 107 | |
| 108 | def callback_fn(self, pipeline, step_index, timestep, callback_kwargs) -> Dict[str, Any]: |
| 109 | cutoff_step_ratio = self.config.cutoff_step_ratio |
| 110 | cutoff_step_index = self.config.cutoff_step_index |
| 111 | |
| 112 | # Use cutoff_step_index if it's not None, otherwise use cutoff_step_ratio |
| 113 | cutoff_step = ( |
| 114 | cutoff_step_index if cutoff_step_index is not None else int(pipeline.num_timesteps * cutoff_step_ratio) |
| 115 | ) |
| 116 | |
| 117 | if step_index == cutoff_step: |
| 118 | prompt_embeds = callback_kwargs[self.tensor_inputs[0]] |
| 119 | prompt_embeds = prompt_embeds[-1:] # "-1" denotes the embeddings for conditional text tokens. |
| 120 | |
| 121 | add_text_embeds = callback_kwargs[self.tensor_inputs[1]] |
| 122 | add_text_embeds = add_text_embeds[-1:] # "-1" denotes the embeddings for conditional pooled text tokens |
| 123 | |
| 124 | add_time_ids = callback_kwargs[self.tensor_inputs[2]] |
| 125 | add_time_ids = add_time_ids[-1:] # "-1" denotes the embeddings for conditional added time vector |
| 126 | |
| 127 | pipeline._guidance_scale = 0.0 |
| 128 | |
| 129 | callback_kwargs[self.tensor_inputs[0]] = prompt_embeds |
| 130 | callback_kwargs[self.tensor_inputs[1]] = add_text_embeds |
| 131 | callback_kwargs[self.tensor_inputs[2]] = add_time_ids |
| 132 | return callback_kwargs |
| 133 | |
| 134 | |
| 135 | class IPAdapterScaleCutoffCallback(PipelineCallback): |
nothing calls this directly
no outgoing calls
no test coverage detected