Skip to content

Commit

Permalink
Add invocation cancellation logic to patchers
Browse files Browse the repository at this point in the history
  • Loading branch information
StAlKeR7779 committed Jul 19, 2024
1 parent 83a86ab commit 39e10d8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions invokeai/backend/stable_diffusion/extensions_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ def _regenerate_ordered_callbacks(self):
self._ordered_callbacks[callback_type] = sorted(callbacks, key=lambda x: x.metadata.order)

def run_callback(self, callback_type: ExtensionCallbackType, ctx: DenoiseContext):
# TODO: add to patchers too?
# and if so, should it be only in beginning of function or in for loop
if self._is_canceled and self._is_canceled():
raise CanceledException

Expand All @@ -55,6 +53,9 @@ def run_callback(self, callback_type: ExtensionCallbackType, ctx: DenoiseContext

@contextmanager
def patch_extensions(self, context: DenoiseContext):
if self._is_canceled and self._is_canceled():
raise CanceledException

with ExitStack() as exit_stack:
for ext in self._extensions:
exit_stack.enter_context(ext.patch_extension(context))
Expand All @@ -63,5 +64,8 @@ def patch_extensions(self, context: DenoiseContext):

@contextmanager
def patch_unet(self, state_dict: Dict[str, torch.Tensor], unet: UNet2DConditionModel):
if self._is_canceled and self._is_canceled():
raise CanceledException

# TODO: create logic in PR with extension which uses it
yield None

0 comments on commit 39e10d8

Please sign in to comment.