From 636a19b283117a4b4b95184d7f3c6ac5b05ddb9c Mon Sep 17 00:00:00 2001 From: fszontagh Date: Fri, 11 Sep 2026 15:34:34 +0200 Subject: [PATCH] feat: expose the loaded model version name through the public API --- include/stable-diffusion.h | 3 +++ src/pipeline/diffusion_engine.cpp | 3 +++ src/stable-diffusion.cpp | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/include/stable-diffusion.h b/include/stable-diffusion.h index 08bc27aee..e24b84d8d 100644 --- a/include/stable-diffusion.h +++ b/include/stable-diffusion.h @@ -493,6 +493,9 @@ SD_API void free_sd_audio(sd_audio_t* audio); SD_API void sd_sample_params_init(sd_sample_params_t* sample_params); SD_API char* sd_sample_params_to_str(const sd_sample_params_t* sample_params); +// Requires a loaded context; returns a static string owned by the library, or "Unknown". +SD_API const char* sd_get_model_version_name(const sd_ctx_t* sd_ctx); + SD_API enum sample_method_t sd_get_default_sample_method(const sd_ctx_t* sd_ctx); SD_API enum scheduler_t sd_get_default_scheduler(const sd_ctx_t* sd_ctx, enum sample_method_t sample_method); diff --git a/src/pipeline/diffusion_engine.cpp b/src/pipeline/diffusion_engine.cpp index 7dba74b8f..9ecf8f402 100644 --- a/src/pipeline/diffusion_engine.cpp +++ b/src/pipeline/diffusion_engine.cpp @@ -99,6 +99,9 @@ const char* model_version_to_str[] = { "ESRGAN", }; +static_assert(VERSION_COUNT == sizeof(model_version_to_str) / sizeof(model_version_to_str[0]), + "\nnumber of elements in model_version_to_str[] != VERSION_COUNT"); + void calculate_alphas_cumprod(float* alphas_cumprod, float linear_start = 0.00085f, float linear_end = 0.0120f, diff --git a/src/stable-diffusion.cpp b/src/stable-diffusion.cpp index cda44e92b..a50c75da1 100644 --- a/src/stable-diffusion.cpp +++ b/src/stable-diffusion.cpp @@ -695,6 +695,13 @@ SD_API bool sd_ctx_has_control_net(const sd_ctx_t* sd_ctx) { return sd_ctx->sd->control_net != nullptr; } +const char* sd_get_model_version_name(const sd_ctx_t* sd_ctx) { + if (sd_ctx == nullptr || sd_ctx->sd == nullptr || sd_ctx->sd->version >= VERSION_COUNT) { + return "Unknown"; + } + return model_version_to_str[sd_ctx->sd->version]; +} + enum sample_method_t sd_get_default_sample_method(const sd_ctx_t* sd_ctx) { return sd::pipeline::default_sample_method(sd_ctx != nullptr ? sd_ctx->sd : nullptr); }