leejet / stable-diffusion.cpp

Stable Diffusion and Flux in pure C/C++
MIT License
3.36k stars 284 forks source link

Question Regarding Reusing Context for Multiple Generations in Example Code #437

Closed grorge123 closed 2 days ago

grorge123 commented 2 days ago

I noticed that in the example provided in stable diffusion.cpp, a context is created and used for a single image generation (either image-to-image or text-to-image). I wondered if it’s possible to reuse the same context for multiple generating without recreating it each time.

I tried reusing the context for multiple generations but encountered a segmentation fault either in image-to-image or text-to-image. For example, I copy and paste results = txt2img(...); after the original generate results code section.

Could you provide an example of a context that has been reused for multiple generations, or is this approach not supported?

SkutteOleg commented 2 days ago

Set free_params_immediately to false when calling new_sd_ctx

https://github.com/leejet/stable-diffusion.cpp/issues/366#issuecomment-2308929569

grorge123 commented 2 days ago

It also works for me. Thank you.