Commit 2759cb0 for stable-diffusion.cpp
commit 2759cb05c1ece1408506bcced0f094af9e823e10
Author: leejet <leejet714@gmail.com>
Date: Sat Dec 5 20:19:11 2026 +0800
refactor(api): unify generation and DGL progress callbacks (#2531)
diff --git a/docs/development/c_api.md b/docs/development/c_api.md
index c41bfdf..9f8cc53 100644
--- a/docs/development/c_api.md
+++ b/docs/development/c_api.md
@@ -58,7 +58,9 @@ copying tensor payloads. DGL outputs are adapted at the result boundary.
Internal producers with an `sd::Tensor<T>` can
move it directly into a handle. Video results keep per-frame tensors and assemble
a contiguous video tensor only when requested. Cached assembly is synchronized.
-Preview tensors are independent snapshots and may be retained by callbacks.
+Generation shares the DGL context's progress registration and keeps one progress
+dispatcher across the DGL programs in a batch. Preview tensors in a sampling
+event are independent snapshots and may be retained by the callback.
Results retain the exact compiled DGL source. WebUI conversion and media metadata
embedding are separate from inference and never rebuild the execution program.
`src/api/generation_metadata.cpp` parses the source once to produce image
diff --git a/docs/development/dgl.md b/docs/development/dgl.md
index d96b381..cb1059b 100644
--- a/docs/development/dgl.md
+++ b/docs/development/dgl.md
@@ -60,7 +60,8 @@ The first two statements describe which model and conditions to evaluate and how
to combine the predictions. They keep the model reachable. The sampling
operation drives the solver and evaluates that predictor at each required
step. The resource plan therefore accounts for diffusion weights during
-`sample`. Each sampling call owns its own prediction history and progress state.
+`sample`. Each sampling call owns its prediction history and reports sampling
+events through the run's shared progress dispatcher.
## What the context retains
@@ -71,6 +72,7 @@ context can release it after its last use. Releasing a script binding and
evicting cached weights are therefore separate lifetime decisions.
One context runs one program at a time. Each run gets a fresh placement plan
-and its own progress, preview and cancellation state. Two runs of the same
+and its own progress and cancellation state. The active sampling pass sends
+its selected previews with the completed step event. Two runs of the same
source can choose different weight placement as cached resources or available
memory change. See [context execution settings](../dgl.md#context-execution-settings).
diff --git a/docs/dgl.md b/docs/dgl.md
index 5e4fd20..0cb01c8 100644
--- a/docs/dgl.md
+++ b/docs/dgl.md
@@ -1004,14 +1004,14 @@ observer = preview(decoder = tae)
latent = sample(start, sigmas, predict = guided, rng = rng, observer = observer)
```
-`preview()` needs no decoder for latent projection. The context's preview
-callback selects the mode, interval and noisy or denoised previews. A sampling
+`preview()` needs no decoder for latent projection. The context's progress
+options select the mode, interval and noisy or denoised previews. A sampling
call without an observer uses a shared projection preview observer. Without a
decoder, preview falls back to projection. An explicit observer is only needed
to supply a decoder or custom preview settings. An observer can be reused
across sampling calls; each call has its own observation state. The observer
retains its decoder, and decoding resources are acquired only for a selected
-preview and released afterwards. Without an enabled preview callback, it
+preview and released afterwards. With previews disabled, it
performs no preview decoding.
### Media dimensions
@@ -1826,8 +1826,10 @@ the capacity changes.
### File access and memory budgets
-Install a file access callback with `sd_dgl_ctx_set_file_access_callback` before
-running scripts in a context. The callback receives a UTF-8 path and an access
+Install a file access callback with `sd_dgl_ctx_set_file_access_callback` on an
+idle context. The setter returns `sd_status_t`. A DGL context borrowed from
+`sd_ctx_get_dgl_ctx()` shares its file access policy with generation and model
+probing. The callback receives a UTF-8 path and an access
type for input reads, model reads or writes. Returning false ends the run with a
file access error. Keep its user data valid throughout the run. Model reads
include checkpoints, referenced shards and external tokenizers. Without a
@@ -1898,7 +1900,7 @@ Each run prepares one weight-placement plan for the graph, including models
already cached in the context. Compilation tracks actual model use separately
from metadata queries and model captures. For example, `latent_shape` does not
need VAE weights, while a VAE preview observer keeps the decoder in the sampling
-working set when VAE/TAE preview callbacks are enabled. Unrelated scalar
+working set when the progress options enable VAE/TAE previews. Unrelated scalar
operations do not change the model-use phases.
If a loader omits `backend`, the run compares available GPU budgets before
@@ -1925,24 +1927,24 @@ allocation checks.
### Progress, preview and cancellation
-Register callbacks on an idle context with `sd_dgl_ctx_set_progress_callback`
-and `sd_dgl_ctx_set_preview_callback`. They run synchronously on the executing
-thread and receive events for that context's current run. A null callback
-clears the registration. The sampling pass counter starts at one on each
-run. Progress can report model loading in tensors, sampling in steps, video
-upscaling in frames, or a stage with no known total.
-Without a progress callback, the DGL execution layer displays sampling and
-weight-loading progress bars. Set `sd_dgl_ctx_set(ctx, "console_progress", "on")`
-on an idle context to display those bars alongside a progress callback.
+Register a callback on an idle context with `sd_dgl_ctx_set_progress_callback`.
+It uses the same event and options as the [generation C API](guides/c_api.md#progress-and-previews).
+It runs synchronously on the executing thread. A null callback clears the
+registration. Progress can report model loading in tensors, sampling in steps,
+tiling in tiles, video upscaling in frames, or a stage with no known total.
+Without a callback, DGL displays its built-in progress bars.
+Set `sd_progress_options_t.console_progress` to display the bars alongside a callback.
The default observer handles previews. Preview mode `proj` uses latent projection. Modes `tae` and `vae`
use the decoder supplied to `preview(decoder=...)`, falling back to projection. A positive interval
previews each matching completed logical step. Intermediate model evaluations,
such as Heun's first evaluation, do not produce duplicate previews or progress
events. Zero previews the final step of the first sampling pass.
-A negative interval selects the step at its absolute value. The callback
-receives the pass number, total steps and borrowed frame tensors. Use
-`sd_tensor_retain` if a frame must outlive the callback.
+A negative interval selects the step at its absolute value. Each completed
+step emits one sampling event. Its `sd_sampling_progress_t` payload contains
+the pass number and any selected denoised and noisy frame tensors. Passes
+start at one on each run. Use `sd_tensor_retain` if a frame must outlive
+the callback.
`sd_dgl_ctx_cancel` can be called from a callback or another thread. An
idle context accepts the call without queuing a cancellation. The current
diff --git a/docs/dgl/README.md b/docs/dgl/README.md
index 39c595a..f85993e 100644
--- a/docs/dgl/README.md
+++ b/docs/dgl/README.md
@@ -115,4 +115,4 @@ and [NumPy tensor files](../dgl.md#tensor-files).
| [PuLID-Flux](../models/pulid.md) | [Identity-guided generation](pulid/pulid-flux1-schnell.dgl) |
| [RelayVSR](../models/relay_vsr.md) | [Upscale a video](relay_vsr/relayvsr-x2-video-upscale.dgl) · [Upscale an image](relay_vsr/relayvsr-x2-image-upscale.dgl) |
| [SeedVR2](../models/seedvr2.md) | [Upscale an image](seedvr2/seedvr2-3b-image-upscale.dgl) · [Upscale a video](seedvr2/seedvr2-3b-video-upscale.dgl) |
-| [TAESD](../models/taesd.md) | [SD 1.5 decoding with TAESD](taesd/sd1-5-taesd-preview.dgl). The CLI writes the final PNG. Intermediate previews require a [host preview callback](../dgl.md#progress-preview-and-cancellation) in `tae` mode. |
+| [TAESD](../models/taesd.md) | [SD 1.5 decoding with TAESD](taesd/sd1-5-taesd-preview.dgl). The CLI writes the final PNG. For intermediate previews, pass `--preview on` or register a [progress callback](../dgl.md#progress-preview-and-cancellation) with preview mode `tae`. |
diff --git a/docs/guides/c_api.md b/docs/guides/c_api.md
index cebea0c..c353553 100644
--- a/docs/guides/c_api.md
+++ b/docs/guides/c_api.md
@@ -80,10 +80,14 @@ preserves the current configuration. Model setters return `SD_STATUS_BUSY`
while model probing is in progress, including from file-access callbacks.
The execution settings and component cache continue to serve generation and the
DGL context borrowed through `sd_ctx_get_dgl_ctx()`. The borrowed pointer stays
-valid until `sd_ctx_free()`. Run scripts and generation calls one at a time. Set
-file-access callbacks for generated programs and scripts through
-`sd_ctx_set_file_access_callback()` and `sd_dgl_ctx_set_file_access_callback()`
-respectively.
+valid until `sd_ctx_free()`. Run scripts and generation calls one at a time.
+
+Register a file access callback once with `sd_ctx_set_file_access_callback()`
+or `sd_dgl_ctx_set_file_access_callback()` on the borrowed context. Both setters
+return `sd_status_t` and update the same policy for generation, model probing
+and DGL scripts. Passing a null callback clears the registration. Both setters
+return `SD_STATUS_BUSY` during generation, DGL execution or model probing.
+Use a separately created DGL context when a script needs an independent policy.
Use `sd_dgl_ctx_unload_models()` to release cached model components and reload
them on demand. It clears idle buffer caches on supported backends and returns
@@ -175,18 +179,46 @@ The bundled CLI and server retain these modes as strings and pass them directly
to setters. Enum parsers, enum name helpers, parameter configuration layouts and
name tables are internal and are not exported by the shared library.
-Preview registration also uses strings:
+## Progress and previews
+
+Register a progress callback on an idle context. Both context types use the
+same event and options. A DGL context borrowed from `sd_ctx_get_dgl_ctx()`
+shares the registration with its owning context.
```c
-sd_status_t status = sd_set_preview_callback(callback, "proj", 5,
- true, false, user_data);
-/* Disable registration when the context is idle. */
-sd_set_preview_callback(NULL, "none", 1, false, false, NULL);
+const sd_progress_options_t options = {
+ .console_progress = true,
+ .preview = { .mode = "proj", .interval = 5, .denoised = true },
+};
+sd_status_t status = sd_ctx_set_progress_callback(ctx, callback, user_data, &options);
+/* For a DGL context, call sd_dgl_ctx_set_progress_callback with the same options. */
+/* Clear registration when idle. */
+sd_ctx_set_progress_callback(ctx, NULL, NULL, NULL);
```
-Preview modes are `none`, `proj`, `tae` and `vae`. A null or unknown mode returns
-`SD_STATUS_INVALID_ARGUMENT` and preserves the previous registration. See the
-public header for interval, noisy/denoised and callback lifetime semantics.
+With a callback registered, set `console_progress` to keep the library's
+progress bars visible. A null options pointer subscribes to progress with
+previews and console output disabled. Passing a null callback clears the
+registration, ignores the options, and restores console progress.
+
+The event's `stage` is a string. On `sampling`, cast `stage_data` to
+`const sd_sampling_progress_t*` for the sampling pass, step time and optional
+frames. On counted `loading` events, it points to `sd_loading_progress_t` with
+bytes processed and elapsed seconds. Other stages can be displayed using the
+common fields. A `total` of zero means the total is unknown.
+
+Sampling emits one event at the start of each pass and one per completed
+logical step. A step can carry both denoised and noisy frames. A positive
+preview interval selects every Nth step, a negative interval selects one
+step by its absolute value, and zero selects the last step of the first
+pass. Pass numbers start at one for each request and continue across the
+images of a batch. Preview modes are `none`, `proj`, `tae` and `vae`. A null
+preview mode disables previews. An unknown mode preserves the previous
+registration and returns `SD_STATUS_INVALID_ARGUMENT`.
+
+Events run synchronously on the executing thread. Callbacks must not throw.
+Data is borrowed for the duration of the callback. Use `sd_tensor_retain()`
+to keep an individual frame.
## Tensor data
@@ -523,6 +555,19 @@ their initialization/formatting helpers, `new_sd_ctx()`, `free_sd_ctx()`,
have been removed. Applications and bindings must migrate and rebuild; no
compatibility layer is provided.
+`sd_dgl_ctx_set_file_access_callback()` now returns `sd_status_t`. Success is
+`SD_STATUS_OK` (`0`). Replace boolean checks with an explicit status check.
+
+```c
+if (sd_dgl_ctx_set_file_access_callback(ctx, callback, userdata) != SD_STATUS_OK) {
+ /* Handle registration failure. */
+}
+```
+
+Register or clear the policy through either handle when the DGL context is
+borrowed from `sd_ctx_get_dgl_ctx()`. To keep separate policies, create a
+standalone DGL context for scripts.
+
Create context/image/video options with the corresponding constructor, populate
them through the shared typed setters, and use `sd_ctx_create()`,
`sd_generate_image()` and `sd_generate_video()`. Read or retain outputs through
diff --git a/docs/models/taesd.md b/docs/models/taesd.md
index ad8fb4f..4348dd1 100644
--- a/docs/models/taesd.md
+++ b/docs/models/taesd.md
@@ -102,8 +102,9 @@ tiny autoencoder matching that model. See [Web UI guide](../../examples/server/R
The [SD 1.5 example](../dgl/taesd/sd1-5-taesd-preview.dgl) uses TAESD to
decode the final image and passes the same decoder to `preview(decoder = vae)`.
-Running it with `sd-cli -M dgl` writes the final PNG. To receive intermediate
-images, run it in a host that registers a DGL preview callback in `"tae"` mode.
+Running it with `sd-cli -M dgl` writes the final PNG. Add `--preview on` for
+intermediate images. Applications can receive them by registering a DGL
+progress callback with preview mode `"tae"`.
See [progress and previews](../dgl.md#progress-preview-and-cancellation).
#### Run a script
diff --git a/examples/cli/dgl.cpp b/examples/cli/dgl.cpp
index 276e8d4..d10273b 100644
--- a/examples/cli/dgl.cpp
+++ b/examples/cli/dgl.cpp
@@ -241,7 +241,7 @@ public:
}
};
-int DGLModeParams::run(const SDContextParams& options, bool embed_metadata, const DGLPreviewOptions& preview) const {
+int DGLModeParams::run(const SDContextParams& options, bool embed_metadata, sd_generation_progress_cb_t callback, void* userdata, const sd_progress_options_t& progress) const {
try {
if (script_path.empty()) {
const auto* catalog = sd_dgl_builtin_catalog();
@@ -295,10 +295,8 @@ int DGLModeParams::run(const SDContextParams& options, bool embed_metadata, cons
check_dgl(raw_context != nullptr);
std::unique_ptr<sd_dgl_ctx_t, decltype(&sd_dgl_ctx_free)> context(raw_context, sd_dgl_ctx_free);
check_dgl(options.configure_dgl(context.get()));
- if (preview.callback) {
- // Decoder-based mode so the script's preview(decoder = ...) argument, not the host,
- // selects between projection and decoding; tae and vae behave identically with a decoder.
- check_dgl(sd_dgl_ctx_set_preview_callback(context.get(), preview.callback, "tae", preview.interval, preview.denoised, preview.noisy, preview.data) == SD_STATUS_OK);
+ if (callback) {
+ check_dgl(sd_dgl_ctx_set_progress_callback(context.get(), callback, userdata, &progress) == SD_STATUS_OK);
}
check_dgl(sd_dgl_ctx_set(context.get(), "embed_metadata", embed_metadata ? "on" : "off"));
if (!max_ram.empty())
diff --git a/examples/cli/dgl.h b/examples/cli/dgl.h
index db0503b..f4893d6 100644
--- a/examples/cli/dgl.h
+++ b/examples/cli/dgl.h
@@ -18,14 +18,6 @@ using DGLScriptArgs = std::map<std::string, std::string, std::less<>>;
void apply_dgl_args(std::string& source, const DGLScriptArgs& args);
-struct DGLPreviewOptions {
- sd_dgl_preview_cb_t callback = nullptr;
- int interval = 0;
- bool denoised = false;
- bool noisy = false;
- void* data = nullptr;
-};
-
struct DGLModeParams {
std::string script_path;
std::string write_builtins_path;
@@ -41,7 +33,7 @@ struct DGLModeParams {
ArgOptions get_options();
bool has_options() const;
bool validate() const;
- int run(const SDContextParams& options, bool embed_metadata, const DGLPreviewOptions& preview) const;
+ int run(const SDContextParams& options, bool embed_metadata, sd_generation_progress_cb_t callback, void* userdata, const sd_progress_options_t& progress) const;
};
#endif // __EXAMPLES_CLI_DGL_H__
diff --git a/examples/cli/main.cpp b/examples/cli/main.cpp
index 2facf91..63f6471 100644
--- a/examples/cli/main.cpp
+++ b/examples/cli/main.cpp
@@ -358,16 +358,19 @@ std::string format_frame_idx(std::string pattern, int frame_idx) {
int continuous_preview_counter = 0;
-void step_callback(int step, int frame_count, const sd_tensor_t* const* tensors, bool is_noisy, void* data) {
+static void preview_progress(const sd_generation_progress_t* progress, void* data) noexcept try {
+ if (strcmp(progress->stage, "sampling") != 0 || !progress->stage_data)
+ return;
+ const auto& sampling = *static_cast<const sd_sampling_progress_t*>(progress->stage_data);
+ const auto* cli_params = static_cast<const SDCliParams*>(data);
+ const auto& frames = cli_params->preview_noisy ? sampling.noisy : sampling.denoised;
+ const int frame_count = frames.frame_count;
+ if (frame_count == 0)
+ return;
std::vector<SDImage> views;
for (int i = 0; i < frame_count; ++i)
- views.push_back(tensor_image_view(tensors[i]));
+ views.push_back(tensor_image_view(frames.frames[i]));
SDImage* image = views.data();
- (void)step;
- (void)is_noisy;
- SDCliParams* cli_params = (SDCliParams*)data;
- // is_noisy is set to true if the preview corresponds to noisy latents, false if it's denoised latents
- // unused in this app, it will either be always noisy or always denoised here
if (frame_count == 1) {
fs::path path = fs::u8path(cli_params->preview_path.empty() ? "preview.png" : cli_params->preview_path);
if (encoded_image_format_from_path(path.u8string()) == EncodedImageFormat::UNKNOWN)
@@ -396,11 +399,8 @@ void step_callback(int step, int frame_count, const sd_tensor_t* const* tensors,
LOG_ERROR("save preview video to '%s' failed", path.u8string().c_str());
}
}
-}
-
-void dgl_step_callback(const sd_preview_info_t* info, int step, int frame_count, const sd_tensor_t* const* frames, bool is_noisy, void* data) {
- (void)info;
- step_callback(step, frame_count, frames, is_noisy, data);
+} catch (const std::exception& error) {
+ LOG_ERROR("preview failed: %s", error.what());
}
static fs::path get_video_audio_sidecar_path(const SDCliParams& cli_params) {
@@ -574,19 +574,16 @@ int main(int argc, const char* argv[]) {
sd_set_log_callback(sd_log_cb, (void*)&cli_params);
parse_args(argc, argv, cli_params, ctx_params, gen_params);
+ const bool preview_enabled = cli_params.preview_method != "none" && cli_params.preview_method != "off";
+ sd_progress_options_t progress_options{
+ true, {cli_params.preview_method.c_str(), cli_params.preview_interval, !cli_params.preview_noisy, cli_params.preview_noisy}};
if (cli_params.mode == DGL) {
- DGLPreviewOptions preview;
- if (cli_params.preview_method != previews_str[0] && cli_params.preview_method != "off") {
- if (cli_params.preview_method != "on") {
- LOG_WARN("DGL previews use the method selected by the script. Use --preview on to enable previews without this warning.");
- }
- preview.callback = dgl_step_callback;
- preview.interval = cli_params.preview_interval;
- preview.denoised = !cli_params.preview_noisy;
- preview.noisy = cli_params.preview_noisy;
- preview.data = &cli_params;
- }
- return cli_params.dgl.run(ctx_params, gen_params.embed_image_metadata, preview);
+ if (preview_enabled && cli_params.preview_method != "on")
+ LOG_WARN("DGL previews use the method selected by the script. Use --preview on to enable previews without this warning.");
+ // A decoder supplied by the script takes precedence over projection.
+ progress_options.preview.mode = "tae";
+ return cli_params.dgl.run(ctx_params, gen_params.embed_image_metadata,
+ preview_enabled ? preview_progress : nullptr, &cli_params, progress_options);
}
if (cli_params.mode == METADATA) {
@@ -606,16 +603,6 @@ int main(int argc, const char* argv[]) {
if (gen_params.fps)
cli_params.preview_fps = *gen_params.fps;
- if (sd_set_preview_callback(step_callback,
- cli_params.preview_method.c_str(),
- cli_params.preview_interval,
- !cli_params.preview_noisy,
- cli_params.preview_noisy,
- (void*)&cli_params) != SD_STATUS_OK) {
- LOG_ERROR("%s", sd_get_last_error());
- return 1;
- }
-
LOG_VERBOSE("version: %s", version_string().c_str());
LOG_VERBOSE("%s", sd_get_system_info());
LOG_DEBUG("%s", cli_params.to_string().c_str());
@@ -783,6 +770,12 @@ int main(int argc, const char* argv[]) {
return 1;
}
+ if (preview_enabled &&
+ sd_ctx_set_progress_callback(sd_ctx.get(), preview_progress, &cli_params, &progress_options) != SD_STATUS_OK) {
+ LOG_ERROR("%s", sd_get_last_error());
+ return 1;
+ }
+
SDImageOwner prompt_image;
sd_set_prompt_image_callback(
sd_ctx.get(), [](const char* source, void* data, const sd_tensor_t** image_out) -> bool {
diff --git a/examples/server/async_jobs.cpp b/examples/server/async_jobs.cpp
index 2b05a9f..bf66c56 100644
--- a/examples/server/async_jobs.cpp
+++ b/examples/server/async_jobs.cpp
@@ -54,19 +54,12 @@ public:
}
};
-static void preview_callback(int step, int frame_count, const sd_tensor_t* const* tensors, bool is_noisy, void* data) {
- std::vector<SDImage> views;
- for (int i = 0; i < frame_count; ++i)
- views.push_back(tensor_image_view(tensors[i]));
- SDImage* frames = views.data();
- (void)is_noisy;
- if (frame_count <= 0 || frames == nullptr || frames[0].data == nullptr) {
+static void update_job_preview(AsyncGenerationJob& job, const sd_generation_progress_t& progress, const sd_sampling_progress_t& sampling) {
+ if (sampling.denoised.frame_count == 0)
+ return;
+ const auto frame = tensor_image_view(sampling.denoised.frames[0]);
+ if (!frame.data)
return;
- }
-
- AsyncGenerationJob* job = static_cast<AsyncGenerationJob*>(data);
- const SDImage& frame = frames[0];
- const sd_preview_info_t info = sd_get_preview_info();
auto image_bytes = encode_image_to_vector(EncodedImageFormat::PNG,
frame.data,
@@ -80,28 +73,11 @@ static void preview_callback(int step, int frame_count, const sd_tensor_t* const
}
std::string b64 = base64_encode(image_bytes);
- std::lock_guard<std::mutex> lock(job->preview_mutex);
- job->preview_b64 = std::move(b64);
- job->preview_step = step < 0 ? -step : step;
- job->preview_pass = info.sample_pass;
- job->preview_total_steps = info.total_steps;
-}
-
-static void clear_preview_callback() {
- sd_set_preview_callback(nullptr, "none", 1, false, false, nullptr);
-}
-
-static void set_preview_callback(AsyncGenerationJob& job) {
- const auto& mode = job.kind == AsyncJobKind::ImgGen ? job.img_gen.preview_mode : job.vid_gen.preview_mode;
- if (mode == "none")
- return;
- int interval = job.kind == AsyncJobKind::ImgGen
- ? job.img_gen.preview_interval
- : job.vid_gen.preview_interval;
- if (interval <= 0) {
- interval = 1;
- }
- sd_set_preview_callback(preview_callback, mode.c_str(), interval, true, false, &job);
+ std::lock_guard<std::mutex> lock(job.preview_mutex);
+ job.preview_b64 = std::move(b64);
+ job.preview_step = int(progress.completed);
+ job.preview_pass = sampling.sample_pass;
+ job.preview_total_steps = int(progress.total);
}
static void update_job_progress(AsyncGenerationJob& job, const char* stage, const char* detail = "", int sample_pass = -1, int64_t completed = 0, int64_t total = 0, const char* unit = "") {
@@ -128,50 +104,44 @@ static void finish_job_progress(AsyncGenerationJob& job) {
static void job_progress_callback(const sd_generation_progress_t* progress, void* data) noexcept {
try {
- auto& job = *static_cast<AsyncGenerationJob*>(data);
+ auto& job = *static_cast<AsyncGenerationJob*>(data);
+ const auto* sampling = std::string_view(progress->stage) == "sampling"
+ ? static_cast<const sd_sampling_progress_t*>(progress->stage_data)
+ : nullptr;
update_job_progress(job, progress->stage, progress->detail,
- progress->sample_pass, progress->completed, progress->total, progress->unit);
+ sampling ? sampling->sample_pass : -1, progress->completed, progress->total, progress->unit);
+ if (sampling)
+ update_job_preview(job, *progress, *sampling);
} catch (...) {
// Progress callbacks must not unwind into the generation context.
}
}
-class JobCallbacksGuard {
+class JobProgressGuard {
sd_ctx_t* ctx_;
+ sd_status_t status_;
public:
- JobCallbacksGuard(sd_ctx_t* ctx, AsyncGenerationJob& job)
+ JobProgressGuard(sd_ctx_t* ctx, AsyncGenerationJob& job)
: ctx_(ctx) {
- clear_preview_callback();
- set_preview_callback(job);
- sd_set_generation_progress_callback(ctx_, job_progress_callback, &job);
- }
-
- ~JobCallbacksGuard() {
- sd_set_generation_progress_callback(ctx_, nullptr, nullptr);
- clear_preview_callback();
+ sd_progress_options_t options{};
+ options.console_progress = true;
+ if (job.kind == AsyncJobKind::ImgGen)
+ options.preview = {job.img_gen.preview_mode.c_str(), std::max(1, job.img_gen.preview_interval), true, false};
+ else if (job.kind == AsyncJobKind::VidGen)
+ options.preview = {job.vid_gen.preview_mode.c_str(), std::max(1, job.vid_gen.preview_interval), true, false};
+ status_ = sd_ctx_set_progress_callback(ctx_, job_progress_callback, &job, &options);
}
- JobCallbacksGuard(const JobCallbacksGuard&) = delete;
- JobCallbacksGuard& operator=(const JobCallbacksGuard&) = delete;
-};
-
-class DglJobProgressGuard {
- sd_dgl_ctx_t* ctx_;
-
-public:
- DglJobProgressGuard(sd_dgl_ctx_t* ctx, AsyncGenerationJob& job) : ctx_(ctx) {
- if (sd_dgl_ctx_set_progress_callback(ctx_, job_progress_callback, &job) != SD_STATUS_OK)
- throw std::runtime_error(sd_dgl_error());
+ ~JobProgressGuard() {
+ if (status_ == SD_STATUS_OK && sd_ctx_set_progress_callback(ctx_, nullptr, nullptr, nullptr) != SD_STATUS_OK)
+ LOG_WARN("could not clear job progress callback: %s", sd_get_last_error());
}
- ~DglJobProgressGuard() {
- if (sd_dgl_ctx_set_progress_callback(ctx_, nullptr, nullptr) != SD_STATUS_OK)
- LOG_WARN("could not clear DGL job progress callback: %s", sd_dgl_error());
- }
+ sd_status_t status() const { return status_; }
- DglJobProgressGuard(const DglJobProgressGuard&) = delete;
- DglJobProgressGuard& operator=(const DglJobProgressGuard&) = delete;
+ JobProgressGuard(const JobProgressGuard&) = delete;
+ JobProgressGuard& operator=(const JobProgressGuard&) = delete;
};
const char* async_job_kind_name(AsyncJobKind kind) {
@@ -410,8 +380,12 @@ bool execute_img_gen_job(ServerRuntime& runtime,
if (!prepare_native_job(runtime, job, error_message)) {
return false;
}
+ JobProgressGuard progress(runtime.sd_ctx, job);
+ if (progress.status() != SD_STATUS_OK) {
+ error_message = sd_get_last_error();
+ return false;
+ }
JobCancellationMonitor cancellation(runtime.sd_ctx, job);
- JobCallbacksGuard callbacks(runtime.sd_ctx, job);
if (!generate_server_images(runtime.sd_ctx, job.img_gen, results, error_message) || job.cancel_requested.load()) {
return false;
}
@@ -482,9 +456,13 @@ bool execute_vid_gen_job(ServerRuntime& runtime,
return false;
}
auto params = job.vid_gen.to_video_opt();
- JobCancellationMonitor cancellation(runtime.sd_ctx, job);
- JobCallbacksGuard callbacks(runtime.sd_ctx, job);
+ JobProgressGuard progress(runtime.sd_ctx, job);
+ if (progress.status() != SD_STATUS_OK) {
+ error_message = sd_get_last_error();
+ return false;
+ }
PromptImageCallbackGuard prompt_images(runtime.sd_ctx, job.vid_gen.gen_params);
+ JobCancellationMonitor cancellation(runtime.sd_ctx, job);
sd_result_t* generated = nullptr;
if (generate_sd_video(runtime.sd_ctx, params, &generated)) {
output_fps = sd_result_get_fps(generated);
@@ -732,9 +710,6 @@ void configure_server_file_access(ServerModels& models, const SDSvrParams& param
for (const auto& entry : config.embedding_map)
policy.configured_files.insert(model_path_key(fs::weakly_canonical(fs::absolute(fs::u8path(entry.second)))));
add_startup_model_sources(policy, config);
- // The DGL context gets a copy of the policy: take the snapshot after the
- // enrichment, or graphs cannot read from --lora-model-dir / --hires-upscalers-dir.
- models.workspace_file_access = policy;
if (params.download.autodl.value_or(false)) {
std::vector<fs::path> roots;
for (const auto& root : policy.models)
@@ -744,8 +719,6 @@ void configure_server_file_access(ServerModels& models, const SDSvrParams& param
if (sd_ctx_set_file_access_callback(models.context.get(), allowed_dgl_path, &policy) != SD_STATUS_OK)
throw std::runtime_error(sd_get_last_error());
- if (!sd_dgl_ctx_set_file_access_callback(sd_ctx_get_dgl_ctx(models.context.get()), allowed_dgl_path, &models.workspace_file_access))
- throw std::runtime_error(sd_get_last_error());
}
std::vector<sd_dgl_input_t> dgl_input_bindings(const std::vector<DglJobInput>& inputs) {
@@ -793,7 +766,11 @@ static sd_status_t execute_dgl_job(ServerRuntime& runtime,
if (job.cancel_requested.load())
return SD_STATUS_CANCELLED;
auto* ctx = sd_ctx_get_dgl_ctx(runtime.sd_ctx);
- DglJobProgressGuard progress(ctx, job);
+ JobProgressGuard progress(runtime.sd_ctx, job);
+ if (progress.status() != SD_STATUS_OK) {
+ error_message = sd_get_last_error();
+ return progress.status();
+ }
JobCancellationMonitor cancellation(job, [ctx]() {
sd_dgl_ctx_cancel(ctx);
});
diff --git a/examples/server/main.cpp b/examples/server/main.cpp
index 432d0cd..0d08c9a 100644
--- a/examples/server/main.cpp
+++ b/examples/server/main.cpp
@@ -104,8 +104,6 @@ int main(int argc, const char** argv) {
}
try {
configure_server_file_access(models, svr_params, ctx_params);
- if (!sd_dgl_ctx_set(sd_ctx_get_dgl_ctx(models.context.get()), "console_progress", "on"))
- throw std::runtime_error(sd_dgl_error());
} catch (const std::exception& error) {
LOG_ERROR("Context setup failed: %s", error.what());
return 1;
@@ -154,7 +152,7 @@ int main(int argc, const char** argv) {
index_html = "Stable Diffusion Server is running";
#endif
register_index_endpoints(svr, svr_params, index_html);
- register_media_view_endpoint(svr, svr_params.media_view, models.workspace_file_access.output);
+ register_media_view_endpoint(svr, svr_params.media_view, models.file_access.output);
register_openai_api_endpoints(svr, runtime);
register_sdapi_endpoints(svr, runtime);
register_sdcpp_api_endpoints(svr, runtime);
diff --git a/examples/server/model_catalog.h b/examples/server/model_catalog.h
index 93ba97b..f904ab1 100644
--- a/examples/server/model_catalog.h
+++ b/examples/server/model_catalog.h
@@ -40,7 +40,6 @@ struct ServerModels {
std::shared_mutex model_mutex;
std::mutex catalog_mutex;
ServerFileAccess file_access;
- ServerFileAccess workspace_file_access;
std::optional<DGLModelSources> dgl_model_sources;
SDCtxPtr context;
SDContextParams base_context;
diff --git a/examples/server/routes_sdapi.cpp b/examples/server/routes_sdapi.cpp
index a725174..7993147 100644
--- a/examples/server/routes_sdapi.cpp
+++ b/examples/server/routes_sdapi.cpp
@@ -483,19 +483,15 @@ struct SDAPIPreviewState {
static SDAPIPreviewState g_preview;
-static void preview_callback(int step, int frame_count, const sd_tensor_t* const* tensors, bool is_noisy, void* data) {
- std::vector<SDImage> views;
- for (int i = 0; i < frame_count; ++i)
- views.push_back(tensor_image_view(tensors[i]));
- SDImage* frames = views.data();
- (void)is_noisy;
- (void)data;
- if (frame_count <= 0 || frames == nullptr || frames[0].data == nullptr) {
+static void preview_progress(const sd_generation_progress_t* progress, void*) noexcept try {
+ if (strcmp(progress->stage, "sampling") != 0 || !progress->stage_data)
+ return;
+ const auto& sampling = *static_cast<const sd_sampling_progress_t*>(progress->stage_data);
+ if (sampling.denoised.frame_count == 0)
+ return;
+ const auto frame = tensor_image_view(sampling.denoised.frames[0]);
+ if (!frame.data)
return;
- }
-
- const SDImage& frame = frames[0];
- const sd_preview_info_t info = sd_get_preview_info();
auto image_bytes = encode_image_to_vector(EncodedImageFormat::JPEG,
frame.data,
@@ -511,29 +507,36 @@ static void preview_callback(int step, int frame_count, const sd_tensor_t* const
std::string b64 = base64_encode(image_bytes);
std::lock_guard<std::mutex> lock(g_preview.mutex);
g_preview.b64 = std::move(b64);
- g_preview.step = static_cast<int>(std::min<int64_t>(step < 0 ? -static_cast<int64_t>(step) : step,
- std::max(0, info.total_steps)));
- g_preview.total = std::max(0, info.total_steps);
- g_preview.job_no = std::max(0, info.sample_pass - 1);
+ g_preview.step = static_cast<int>(progress->completed);
+ g_preview.total = static_cast<int>(progress->total);
+ g_preview.job_no = sampling.sample_pass - 1;
+} catch (const std::exception& error) {
+ LOG_WARN("could not update preview: %s", error.what());
}
struct SDAPIPreviewGuard {
- SDAPIPreviewGuard(const std::string& id_task, const SDGenerationParams& params, const std::string& job_type, bool detailing = false) {
+ sd_ctx_t* ctx;
+
+ SDAPIPreviewGuard(sd_ctx_t* context, const std::string& id_task, const SDGenerationParams& params, const std::string& job_type, bool detailing = false)
+ : ctx(context) {
std::lock_guard<std::mutex> lock(g_preview.mutex);
g_preview.id_task = id_task;
g_preview.total = 0;
g_preview.job_type = job_type;
g_preview.b64.clear();
- g_preview.step = 0;
- g_preview.active = true;
+ g_preview.step = 0;
// Each batch item has a base pass and, when enabled, a hires pass.
g_preview.job_count = static_cast<int64_t>(std::max(1, params.batch_count.value_or(1))) * (params.hires_enabled.value_or(false) ? 2 : 1) + (detailing ? 1 : 0);
g_preview.job_no = 0;
- sd_set_preview_callback(preview_callback, "proj", 1, true, false, nullptr);
+ const sd_progress_options_t options{true, {"proj", 1, true, false}};
+ if (sd_ctx_set_progress_callback(ctx, preview_progress, nullptr, &options) != SD_STATUS_OK)
+ throw std::runtime_error(sd_get_last_error());
+ g_preview.active = true;
}
void begin_detailing() {
- sd_set_preview_callback(nullptr, "none", 1, false, false, nullptr);
+ if (sd_ctx_set_progress_callback(ctx, nullptr, nullptr, nullptr) != SD_STATUS_OK)
+ throw std::runtime_error(sd_get_last_error());
std::lock_guard<std::mutex> lock(g_preview.mutex);
g_preview.job_type = "adetailer";
g_preview.job_no = static_cast<int>(g_preview.job_count - 1);
@@ -542,7 +545,8 @@ struct SDAPIPreviewGuard {
}
~SDAPIPreviewGuard() {
- sd_set_preview_callback(nullptr, "none", 1, false, false, nullptr);
+ if (sd_ctx_set_progress_callback(ctx, nullptr, nullptr, nullptr) != SD_STATUS_OK)
+ LOG_WARN("could not clear preview progress callback: %s", sd_get_last_error());
std::lock_guard<std::mutex> lock(g_preview.mutex);
g_preview.active = false;
g_preview.b64.clear();
@@ -587,7 +591,7 @@ void register_sdapi_endpoints(httplib::Server& svr, ServerRuntime& rt) {
{
const bool detailing = request.adetailer_enabled && !runtime->default_gen_params->ad_model_path.empty();
- SDAPIPreviewGuard preview_guard(id_task, request.gen_params, img2img ? "img2img" : "txt2img", detailing);
+ SDAPIPreviewGuard preview_guard(runtime->sd_ctx, id_task, request.gen_params, img2img ? "img2img" : "txt2img", detailing);
generate_server_images(runtime->sd_ctx, request, results, error_message);
num_results = results.count();
if (detailing && !results.empty())
diff --git a/examples/server/routes_sdcpp.cpp b/examples/server/routes_sdcpp.cpp
index 4a64eb7..54a039b 100644
--- a/examples/server/routes_sdcpp.cpp
+++ b/examples/server/routes_sdcpp.cpp
@@ -1,7 +1,9 @@
#include "routes.h"
+#include <algorithm>
#include <cmath>
#include <filesystem>
+#include <iterator>
#include <utility>
#include "async_jobs.h"
@@ -351,7 +353,7 @@ static json make_capabilities_json(ServerRuntime& runtime) {
result["generation_model_selection"] = true;
result["media_view"] = runtime.svr_params->media_view;
if (runtime.svr_params->media_view && !runtime.svr_params->output_dir.empty()) {
- const auto& output = runtime.models->workspace_file_access.output;
+ const auto& output = runtime.models->file_access.output;
auto paths = json::array({output.generic_u8string()});
const auto relative = output.lexically_relative(fs::weakly_canonical(fs::current_path()));
if (!relative.empty())
@@ -460,6 +462,14 @@ static bool parse_vid_gen_request(const json& body,
}
bool parse_native_job_request(const json& body, ServerRuntime& runtime, AsyncGenerationJob& job, std::string& error_message) {
+ if (const auto preview = body.find("preview"); preview != body.end()) {
+ const auto* mode = preview->get_ptr<const std::string*>();
+ const auto& modes = example_options::preview_modes;
+ if (!mode || std::find(std::begin(modes), std::end(modes), *mode) == std::end(modes)) {
+ error_message = "preview must be none, proj, tae or vae";
+ return false;
+ }
+ }
if (job.kind != AsyncJobKind::VidGen)
return parse_img_gen_request(body, runtime, job.img_gen, error_message);
if (!parse_vid_gen_request(body, runtime, job.vid_gen, error_message))
diff --git a/include/stable-diffusion.h b/include/stable-diffusion.h
index 68e22ce..27a52af 100644
--- a/include/stable-diffusion.h
+++ b/include/stable-diffusion.h
@@ -203,14 +203,17 @@ SD_API sd_status_t sd_opt_unset(sd_opt_t* params, const char* key);
SD_API sd_status_t sd_ctx_create(const sd_ctx_opt_t* params, sd_ctx_t** ctx_out);
SD_API void sd_ctx_free(sd_ctx_t* ctx);
// Borrows the context used for generation, or returns NULL if ctx is NULL.
-// It shares component caches and can run scripts between generation calls.
+// It shares component caches and callback registrations for progress and file
+// access. It can run scripts between generation calls.
// Its lifetime is tied to ctx. Do not pass it to sd_dgl_ctx_free().
SD_API sd_dgl_ctx_t* sd_ctx_get_dgl_ctx(sd_ctx_t* ctx);
// Copies the new model configuration into an idle context. The execution
// settings, callbacks, and DGL component cache belong to the existing context.
// Returns SD_STATUS_BUSY during generation, DGL execution, or a model probe.
SD_API sd_status_t sd_ctx_set_model_options(sd_ctx_t* ctx, const sd_ctx_opt_t* params);
-// Applies to generated programs and model probing. Register or clear while idle.
+// Applies to generated programs, model probing and scripts run on the borrowed
+// DGL context. Register or clear while idle. Returns SD_STATUS_BUSY during
+// generation, script execution or model probing. A NULL callback clears it.
SD_API sd_status_t sd_ctx_set_file_access_callback(sd_ctx_t* ctx, sd_dgl_file_access_cb_t callback, void* userdata);
SD_API sd_status_t sd_generate_image(sd_ctx_t* ctx, const sd_img_gen_opt_t* params, sd_result_t** result_out);
@@ -280,49 +283,65 @@ enum sd_log_level_t {
typedef void (*sd_log_cb_t)(enum sd_log_level_t level, const char* text, void* data);
SD_API void sd_set_log_callback(sd_log_cb_t sd_log_cb, void* data);
-typedef void (*sd_progress_cb_t)(int step, int steps, float time, void* data);
-SD_API void sd_set_progress_callback(sd_progress_cb_t cb, void* data);
+typedef struct {
+ int frame_count;
+ const sd_tensor_t* const* frames;
+} sd_progress_frames_t;
+
+typedef struct {
+ int sample_pass;
+ float step_seconds;
+ sd_progress_frames_t denoised;
+ sd_progress_frames_t noisy;
+} sd_sampling_progress_t;
+
+typedef struct {
+ uint64_t bytes_processed;
+ float elapsed_seconds;
+} sd_loading_progress_t;
typedef struct {
const char* stage;
const char* detail;
const char* unit;
- int sample_pass;
int64_t completed;
int64_t total;
+ // "sampling" carries sd_sampling_progress_t. Counted "loading" carries
+ // sd_loading_progress_t.
+ // NULL when there is no payload. Only interpret data for a recognized stage.
+ const void* stage_data;
} sd_generation_progress_t;
typedef void (*sd_generation_progress_cb_t)(const sd_generation_progress_t* progress, void* data);
-// Context-local generation events, independent of preview and the legacy progress callback.
-// Strings and the event are valid only during the synchronous callback. Callbacks must not throw.
-// total == 0 means unknown; sample_pass counts from 1 since callback registration.
-// Register/clear only while the context is idle. Passing NULL clears the callback.
-SD_API void sd_set_generation_progress_callback(sd_ctx_t* ctx, sd_generation_progress_cb_t cb, void* data);
+typedef struct {
+ // NULL or "none" disables previews. Other modes are "proj", "tae" and "vae".
+ const char* mode;
+ // A positive interval N selects every Nth logical step. A negative interval
+ // selects logical step -interval. Zero selects the first pass's final step.
+ int interval;
+ bool denoised;
+ bool noisy;
+} sd_preview_options_t;
typedef struct {
- int sample_pass;
- int total_steps;
-} sd_preview_info_t;
-
-// Frames are borrowed during the callback; retain a tensor to keep its snapshot.
-typedef void (*sd_preview_cb_t)(int step, int frame_count, const sd_tensor_t* const* frames, bool is_noisy, void* data);
-
-// In each sampling pass, a positive interval previews every Nth denoiser step, while a
-// negative interval previews only completed logical step -interval. Zero previews the final
-// completed step of the first sampling pass (base-resolution or high-noise).
-// Mode is "none", "proj", "tae" or "vae"; invalid input preserves registration.
-SD_API sd_status_t sd_set_preview_callback(
- sd_preview_cb_t cb,
- const char* mode,
- int interval,
- bool denoised,
- bool noisy,
- void* data);
-
-// Query from a preview callback. Passes are numbered from 1 since the last
-// sd_set_preview_callback call; total_steps is the actual count in that pass.
-// Both fields are zero before sampling starts.
-SD_API sd_preview_info_t sd_get_preview_info();
+ bool console_progress;
+ sd_preview_options_t preview;
+} sd_progress_options_t;
+
+// Register or clear while idle. A NULL callback clears registration and ignores
+// options. When registering, a NULL options pointer uses defaults. Options are
+// copied. Invalid options preserve the previous registration. Built-in progress
+// is shown when no callback is registered or console_progress is true.
+// Callbacks run synchronously on the executing thread and must not throw.
+// The event, strings, payloads and frames are borrowed until the callback
+// returns. Use sd_tensor_retain() to keep a frame. total == 0 means unknown.
+// Each sampling pass starts at completed == 0 and reports each completed logical
+// step once. sample_pass counts from 1 per request, including across batch images.
+SD_API sd_status_t sd_ctx_set_progress_callback(
+ sd_ctx_t* ctx,
+ sd_generation_progress_cb_t callback,
+ void* userdata,
+ const sd_progress_options_t* options);
// Resolves <image:source> markers. The returned U8 [C,W,H] tensor is borrowed
// and copied before the next callback. Register/clear while ctx is idle.
@@ -356,8 +375,7 @@ SD_API sd_dgl_ctx_t* sd_dgl_ctx_create_once(void);
SD_API void sd_dgl_ctx_free(sd_dgl_ctx_t* ctx);
// Sets options on an idle context: max_vram, max_ram, conditioning_cache_size, batched_cfg,
// n_threads, auto_fit, enable_mmap, eager_load, disable_prefetch, disable_segmented_compute,
-// embed_metadata (default on; controls generation metadata in DGL image/video saves),
-// console_progress (default off; keeps built-in progress output alongside callbacks).
+// embed_metadata (default on; controls generation metadata in DGL image/video saves).
// Threading, placement and weight-loading options invalidate cached models when changed.
SD_API bool sd_dgl_ctx_set(sd_dgl_ctx_t* ctx, const char* key, const char* value);
@@ -366,31 +384,17 @@ SD_API bool sd_dgl_ctx_set(sd_dgl_ctx_t* ctx, const char* key, const char* value
// Subsequent requests reload components as needed. Returns SD_STATUS_BUSY during execution.
SD_API sd_status_t sd_dgl_ctx_unload_models(sd_dgl_ctx_t* ctx);
-// Optional per-context callback. A null callback restores unrestricted file access.
-SD_API bool sd_dgl_ctx_set_file_access_callback(sd_dgl_ctx_t* ctx, sd_dgl_file_access_cb_t callback, void* userdata);
-
-// Callbacks run synchronously on the executing thread. Set or clear while idle.
-// Pass counts start at 1 in each run. Data supplied by the library is borrowed
-// until the callback returns. Callbacks may request cancellation and must not throw.
-typedef void (*sd_dgl_preview_cb_t)(
- const sd_preview_info_t* info,
- int step,
- int frame_count,
- const sd_tensor_t* const* frames,
- bool is_noisy,
- void* userdata);
-SD_API sd_status_t sd_dgl_ctx_set_progress_callback(sd_dgl_ctx_t* ctx, sd_generation_progress_cb_t callback, void* userdata);
-// Modes: none, proj, tae, vae. Pass NULL as callback to clear.
-// Sampling uses projection previews by default. Positive intervals count
-// completed logical steps; supply preview(decoder=...) for tae or vae decoding.
-SD_API sd_status_t sd_dgl_ctx_set_preview_callback(
+// Same registration contract as sd_ctx_set_file_access_callback. A NULL
+// callback restores file access according to the process's permissions.
+SD_API sd_status_t sd_dgl_ctx_set_file_access_callback(sd_dgl_ctx_t* ctx, sd_dgl_file_access_cb_t callback, void* userdata);
+
+// Same callback contract as sd_ctx_set_progress_callback. In DGL scripts,
+// supply preview(decoder=...) for decoder-based previews.
+SD_API sd_status_t sd_dgl_ctx_set_progress_callback(
sd_dgl_ctx_t* ctx,
- sd_dgl_preview_cb_t callback,
- const char* mode,
- int interval,
- bool denoised,
- bool noisy,
- void* userdata);
+ sd_generation_progress_cb_t callback,
+ void* userdata,
+ const sd_progress_options_t* options);
typedef enum {
SD_DGL_INPUT_TENSOR,
diff --git a/src/api/api.cpp b/src/api/api.cpp
index 43830ab..6070de4 100644
--- a/src/api/api.cpp
+++ b/src/api/api.cpp
@@ -62,17 +62,6 @@ enum sd_type_t str_to_sd_type(const char* str) {
return SD_TYPE_COUNT;
}
-sd_status_t sd_set_preview_callback(sd_preview_cb_t cb, const char* mode, int interval, bool denoised, bool noisy, void* data) {
- sd::api::clear_error();
- if (!mode)
- return sd::api::error(SD_STATUS_INVALID_ARGUMENT, "preview.mode", "mode is required");
- const auto parsed = str_to_preview(mode);
- if (parsed == PREVIEW_COUNT)
- return sd::api::error(SD_STATUS_INVALID_ARGUMENT, "preview.mode", "unknown preview mode");
- sd_set_preview_callback_impl(cb, parsed, interval, denoised, noisy, data);
- return SD_STATUS_OK;
-}
-
void sd_set_prompt_image_callback(sd_ctx_t* ctx, sd_prompt_image_cb_t callback, void* data) {
if (!ctx || !ctx->engine)
return;
@@ -84,16 +73,16 @@ void sd_set_prompt_image_callback(sd_ctx_t* ctx, sd_prompt_image_cb_t callback,
}
}
-void sd_set_generation_progress_callback(sd_ctx_t* ctx, sd_generation_progress_cb_t callback, void* data) {
- if (!ctx || !ctx->engine)
- return;
- auto& engine = *ctx->engine;
- std::lock_guard<std::recursive_mutex> lock(engine.mutex);
- if (!engine.executing) {
- engine.progress = callback;
- engine.progress_data = data;
- engine.sample_pass = 0;
- }
+sd_status_t sd_ctx_set_progress_callback(sd_ctx_t* ctx, sd_generation_progress_cb_t callback, void* userdata, const sd_progress_options_t* options) {
+ return sd::api::call([&] {
+ if (!ctx || !ctx->engine)
+ return sd::api::error(SD_STATUS_INVALID_ARGUMENT, nullptr, "context is required");
+ auto& engine = *ctx->engine;
+ std::unique_lock<std::recursive_mutex> lock(engine.mutex, std::try_to_lock);
+ if (!lock.owns_lock() || engine.executing)
+ return sd::api::error(SD_STATUS_BUSY, nullptr, "context is busy");
+ return sd_dgl_ctx_set_progress_callback(&engine.execution, callback, userdata, options);
+ });
}
sd_status_t sd_ctx_create(const sd_ctx_opt_t* options, sd_ctx_t** out) {
@@ -129,7 +118,6 @@ static sd_status_t set_model_options(sd_ctx_t* context, const sd_ctx_opt_t* opti
sd::api::GenerationRun replacement(engine);
sd::api::GenerationModel candidate(sd::api::copy_options(options), sd::api::Context);
if (kind != SD_RESULT_INVALID) {
- sd::FileAccessScope access(engine.file_access);
const bool video = kind == SD_RESULT_VIDEO;
if (!sd::api::supports_generation(candidate.definition(engine), video))
return sd::api::error(SD_STATUS_UNSUPPORTED, nullptr, video ? "selected model does not support vid_gen" : "selected model does not support img_gen");
@@ -176,7 +164,6 @@ static const ModelDefinition* context_definition(const sd_ctx_t* context) {
if (family != VERSION_COUNT) {
definition = find_model_definition(family);
} else {
- sd::FileAccessScope access(engine.file_access);
definition = &engine.model.definition(engine);
}
sd::api::clear_error();
@@ -213,7 +200,6 @@ int sd_ctx_get_video_frame_count(sd_ctx_t* context, const sd_ctx_opt_t* model_op
return sd::api::error(SD_STATUS_INVALID_ARGUMENT, nullptr, "context is required");
auto& engine = *context->engine;
sd::api::GenerationModel candidate(sd::api::copy_options(model_options), sd::api::Context);
- sd::FileAccessScope access(engine.file_access);
definition = &candidate.definition(engine);
sd::api::clear_error();
return SD_STATUS_OK;
@@ -234,8 +220,7 @@ sd_status_t sd_ctx_set_file_access_callback(sd_ctx_t* context, sd_dgl_file_acces
std::unique_lock<std::recursive_mutex> lock(engine.mutex, std::try_to_lock);
if (!lock.owns_lock() || engine.executing)
return sd::api::error(SD_STATUS_BUSY, nullptr, "context is busy");
- engine.file_access = {callback, data};
- return SD_STATUS_OK;
+ return sd_dgl_ctx_set_file_access_callback(&engine.execution, callback, data);
});
}
diff --git a/src/api/generation.cpp b/src/api/generation.cpp
index 00a645e..4a16651 100644
--- a/src/api/generation.cpp
+++ b/src/api/generation.cpp
@@ -54,13 +54,23 @@ namespace sd::api {
const ModelDefinition& GenerationModel::definition(GenerationContext& context) {
std::lock_guard<std::recursive_mutex> lock(context.mutex);
- if (context.probing_model)
- throw dgl::Error(SD_STATUS_BUSY, "model probe is in progress");
- context.probing_model = true;
struct ProbeGuard {
- bool& probing;
- ~ProbeGuard() { probing = false; }
- } probe{context.probing_model};
+ dgl::Context& execution;
+
+ explicit ProbeGuard(dgl::Context& context)
+ : execution(context) {
+ std::unique_lock<std::mutex> lock(execution.mutex, std::try_to_lock);
+ if (!lock.owns_lock() || execution.probing_model)
+ throw dgl::Error(SD_STATUS_BUSY, "DGL context is busy");
+ execution.probing_model = true;
+ }
+
+ ~ProbeGuard() {
+ std::lock_guard<std::mutex> lock(execution.mutex);
+ execution.probing_model = false;
+ }
+ } probe(context.execution);
+ FileAccessScope access(context.execution.file_access);
context.check_cancelled();
const auto& settings = config.context;
const auto* path = settings.diffusion_model_path && *settings.diffusion_model_path ? settings.diffusion_model_path : settings.model_path;
@@ -148,18 +158,21 @@ namespace sd::api {
throw dgl::Error(SD_STATUS_CANCELLED, "generation cancelled");
}
- GenerationRun::GenerationRun(GenerationContext& context)
- : context_(context) {
- std::unique_lock<std::recursive_mutex> lock(context_.mutex, std::try_to_lock);
- if (!lock.owns_lock() || context_.executing || context_.probing_model)
+ dgl::RunCallbacks GenerationRun::begin(GenerationContext& context) {
+ std::unique_lock<std::recursive_mutex> lock(context.mutex, std::try_to_lock);
+ if (!lock.owns_lock() || context.executing)
throw dgl::Error(SD_STATUS_BUSY, "context is busy");
- std::unique_lock<std::mutex> execution_lock(context_.execution.mutex, std::try_to_lock);
- if (!execution_lock.owns_lock() || context_.execution.active_run)
+ std::unique_lock<std::mutex> execution_lock(context.execution.mutex, std::try_to_lock);
+ if (!execution_lock.owns_lock() || context.execution.active_run || context.execution.probing_model)
throw dgl::Error(SD_STATUS_BUSY, "DGL context is busy");
- context_.execution.generating = true;
- context_.executing = true;
+ context.execution.generating = true;
+ context.executing = true;
+ return context.execution.callbacks;
}
+ GenerationRun::GenerationRun(GenerationContext& context)
+ : context_(context), events_(begin(context)) {}
+
GenerationRun::~GenerationRun() {
std::lock_guard<std::recursive_mutex> lock(context_.mutex);
std::lock_guard<std::mutex> execution_lock(context_.execution.mutex);
@@ -168,48 +181,35 @@ namespace sd::api {
context_.executing = false;
}
- static void generation_progress(const sd_generation_progress_t* info, void* data) {
- auto& context = *static_cast<GenerationContext*>(data);
- auto translated = *info;
- translated.sample_pass += context.sample_pass;
- if (context.progress)
- context.progress(&translated, context.progress_data);
- }
-
- dgl::Value execute_program(GenerationContext& context, const GenerationProgram& program, const dgl::Graph* compiled) {
+ dgl::Value GenerationRun::execute_program(const GenerationProgram& program, const dgl::Graph* compiled) {
+ auto& context = context_;
context.check_cancelled();
- FileAccessScope access(context.file_access);
+ FileAccessScope access(context.execution.file_access);
dgl::Graph graph;
if (!compiled) {
graph = dgl::compile(program.source, dgl::operations(), !program.inputs.empty());
compiled = &graph;
}
context.check_cancelled();
- dgl::RunCallbacks callbacks;
- callbacks.progress = generation_progress;
- callbacks.progress_data = &context;
- dgl::RunEvents events(callbacks, true);
struct ActiveRun {
GenerationContext& context;
- dgl::RunEvents& events;
~ActiveRun() {
std::lock_guard<std::recursive_mutex> lock(context.mutex);
std::lock_guard<std::mutex> execution_lock(context.execution.mutex);
- context.sample_pass += events.preview_info().sample_pass;
context.active_run = nullptr;
context.execution.active_run = nullptr;
}
- } active{context, events};
+ } active{context};
{
std::lock_guard<std::recursive_mutex> lock(context.mutex);
std::lock_guard<std::mutex> execution_lock(context.execution.mutex);
- context.active_run = &events;
- context.execution.active_run = &events;
- if (context.cancellation.load() == SD_CANCEL_ALL)
- events.cancel();
+ context.active_run = &events_;
+ context.execution.active_run = &events_;
+ events_.set_cancelled(context.cancellation.load() == SD_CANCEL_ALL);
}
- dgl::RunEventsScope scope(events);
- dgl::RunState state{context.execution, events};
+ dgl::RunEventsScope scope(events_);
+ dgl::RunState state{context.execution, events_};
+ events_.begin_execution();
LOG_DEBUG("Executing DGL program:\n%s", compiled->source.c_str());
return dgl::run(*compiled, state, program.inputs);
}
@@ -223,7 +223,7 @@ namespace sd::api {
sd_status_t generate_images(GenerationContext& context, const sd_img_gen_opt_t* options, sd_result_t** out) {
GenerationRun request(context);
- FileAccessScope access(context.file_access);
+ FileAccessScope access(context.execution.file_access);
auto snapshot = copy_options(options);
OptConfig config;
const auto status = resolve(snapshot.get(), Image, config);
@@ -236,7 +236,7 @@ namespace sd::api {
if (context.cancellation.load() == SD_CANCEL_NEW_LATENTS)
break;
auto program = image_program(context, config.image, snapshot.get(), int64_t((uint64_t(seed) + uint64_t(i)) & INT64_MAX));
- auto value = execute_program(context, program);
+ auto value = request.execute_program(program);
append_program_image(*result, value, program.source);
}
if (result->images.empty())
@@ -247,14 +247,14 @@ namespace sd::api {
}
sd_status_t generate_video(GenerationContext& context, const sd_vid_gen_opt_t* options, sd_result_t** out) {
GenerationRun request(context);
- FileAccessScope access(context.file_access);
+ FileAccessScope access(context.execution.file_access);
auto snapshot = copy_options(options);
OptConfig config;
const auto status = resolve(snapshot.get(), Video, config);
if (status != SD_STATUS_OK)
return status;
auto program = video_program(context, config.video, snapshot.get(), resolved_seed(config.video.seed));
- auto value = execute_program(context, program);
+ auto value = request.execute_program(program);
auto result = std::make_unique<sd_result_t>();
set_program_video(*result, value, program.source);
context.check_cancelled();
diff --git a/src/api/generation.h b/src/api/generation.h
index 09f3c44..159ac4c 100644
--- a/src/api/generation.h
+++ b/src/api/generation.h
@@ -34,17 +34,12 @@ namespace sd::api {
struct GenerationContext {
GenerationModel model;
sd_dgl_ctx_t execution;
- FileAccessPolicy file_access;
std::recursive_mutex mutex;
- bool executing = false;
- bool probing_model = false;
+ bool executing = false;
std::atomic<sd_cancel_mode_t> cancellation{SD_CANCEL_RESET};
- dgl::RunEvents* active_run = nullptr;
- sd_generation_progress_cb_t progress = nullptr;
- void* progress_data = nullptr;
- sd_prompt_image_cb_t prompt_image = nullptr;
- void* prompt_image_data = nullptr;
- int sample_pass = 0;
+ dgl::RunEvents* active_run = nullptr;
+ sd_prompt_image_cb_t prompt_image = nullptr;
+ void* prompt_image_data = nullptr;
GenerationContext(const sd_opt_t* source, Operation purpose);
void check_cancelled() const;
@@ -52,22 +47,26 @@ namespace sd::api {
bool supports_generation(const ModelDefinition& definition, bool video);
+ struct GenerationProgram {
+ std::string source;
+ dgl::Values inputs;
+ };
+
class GenerationRun {
GenerationContext& context_;
+ dgl::RunEvents events_;
+
+ static dgl::RunCallbacks begin(GenerationContext& context);
public:
explicit GenerationRun(GenerationContext& context);
~GenerationRun();
GenerationRun(const GenerationRun&) = delete;
GenerationRun& operator=(const GenerationRun&) = delete;
- };
- struct GenerationProgram {
- std::string source;
- dgl::Values inputs;
+ dgl::Value execute_program(const GenerationProgram& program, const dgl::Graph* compiled = nullptr);
};
- dgl::Value execute_program(GenerationContext& context, const GenerationProgram& program, const dgl::Graph* compiled = nullptr);
GenerationProgram image_program(GenerationContext& context, const ImageConfig& image, const sd_opt_t* explicit_options, int64_t seed);
GenerationProgram video_program(GenerationContext& context, const VideoConfig& video, const sd_opt_t* explicit_options, int64_t seed);
sd_status_t generate_images(GenerationContext& context, const sd_img_gen_opt_t* options, sd_result_t** result);
diff --git a/src/api/tensor.cpp b/src/api/tensor.cpp
index f783346..8029524 100644
--- a/src/api/tensor.cpp
+++ b/src/api/tensor.cpp
@@ -134,23 +134,6 @@ std::vector<sd::Image> sd::api::video_frames(const sd_tensor_t& tensor) {
return result;
}
-void sd::api::preview_images(const std::function<void(int, int, const sd_tensor_t* const*, bool, void*)>& callback, int step, int count, const sd::Image* images, bool noisy, void* data) {
- std::vector<TensorRef> tensors;
- std::vector<const sd_tensor_t*> views;
- tensors.reserve(count);
- views.reserve(count);
- for (int i = 0; i < count; ++i) {
- const auto& image = images[i];
- const int64_t shape[] = {image.channel, image.width, image.height};
- auto* tensor = sd_tensor_create(SD_TENSOR_U8, 3, shape, image.data, size_t(image.channel) * image.width * image.height);
- if (!tensor)
- throw std::bad_alloc();
- tensors.push_back(TensorRef::adopt(tensor));
- views.push_back(tensors.back().get());
- }
- callback(step, count, views.data(), noisy, data);
-}
-
sd_tensor_t* sd_tensor_create(sd_tensor_type_t type, size_t rank, const int64_t* shape, const void* data, size_t data_size) {
sd_tensor_t* result = nullptr;
sd::api::call([&] {
diff --git a/src/api/tensor.h b/src/api/tensor.h
index a9affa6..039a44f 100644
--- a/src/api/tensor.h
+++ b/src/api/tensor.h
@@ -3,7 +3,6 @@
#include <atomic>
#include <cstring>
-#include <functional>
#include <memory>
#include <stdexcept>
#include <type_traits>
@@ -109,7 +108,6 @@ namespace sd::api {
sd::Image image_view(const sd_tensor_t& tensor);
sd::Audio audio_view(const sd_audio_t& audio);
std::vector<sd::Image> video_frames(const sd_tensor_t& tensor);
- void preview_images(const std::function<void(int, int, const sd_tensor_t* const*, bool, void*)>& callback, int step, int count, const sd::Image* images, bool noisy, void* data);
}
#endif // __SD_API_TENSOR_H__
diff --git a/src/api/upscaler.cpp b/src/api/upscaler.cpp
index a7e70db..65aaaed 100644
--- a/src/api/upscaler.cpp
+++ b/src/api/upscaler.cpp
@@ -49,7 +49,7 @@ sd_status_t sd_upscaler_create(const sd_upscaler_opt_t* options, sd_upscaler_t**
result->program = sd::dgl::compile(result->source, sd::dgl::operations(), true);
const auto& resource = result->program.resources.at(0);
auto arguments = resource.arguments;
- sd::dgl::RunEvents events({}, false);
+ sd::dgl::RunEvents events(sd::dgl::RunCallbacks{});
sd::dgl::RunEventsScope scope(events);
sd::dgl::RunState state{result->context.execution, events};
sd::dgl::RunPlan plan(result->program, state);
@@ -111,7 +111,7 @@ sd_status_t sd_upscale(sd_upscaler_t* upscaler, const sd_upscale_opt_t* options,
sd::api::GenerationProgram program;
program.source = config.post.repeats == 1 ? upscaler->source : sd::api::upscale_source(upscaler->context.model.config, config.post.repeats);
program.inputs.emplace("input_image", sd::dgl::Value::object(std::shared_ptr<sd_tensor_t>(sd_tensor_retain(input), sd_tensor_free)));
- auto value = sd::api::execute_program(upscaler->context, program, config.post.repeats == 1 ? &upscaler->program : nullptr);
+ auto value = request.execute_program(program, config.post.repeats == 1 ? &upscaler->program : nullptr);
auto result = std::make_unique<sd_result_t>();
sd::api::append_program_image(*result, value, program.source);
*out = result.release();
diff --git a/src/core/progress.h b/src/core/progress.h
index 61d2e30..390f1c2 100644
--- a/src/core/progress.h
+++ b/src/core/progress.h
@@ -3,31 +3,28 @@
#include <cstdint>
-void pretty_progress(int step, int steps, float time);
+void report_tile_progress(int completed, int total, float seconds);
void pretty_console_progress(int step, int steps, float time);
void pretty_bytes_progress(int step, int steps, uint64_t bytes_processed, float elapsed_seconds);
+void pretty_console_bytes_progress(int step, int steps, uint64_t bytes_processed, float elapsed_seconds);
namespace sd {
- class ByteProgressScope {
- using Callback = void (*)(int completed, int total, void* data);
- Callback previous_callback_;
- void* previous_data_;
-
+ class ProgressScope {
public:
- ByteProgressScope(Callback callback, void* data);
- ~ByteProgressScope();
- ByteProgressScope(const ByteProgressScope&) = delete;
- ByteProgressScope& operator=(const ByteProgressScope&) = delete;
- };
+ struct Callbacks {
+ void (*tiles)(int completed, int total, float seconds, void* data);
+ void (*loading)(int completed, int total, uint64_t bytes, float seconds, void* data);
+ void* data;
+ };
- class ByteProgressConsoleScope {
- bool previous_;
+ private:
+ Callbacks previous_;
public:
- explicit ByteProgressConsoleScope(bool enabled = true);
- ~ByteProgressConsoleScope();
- ByteProgressConsoleScope(const ByteProgressConsoleScope&) = delete;
- ByteProgressConsoleScope& operator=(const ByteProgressConsoleScope&) = delete;
+ explicit ProgressScope(Callbacks callbacks);
+ ~ProgressScope();
+ ProgressScope(const ProgressScope&) = delete;
+ ProgressScope& operator=(const ProgressScope&) = delete;
};
}
diff --git a/src/core/util.cpp b/src/core/util.cpp
index e56dac1..a06e607 100644
--- a/src/core/util.cpp
+++ b/src/core/util.cpp
@@ -374,17 +374,6 @@ int32_t sd_get_num_physical_cores() {
return n_threads > 0 ? (n_threads <= 4 ? n_threads : n_threads / 2) : 4;
}
-static sd_progress_cb_t sd_progress_cb = nullptr;
-void* sd_progress_cb_data = nullptr;
-
-static sd_preview_info_t sd_preview_info = {};
-static sd_preview_cb_t sd_preview_cb = nullptr;
-static void* sd_preview_cb_data = nullptr;
-preview_t sd_preview_mode = PREVIEW_NONE;
-int sd_preview_interval = 1;
-bool sd_preview_denoised = true;
-bool sd_preview_noisy = false;
-
static sd_graph_eval_callback_t sd_backend_eval_cb = nullptr;
static void* sd_backend_eval_cb_data = nullptr;
@@ -592,12 +581,13 @@ static void print_progress_line(int step, int steps, const std::string& speed_te
fflush(stdout); // for linux
}
-void pretty_progress(int step, int steps, float time) {
- if (sd_progress_cb) {
- sd_progress_cb(step, steps, time, sd_progress_cb_data);
- return;
- }
- pretty_console_progress(step, steps, time);
+static thread_local sd::ProgressScope::Callbacks progress_callbacks{};
+
+void report_tile_progress(int completed, int total, float seconds) {
+ if (progress_callbacks.tiles)
+ progress_callbacks.tiles(completed, total, seconds, progress_callbacks.data);
+ else
+ pretty_console_progress(completed, total, seconds);
}
void pretty_console_progress(int step, int steps, float time) {
@@ -627,41 +617,23 @@ void pretty_console_progress(int step, int steps, float time) {
print_progress_line(step, steps, sd_format("%.2f%s", speed, unit), '=', true, remainder_text);
}
-static thread_local void (*byte_progress_callback)(int, int, void*) = nullptr;
-static thread_local void* byte_progress_data = nullptr;
-static thread_local bool byte_progress_console = false;
-
-sd::ByteProgressConsoleScope::ByteProgressConsoleScope(bool enabled)
- : previous_(byte_progress_console) {
- byte_progress_console = enabled;
-}
-
-sd::ByteProgressConsoleScope::~ByteProgressConsoleScope() {
- byte_progress_console = previous_;
+sd::ProgressScope::ProgressScope(Callbacks callbacks)
+ : previous_(progress_callbacks) {
+ progress_callbacks = callbacks;
}
-sd::ByteProgressScope::ByteProgressScope(Callback callback, void* data)
- : previous_callback_(byte_progress_callback), previous_data_(byte_progress_data) {
- byte_progress_callback = callback;
- byte_progress_data = data;
+sd::ProgressScope::~ProgressScope() {
+ progress_callbacks = previous_;
}
-sd::ByteProgressScope::~ByteProgressScope() {
- byte_progress_callback = previous_callback_;
- byte_progress_data = previous_data_;
+void pretty_bytes_progress(int step, int steps, uint64_t bytes_processed, float elapsed_seconds) {
+ if (progress_callbacks.loading)
+ progress_callbacks.loading(step, steps, bytes_processed, elapsed_seconds, progress_callbacks.data);
+ else
+ pretty_console_bytes_progress(step, steps, bytes_processed, elapsed_seconds);
}
-void pretty_bytes_progress(int step, int steps, uint64_t bytes_processed, float elapsed_seconds) {
- if (byte_progress_callback) {
- byte_progress_callback(step, steps, byte_progress_data);
- if (!byte_progress_console)
- return;
- }
- if (!byte_progress_console && sd_progress_cb) {
- float time = elapsed_seconds / (step + 1e-6f);
- sd_progress_cb(step, steps, time, sd_progress_cb_data);
- return;
- }
+void pretty_console_bytes_progress(int step, int steps, uint64_t bytes_processed, float elapsed_seconds) {
if (step == 0) {
return;
}
@@ -750,56 +722,11 @@ void sd_set_log_callback(sd_log_cb_t cb, void* data) {
sd_log_cb = cb;
sd_log_cb_data = data;
}
-void sd_set_progress_callback(sd_progress_cb_t cb, void* data) {
- sd_progress_cb = cb;
- sd_progress_cb_data = data;
-}
-void sd_set_preview_callback_impl(sd_preview_cb_t cb, preview_t mode, int interval, bool denoised, bool noisy, void* data) {
- sd_preview_info = {};
- sd_preview_cb = cb;
- sd_preview_cb_data = data;
- sd_preview_mode = mode;
- sd_preview_interval = interval;
- sd_preview_denoised = denoised;
- sd_preview_noisy = noisy;
-}
-
void sd_set_backend_eval_callback(sd_graph_eval_callback_t cb, void* data) {
sd_backend_eval_cb = cb;
sd_backend_eval_cb_data = data;
}
-void sd_begin_preview_pass(int total_steps) {
- if (sd_preview_cb != nullptr) {
- ++sd_preview_info.sample_pass;
- sd_preview_info.total_steps = total_steps;
- }
-}
-
-sd_preview_info_t sd_get_preview_info() {
- return sd_preview_info;
-}
-
-sd_preview_cb_t sd_get_preview_callback() {
- return sd_preview_cb;
-}
-void* sd_get_preview_callback_data() {
- return sd_preview_cb_data;
-}
-
-preview_t sd_get_preview_mode() {
- return sd_preview_mode;
-}
-int sd_get_preview_interval() {
- return sd_preview_interval;
-}
-bool sd_should_preview_denoised() {
- return sd_preview_denoised;
-}
-bool sd_should_preview_noisy() {
- return sd_preview_noisy;
-}
-
sd_graph_eval_callback_t sd_get_backend_eval_callback() {
return sd_backend_eval_cb;
}
@@ -808,13 +735,6 @@ void* sd_get_backend_eval_callback_data() {
return sd_backend_eval_cb_data;
}
-sd_progress_cb_t sd_get_progress_callback() {
- return sd_progress_cb;
-}
-void* sd_get_progress_callback_data() {
- return sd_progress_cb_data;
-}
-
sd::Image tensor_to_sd_image(const sd::Tensor<float>& tensor, int frame_index) {
const auto& shape = tensor.shape();
GGML_ASSERT(shape.size() == 4 || shape.size() == 5);
diff --git a/src/core/util.h b/src/core/util.h
index 1274e64..44a7d07 100644
--- a/src/core/util.h
+++ b/src/core/util.h
@@ -100,18 +100,6 @@ std::vector<std::pair<std::string, float>> parse_prompt_attention(const std::str
std::vector<std::pair<std::string, float>> split_quotation_attention(
const std::vector<std::pair<std::string, float>>& parsed_attention);
-sd_progress_cb_t sd_get_progress_callback();
-void* sd_get_progress_callback_data();
-
-void sd_begin_preview_pass(int total_steps);
-sd_preview_cb_t sd_get_preview_callback();
-void* sd_get_preview_callback_data();
-void sd_set_preview_callback_impl(sd_preview_cb_t cb, preview_t mode, int interval, bool denoised, bool noisy, void* data);
-preview_t sd_get_preview_mode();
-int sd_get_preview_interval();
-bool sd_should_preview_denoised();
-bool sd_should_preview_noisy();
-
sd_graph_eval_callback_t sd_get_backend_eval_callback();
void* sd_get_backend_eval_callback_data();
diff --git a/src/dgl/context.cpp b/src/dgl/context.cpp
index ac22bd9..ed19a37 100644
--- a/src/dgl/context.cpp
+++ b/src/dgl/context.cpp
@@ -137,9 +137,6 @@ namespace sd::dgl {
if (!parse_strict_bool(value, enabled))
throw std::runtime_error("batched_cfg expects a boolean");
batched_cfg = enabled;
- } else if (key == "console_progress") {
- if (!parse_strict_bool(value, callbacks.console_progress))
- throw std::runtime_error("console_progress expects a boolean");
} else if (key == "max_vram") {
ggml_graph_cut::MaxVramAssignment limit;
std::string error;
diff --git a/src/dgl/context.h b/src/dgl/context.h
index 90318f7..09a4362 100644
--- a/src/dgl/context.h
+++ b/src/dgl/context.h
@@ -34,6 +34,7 @@ namespace sd::dgl {
std::mutex mutex;
RunEvents* active_run = nullptr;
bool generating = false;
+ bool probing_model = false;
RunCallbacks callbacks;
FileAccessPolicy file_access;
std::shared_ptr<SDBackendPool> backends = std::make_shared<SDBackendPool>();
diff --git a/src/dgl/dgl.cpp b/src/dgl/dgl.cpp
index 7ac9ccc..8eab443 100644
--- a/src/dgl/dgl.cpp
+++ b/src/dgl/dgl.cpp
@@ -32,7 +32,7 @@ namespace {
if (!ctx)
throw Error(SD_STATUS_INVALID_ARGUMENT, "context is required");
std::unique_lock<std::mutex> lock(ctx->mutex, std::try_to_lock);
- if (!lock.owns_lock() || ctx->active_run || ctx->generating)
+ if (!lock.owns_lock() || ctx->active_run || ctx->generating || ctx->probing_model)
throw Error(SD_STATUS_BUSY, "DGL context is busy");
return lock;
}
@@ -51,7 +51,7 @@ namespace {
RunEvents events;
explicit ActiveRun(Context& context)
- : context_(context), events(context.callbacks, false) {
+ : context_(context), events(context.callbacks) {
context_.active_run = &events;
}
@@ -129,7 +129,7 @@ namespace {
RunState state{ctx, events};
ctx.models->clear_host_memory_error();
try {
- events.report("executing");
+ events.begin_execution();
return std::make_unique<sd_dgl_result_t>(run(graph, state, std::move(inputs)));
} catch (const std::exception& error) {
events.check_cancelled();
@@ -189,33 +189,32 @@ sd_status_t sd_dgl_ctx_unload_models(sd_dgl_ctx_t* ctx) {
});
}
-bool sd_dgl_ctx_set_file_access_callback(sd_dgl_ctx_t* ctx, sd_dgl_file_access_cb_t callback, void* userdata) {
+sd_status_t sd_dgl_ctx_set_file_access_callback(sd_dgl_ctx_t* ctx, sd_dgl_file_access_cb_t callback, void* userdata) {
return api_call([&] {
- auto lock = lock_idle(ctx);
- ctx->file_access = {callback, userdata};
- }) == SD_STATUS_OK;
-}
-
-sd_status_t sd_dgl_ctx_set_progress_callback(sd_dgl_ctx_t* ctx, sd_generation_progress_cb_t callback, void* userdata) {
- return api_call([&] {
- auto lock = lock_idle(ctx);
- ctx->callbacks.progress = callback;
- ctx->callbacks.progress_data = userdata;
+ auto lock = lock_idle(ctx);
+ ctx->file_access = {callback, userdata};
});
}
-sd_status_t sd_dgl_ctx_set_preview_callback(sd_dgl_ctx_t* ctx, sd_dgl_preview_cb_t callback, const char* mode, int interval, bool denoised, bool noisy, void* userdata) {
+sd_status_t sd_dgl_ctx_set_progress_callback(sd_dgl_ctx_t* ctx, sd_generation_progress_cb_t callback, void* userdata, const sd_progress_options_t* options) {
return api_call([&] {
- auto lock = lock_idle(ctx);
- const auto preview = callback && mode ? str_to_preview(mode) : PREVIEW_NONE;
- if (callback && (!mode || preview == PREVIEW_COUNT))
- throw Error(SD_STATUS_INVALID_ARGUMENT, "preview mode must be none, proj, tae or vae");
- ctx->callbacks.preview = callback;
- ctx->callbacks.preview_data = userdata;
- ctx->callbacks.mode = preview;
- ctx->callbacks.interval = interval;
- ctx->callbacks.denoised = denoised;
- ctx->callbacks.noisy = noisy;
+ auto lock = lock_idle(ctx);
+ RunCallbacks callbacks;
+ if (callback) {
+ callbacks.progress = callback;
+ callbacks.progress_data = userdata;
+ if (options) {
+ const auto& preview = options->preview;
+ callbacks.mode = preview.mode ? str_to_preview(preview.mode) : PREVIEW_NONE;
+ if (callbacks.mode == PREVIEW_COUNT)
+ throw Error(SD_STATUS_INVALID_ARGUMENT, "preview mode must be none, proj, tae or vae");
+ callbacks.interval = preview.interval;
+ callbacks.denoised = preview.denoised;
+ callbacks.noisy = preview.noisy;
+ callbacks.console_progress = options->console_progress;
+ }
+ }
+ ctx->callbacks = callbacks;
});
}
diff --git a/src/dgl/ops/preview.cpp b/src/dgl/ops/preview.cpp
index 352c271..62321e3 100644
--- a/src/dgl/ops/preview.cpp
+++ b/src/dgl/ops/preview.cpp
@@ -4,7 +4,6 @@
#include <cstdint>
-#include "api/tensor.h"
#include "core/ggml_tensor_utils.h"
#include "dgl/models/circular_axes.h"
#include "dgl/models/diffusion_prediction.h"
@@ -18,7 +17,7 @@
#include "runtime/latent-preview.h"
namespace sd::dgl::ops {
- static void preview_image(int step, const Tensor<float>& latents, SDVersion version, preview_t preview_mode, models::VAE* decoder, sd_preview_cb_t step_callback, void* step_callback_data, bool is_noisy) {
+ static void preview_image(int step, const Tensor<float>& latents, SDVersion version, preview_t preview_mode, models::VAE* decoder, RunEvents& events, bool is_noisy) {
bool is_video = preview_latent_tensor_is_video(latents);
uint32_t dim = is_video ? static_cast<uint32_t>(latents.shape()[3]) : static_cast<uint32_t>(latents.shape()[2]);
const bool sefi = sd_version_is_sefi_image(version);
@@ -116,7 +115,7 @@ namespace sd::dgl::ops {
for (uint32_t i = 0; i < frames; i++) {
images[i] = {img_width, img_height, img_channels, data.data() + i * stride};
}
- sd::api::preview_images(step_callback, step, frames, images.data(), is_noisy, step_callback_data);
+ events.set_preview(images, is_noisy);
return;
}
@@ -139,7 +138,7 @@ namespace sd::dgl::ops {
pixels.emplace_back(images[i].data, std::free);
}
- sd::api::preview_images(step_callback, step, frames, images.data(), is_noisy, step_callback_data);
+ events.set_preview(images, is_noisy);
return;
}
@@ -163,8 +162,7 @@ namespace sd::dgl::ops {
return step.index % interval == 0;
if (interval < 0)
return step.index == -static_cast<int64_t>(interval);
- return step.index == run_.total_steps &&
- (run_.events.uses_legacy_preview() || run_.events.preview_info().sample_pass == 1);
+ return step.index == run_.total_steps && run_.events.sample_pass() == 1;
}
void show(const SamplingStep& step, const Tensor<float>& latent, bool noisy) {
@@ -173,14 +171,12 @@ namespace sd::dgl::ops {
const auto mode = mode_;
if (mode == PREVIEW_PROJ) {
sd::ParallelScope scope(run_.dit.tensor_executor.get());
- preview_image(step.index, latent, run_.dit.version(), mode, nullptr,
- events.preview_callback(), &events, noisy);
+ preview_image(step.index, latent, run_.dit.version(), mode, nullptr, events, noisy);
} else {
models::Model::ExecutionScope model_scope(*decoder_);
model_scope.require_ready();
models::CircularAxesScope axes(*decoder_, circular_x_, circular_y_);
- preview_image(step.index, latent, run_.dit.version(), mode, decoder_.get(),
- events.preview_callback(), &events, noisy);
+ preview_image(step.index, latent, run_.dit.version(), mode, decoder_.get(), events, noisy);
}
events.check_cancelled();
}
@@ -208,9 +204,9 @@ namespace sd::dgl::ops {
: decoder_(std::move(decoder)), circular_x_(circular_x), circular_y_(circular_y) {}
std::unique_ptr<SamplingObserverSession> PreviewObserver::start(const SamplingRun& run) const {
- const auto& callbacks = run.events.callbacks();
- if (callbacks.mode == PREVIEW_NONE || !run.events.preview_callback() || (!callbacks.noisy && !callbacks.denoised))
+ if (!run.events.previews_enabled())
return {};
- return std::make_unique<PreviewSession>(run, decoder_, decoder_ ? callbacks.mode : PREVIEW_PROJ, circular_x_, circular_y_);
+ const auto mode = decoder_ ? run.events.callbacks().mode : PREVIEW_PROJ;
+ return std::make_unique<PreviewSession>(run, decoder_, mode, circular_x_, circular_y_);
}
} // namespace sd::dgl::ops
diff --git a/src/dgl/run_events.cpp b/src/dgl/run_events.cpp
index 38e380b..5e511b0 100644
--- a/src/dgl/run_events.cpp
+++ b/src/dgl/run_events.cpp
@@ -1,110 +1,121 @@
#include "run_events.h"
#include <cstdio>
+#include <utility>
#include "diagnostic.h"
+#include "ggml.h"
namespace sd::dgl {
static thread_local RunEvents* active_events = nullptr;
- RunEvents::RunEvents(const RunCallbacks& callbacks, bool legacy_callbacks)
- : callbacks_(callbacks), legacy_progress_(legacy_callbacks) {
- progress_.set_callback(callbacks_.progress, callbacks_.progress_data);
- if (legacy_callbacks && !callbacks_.preview) {
- legacy_preview_ = sd_get_preview_callback();
- legacy_preview_data_ = sd_get_preview_callback_data();
- callbacks_.mode = sd_get_preview_mode();
- callbacks_.interval = sd_get_preview_interval();
- callbacks_.denoised = sd_should_preview_denoised();
- callbacks_.noisy = sd_should_preview_noisy();
- }
- }
-
void RunEvents::check_cancelled() const {
if (cancelled())
throw Error(SD_STATUS_CANCELLED, "DGL run cancelled");
}
+ void RunEvents::emit(const sd_generation_progress_t& progress) const {
+ if (callbacks_.progress)
+ callbacks_.progress(&progress, callbacks_.progress_data);
+ }
+
void RunEvents::report(const char* stage, const char* detail, int64_t completed, int64_t total, const char* unit) const {
check_cancelled();
- progress_.report(stage, detail, completed, total, unit);
+ emit({stage, detail, unit, completed, total, nullptr});
check_cancelled();
}
void RunEvents::report_frames(const char* stage, int completed, int total) const {
report(stage, "", completed, total, "frames");
- if (legacy_progress_ && sd_get_progress_callback())
- sd_get_progress_callback()(completed, total, 0.f, sd_get_progress_callback_data());
- check_cancelled();
}
- void RunEvents::report_loading(int completed, int total, void* data) {
- const auto& run = *static_cast<RunEvents*>(data);
+ void RunEvents::report_tiles(int completed, int total, float seconds, void* data) {
+ auto& run = *static_cast<RunEvents*>(data);
+ if (completed == 0)
+ run.finish_progress_line();
+ run.render_step(completed, total, seconds);
+ run.report("tiling", "", completed, total, "tiles");
+ }
+
+ void RunEvents::report_loading(int completed, int total, uint64_t bytes, float seconds, void* data) {
+ auto& run = *static_cast<RunEvents*>(data);
// The loader monitors progress while its worker threads are still running.
- if (!run.cancelled())
- run.progress_.report("loading", "", completed, total, "tensors");
+ if (run.cancelled())
+ return;
+ const sd_loading_progress_t loading{bytes, seconds};
+ if (run.uses_console_progress() && completed > 0) {
+ pretty_console_bytes_progress(completed, total, loading.bytes_processed, loading.elapsed_seconds);
+ run.progress_line_open_ = completed > 0 && completed < total;
+ }
+ run.emit({"loading", "", "tensors", completed, total, &loading});
}
- void RunEvents::render_sample_progress(int completed, int total_steps, float time) {
- const bool console_only = forces_console_progress();
- const bool renders_line = console_only || !sd_get_progress_callback();
- if (console_only)
- pretty_console_progress(completed, total_steps, time);
- else
- pretty_progress(completed, total_steps, time);
- sample_line_open_ = renders_line && completed > 0 && completed < total_steps;
+ void RunEvents::render_step(int completed, int total, float seconds) {
+ if (uses_console_progress()) {
+ pretty_console_progress(completed, total, seconds);
+ progress_line_open_ = completed > 0 && completed < total;
+ }
+ }
+
+ void RunEvents::begin_execution() {
+ if (!executing_reported_) {
+ executing_reported_ = true;
+ report("executing");
+ }
}
void RunEvents::begin_sample(int total_steps) {
check_cancelled();
- finish_sample_line();
- ++preview_info_.sample_pass;
- preview_info_.total_steps = total_steps;
- if (legacy_preview_)
- sd_begin_preview_pass(total_steps);
- last_progress_us_ = ggml_time_us();
- if (uses_console_progress())
- render_sample_progress(0, total_steps, 0.f);
- progress_.begin_sample(total_steps, "");
+ finish_progress_line();
+ ++sample_pass_;
+ render_step(0, total_steps, 0.f);
+ const sd_sampling_progress_t sampling{sample_pass_, 0.f, {}, {}};
+ emit({"sampling", "", "steps", 0, total_steps, &sampling});
check_cancelled();
+ last_progress_us_ = ggml_time_us();
}
void RunEvents::sample_step(int completed, int total_steps) {
- if (uses_console_progress()) {
- const auto now = ggml_time_us();
- render_sample_progress(completed, total_steps, (now - last_progress_us_) / 1000000.f);
- last_progress_us_ = now;
- }
- progress_.report_sample(completed, total_steps);
check_cancelled();
+ const auto denoised = std::exchange(denoised_, {});
+ const auto noisy = std::exchange(noisy_, {});
+ const sd_sampling_progress_t sampling{
+ sample_pass_, (ggml_time_us() - last_progress_us_) / 1000000.f, denoised.view(), noisy.view()};
+ render_step(completed, total_steps, sampling.step_seconds);
+ emit({"sampling", "", "steps", completed, total_steps, &sampling});
+ check_cancelled();
+ last_progress_us_ = ggml_time_us();
}
- void RunEvents::finish_sample_line() {
- if (sample_line_open_) {
+ void RunEvents::finish_progress_line() {
+ if (progress_line_open_) {
std::fputc('\n', stdout);
std::fflush(stdout);
- sample_line_open_ = false;
+ progress_line_open_ = false;
}
}
- void RunEvents::preview_bridge(int step, int frame_count, const sd_tensor_t* const* frames, bool noisy, void* userdata) {
- auto& run = *static_cast<RunEvents*>(userdata);
- if (run.cancelled())
- return;
- if (run.callbacks_.preview)
- run.callbacks_.preview(&run.preview_info_, step, frame_count, frames, noisy, run.callbacks_.preview_data);
- else if (run.legacy_preview_)
- run.legacy_preview_(step, frame_count, frames, noisy, run.legacy_preview_data_);
+ void RunEvents::set_preview(const std::vector<sd::Image>& images, bool noisy) {
+ auto& frames = noisy ? noisy_ : denoised_;
+ frames.tensors.reserve(images.size());
+ frames.views.reserve(images.size());
+ for (const auto& image : images) {
+ const int64_t shape[] = {image.channel, image.width, image.height};
+ auto* tensor = sd_tensor_create(SD_TENSOR_U8, 3, shape, image.data, size_t(image.channel) * image.width * image.height);
+ if (!tensor)
+ throw std::bad_alloc();
+ frames.tensors.push_back(api::TensorRef::adopt(tensor));
+ frames.views.push_back(tensor);
+ }
}
RunEventsScope::RunEventsScope(RunEvents& events)
: previous_(active_events),
- byte_progress_(!events.uses_legacy_progress() && events.callbacks().progress ? RunEvents::report_loading : nullptr, &events),
- console_progress_(events.forces_console_progress()) {
+ progress_({RunEvents::report_tiles, RunEvents::report_loading, &events}) {
active_events = &events;
}
RunEventsScope::~RunEventsScope() {
- active_events->finish_sample_line();
+ active_events->finish_progress_line();
active_events = previous_;
}
diff --git a/src/dgl/run_events.h b/src/dgl/run_events.h
index 21bb543..6ce9270 100644
--- a/src/dgl/run_events.h
+++ b/src/dgl/run_events.h
@@ -3,17 +3,15 @@
#include <atomic>
+#include "api/tensor.h"
#include "core/option_types.h"
-#include "core/util.h"
-#include "runtime/generation_progress.h"
+#include "core/progress.h"
namespace sd::dgl {
struct RunCallbacks {
sd_generation_progress_cb_t progress = nullptr;
void* progress_data = nullptr;
- sd_dgl_preview_cb_t preview = nullptr;
- void* preview_data = nullptr;
- enum preview_t mode = PREVIEW_NONE;
+ preview_t mode = PREVIEW_NONE;
int interval = 0;
bool denoised = false;
bool noisy = false;
@@ -21,44 +19,57 @@ namespace sd::dgl {
};
class RunEvents {
+ struct PreviewFrames {
+ std::vector<api::TensorRef> tensors;
+ std::vector<const sd_tensor_t*> views;
+
+ sd_progress_frames_t view() const {
+ return {static_cast<int>(views.size()), views.empty() ? nullptr : views.data()};
+ }
+ };
+
std::atomic<bool> cancelled_{false};
RunCallbacks callbacks_;
- sd::GenerationProgress progress_;
- sd_preview_info_t preview_info_{};
- sd_preview_cb_t legacy_preview_ = nullptr;
- void* legacy_preview_data_ = nullptr;
- bool legacy_progress_ = false;
- int64_t last_progress_us_ = 0;
- bool sample_line_open_ = false;
+ PreviewFrames denoised_;
+ PreviewFrames noisy_;
+ int sample_pass_ = 0;
+ int64_t last_progress_us_ = 0;
+ bool executing_reported_ = false;
+ bool progress_line_open_ = false;
- static void preview_bridge(int step, int frame_count, const sd_tensor_t* const* frames, bool noisy, void* userdata);
- void render_sample_progress(int completed, int total_steps, float time);
+ bool uses_console_progress() const { return !callbacks_.progress || callbacks_.console_progress; }
+ void emit(const sd_generation_progress_t& progress) const;
+ void render_step(int completed, int total, float seconds);
+ static void report_tiles(int completed, int total, float seconds, void* data);
+ static void report_loading(int completed, int total, uint64_t bytes, float seconds, void* data);
+ friend class RunEventsScope;
public:
- RunEvents(const RunCallbacks& callbacks, bool legacy_callbacks);
+ explicit RunEvents(const RunCallbacks& callbacks)
+ : callbacks_(callbacks) {}
void cancel() noexcept { cancelled_.store(true, std::memory_order_relaxed); }
void set_cancelled(bool cancelled) noexcept { cancelled_.store(cancelled, std::memory_order_relaxed); }
bool cancelled() const noexcept { return cancelled_.load(std::memory_order_relaxed); }
void check_cancelled() const;
void report(const char* stage, const char* detail = "", int64_t completed = 0, int64_t total = 0, const char* unit = "") const;
void report_frames(const char* stage, int completed, int total) const;
- static void report_loading(int completed, int total, void* data);
- bool uses_legacy_progress() const { return legacy_progress_; }
- bool forces_console_progress() const { return !legacy_progress_ && callbacks_.console_progress; }
- bool uses_console_progress() const { return legacy_progress_ || !callbacks_.progress || forces_console_progress(); }
+ void begin_execution();
void begin_sample(int total_steps);
void sample_step(int completed, int total_steps);
- void finish_sample_line();
+ void set_preview(const std::vector<sd::Image>& images, bool noisy);
const RunCallbacks& callbacks() const { return callbacks_; }
- const sd_preview_info_t& preview_info() const { return preview_info_; }
- bool uses_legacy_preview() const { return legacy_preview_ != nullptr; }
- sd_preview_cb_t preview_callback() const { return callbacks_.preview || legacy_preview_ ? preview_bridge : nullptr; }
+ bool previews_enabled() const {
+ return callbacks_.progress && callbacks_.mode != PREVIEW_NONE && (callbacks_.noisy || callbacks_.denoised);
+ }
+ int sample_pass() const { return sample_pass_; }
+
+ private:
+ void finish_progress_line();
};
class RunEventsScope {
RunEvents* previous_;
- ByteProgressScope byte_progress_;
- ByteProgressConsoleScope console_progress_;
+ ProgressScope progress_;
public:
explicit RunEventsScope(RunEvents& events);
diff --git a/src/dgl/run_plan.cpp b/src/dgl/run_plan.cpp
index d393a3c..81f9d75 100644
--- a/src/dgl/run_plan.cpp
+++ b/src/dgl/run_plan.cpp
@@ -36,7 +36,7 @@ namespace sd::dgl {
}
RunPlan::RunPlan(const Graph& graph, RunState& state)
- : graph_(graph), state_(state), enabled_(state.context.auto_fit()), vae_preview_(state.events.preview_callback() && (state.events.callbacks().mode == PREVIEW_VAE || state.events.callbacks().mode == PREVIEW_TAE) && (state.events.callbacks().noisy || state.events.callbacks().denoised)) {
+ : graph_(graph), state_(state), enabled_(state.context.auto_fit()), vae_preview_(state.events.previews_enabled() && (state.events.callbacks().mode == PREVIEW_VAE || state.events.callbacks().mode == PREVIEW_TAE)) {
if (graph.resources.empty())
return;
if (std::any_of(graph.resources.begin(), graph.resources.end(), [](const auto& call) {
diff --git a/src/runtime/generation_progress.h b/src/runtime/generation_progress.h
deleted file mode 100644
index a211931..0000000
--- a/src/runtime/generation_progress.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#ifndef __SD_RUNTIME_GENERATION_PROGRESS_H__
-#define __SD_RUNTIME_GENERATION_PROGRESS_H__
-
-#include "stable-diffusion.h"
-
-namespace sd {
-
- class GenerationProgress {
- sd_generation_progress_cb_t callback_ = nullptr;
- void* data_ = nullptr;
- int sample_pass_ = 0;
- const char* sample_detail_ = "";
-
- public:
- void set_callback(sd_generation_progress_cb_t callback, void* data) {
- callback_ = callback;
- data_ = data;
- sample_pass_ = 0;
- sample_detail_ = "";
- }
-
- void report(const char* stage, const char* detail = "", int64_t completed = 0, int64_t total = 0, const char* unit = "") const {
- if (callback_ != nullptr) {
- const sd_generation_progress_t progress{stage, detail, unit, sample_pass_, completed, total};
- callback_(&progress, data_);
- }
- }
-
- void begin_sample(int64_t total, const char* detail) {
- ++sample_pass_;
- sample_detail_ = detail;
- report_sample(0, total);
- }
-
- void report_sample(int64_t completed, int64_t total) const {
- report("sampling", sample_detail_, completed, total, "steps");
- }
- };
-
-} // namespace sd
-
-#endif // __SD_RUNTIME_GENERATION_PROGRESS_H__
diff --git a/src/runtime/tiling.cpp b/src/runtime/tiling.cpp
index efdacdd..c679c0c 100644
--- a/src/runtime/tiling.cpp
+++ b/src/runtime/tiling.cpp
@@ -190,7 +190,7 @@ sd::Tensor<float> process_tiles_2d(const sd::Tensor<float>& input,
if (!silent) {
LOG_VERBOSE("num tiles : %d, %d ", static_cast<int>(tiles_x.size()), static_cast<int>(tiles_y.size()));
LOG_VERBOSE("processing %i tiles", num_tiles);
- pretty_progress(0, num_tiles, 0.0f);
+ report_tile_progress(0, num_tiles, 0.0f);
}
for (const auto& y : tiles_y) {
for (const auto& x : tiles_x) {
@@ -213,7 +213,7 @@ sd::Tensor<float> process_tiles_2d(const sd::Tensor<float>& input,
y.overlap_before * scale_out, y.overlap_after * scale_out);
++tile_count;
if (!silent) {
- pretty_progress(tile_count, num_tiles, (ggml_time_ms() - t1) / 1000.0f);
+ report_tile_progress(tile_count, num_tiles, (ggml_time_ms() - t1) / 1000.0f);
}
}
}