From d11725174773b2d48a8afd870a351dd3198de3d2 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Wed, 15 Mar 2023 01:17:23 -0400 Subject: [PATCH] make step_callback work again in generate() call This PR fixes #2951 and restores the step_callback argument in the refactored generate() method. Note that this issue states that "something is still wrong because steps and step are zero." However, I think this is confusion over the call signature of the callback, which since the diffusers merge has been `callback(state:PipelineIntermediateState)` This is the test script that I used to determine that `step` is being passed correctly: ``` from pathlib import Path from invokeai.backend import ModelManager, PipelineIntermediateState from invokeai.backend.globals import global_config_dir from invokeai.backend.generator import Txt2Img def my_callback(state:PipelineIntermediateState, total_steps:int): print(f'callback(step={state.step}/{total_steps})') def main(): manager = ModelManager(Path(global_config_dir()) / "models.yaml") model = manager.get_model('stable-diffusion-1.5') print ('=== TXT2IMG TEST ===') steps=30 output = next(Txt2Img(model).generate(prompt='banana sushi', iterations=None, steps=steps, step_callback=lambda x: my_callback(x,steps) ) ) print(f'image={output.image}, seed={output.seed}, steps={output.params.steps}') if __name__=='__main__': main() ``` --- invokeai/backend/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/invokeai/backend/__init__.py b/invokeai/backend/__init__.py index 06066dd6b1..662700e9ba 100644 --- a/invokeai/backend/__init__.py +++ b/invokeai/backend/__init__.py @@ -10,6 +10,7 @@ from .generator import ( Img2Img, Inpaint ) +from .stable_diffusion.diffusers_pipeline import PipelineIntermediateState from .model_management import ModelManager from .safety_checker import SafetyChecker from .args import Args