Skip to content

feat: expose the loaded model version name through the public API - #1962

Merged
leejet merged 1 commit into
leejet:masterfrom
fszontagh:feat/model-version-name-api
Sep 11, 2026
Merged

feat: expose the loaded model version name through the public API#1962
leejet merged 1 commit into
leejet:masterfrom
fszontagh:feat/model-version-name-api

Conversation

@fszontagh

Copy link
Copy Markdown
Contributor

Summary

Adds sd_get_model_version_name() so a library user can identify the architecture of a loaded model.

The version is detected at load time and already logged, but is not reachable through the C API.

Requires a successfully loaded context - new_sd_ctx() returns NULL on a failed load, so this does not identify a model file without loading it. Returns "Unknown" instead of NULL for a null context or an unidentified model.

Also adds the size guard model_version_to_str[] was missing, matching sampling_methods_str[] and scheduler_to_str[].

Exposes the display name, not the SDVersion enum, to keep the enum numbering out of the public ABI.

Related Issue / Discussion

Additional Information

Verified by linking a plain C translation unit that includes only stable-diffusion.h, then loading real checkpoints:

NULL ctx           -> "Unknown"
SD 1.x             -> "SD 1.x"
SD 1.x inpaint     -> "SD 1.x Inpaint"
SDXL               -> "SDXL"

clang-format reports no change to the added lines.

Checklist

@leejet
leejet merged commit e06b205 into leejet:master Sep 11, 2026
9 checks passed
@fszontagh
fszontagh deleted the feat/model-version-name-api branch September 11, 2026 15:58
fszontagh added a commit to fszontagh/stable-diffusion.cpp-restapi that referenced this pull request Sep 11, 2026
Upstream picked up leejet/stable-diffusion.cpp#1962 - our
sd_get_model_version_name is now part of the public C API surface.
Bumps the pin to e06b2053 (3 commits since the previous head), which
brings:

- #1959 fix: preserve BF16 embedding weights for get_rows
- #1961 fix: handle invalid option numbers
- #1962 feat: expose the loaded model version name through the public
  API - our PR, upstreamed

The CMakeLists.txt patch block now detects that both the header
declaration and the .cpp body are already present in the fetched
source and skips both patches automatically. Verified with a
`grep -c sd_get_model_version_name` across include/*.h + src/*.cpp:
1 hit in the header, 1 in stable-diffusion.cpp, zero anywhere else.

Consequence for future bumps: the patch block is now dead weight
that only re-activates if a future refactor moves the definition
out of upstream. Leaving it in as a safety net for now; can drop
entirely after a few more upstream bumps confirm stability.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants