-
Notifications
You must be signed in to change notification settings - Fork 456
Description
Feature Summary
Currently there's no way to abort/cancel an in-progress generate_image() or generate_video() call from the calling code.
Detailed Description
Summary
Currently there's no way to abort/cancel an in-progress generate_image() or generate_video() call from the calling code. This makes it impossible to handle user interrupts (Ctrl+C) or implement timeouts in applications using the library.
Problem
The progress callback is defined as:
typedef void (*sd_progress_cb_t)(int step, int steps, float time, void* data);Since it returns void, there's no way for the caller to signal "please stop" back to the library.
The underlying ggml library has an abort callback mechanism (ggml_abort_callback returning bool), but this isn't exposed through the stable-diffusion.cpp API.
Suggested Solutions
Any of these would work:
- Change progress callback to return bool - Return false to continue, true to abort:
typedef bool (*sd_progress_cb_t)(int step, int steps, float time, void* data);- Add a separate abort callback - Expose ggml's mechanism:
typedef bool (*sd_abort_cb_t)(void* data);
SD_API void sd_set_abort_callback(sd_abort_cb_t cb, void* data);- Add explicit cancel function - Set a flag that's checked during iteration:
SD_API void sd_cancel(sd_ctx_t* sd_ctx);Use Case
I'm developing Python bindings for stable-diffusion.cpp. Without an abort mechanism, the only option is to kill the process.
Related user-reported issue
Alternatives you considered
No response
Additional context
No response