Skip to content

Commit 24d8fd7

Browse files
committedMar 28, 2025
Model: merge split models when converting
1 parent 5a38db8 commit 24d8fd7

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed
 

‎examples/cli/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ int main(int argc, const char* argv[]) {
841841
}
842842

843843
if (params.mode == CONVERT) {
844-
bool success = convert(params.model_path.c_str(), params.vae_path.c_str(), params.output_path.c_str(), params.wtype);
844+
bool success = convert(params.model_path.c_str(), params.clip_l_path.c_str(), params.clip_g_path.c_str(), params.t5xxl_path.c_str(), params.diffusion_model_path.c_str(), params.vae_path.c_str(), params.output_path.c_str(), params.wtype);
845845
if (!success) {
846846
fprintf(stderr,
847847
"convert '%s'/'%s' to '%s' failed\n",

‎model.cpp

+33-4
Original file line numberDiff line numberDiff line change
@@ -2073,12 +2073,41 @@ void setConvertImatrixCollector(void* collector) {
20732073
imatrix_collector = ((IMatrixCollector*)collector);
20742074
}
20752075

2076-
bool convert(const char* input_path, const char* vae_path, const char* output_path, sd_type_t output_type) {
2076+
bool convert(const char* model_path, const char* clip_l_path, const char* clip_g_path, const char* t5xxl_path, const char* diffusion_model_path, const char* vae_path, const char* output_path, sd_type_t output_type) {
20772077
ModelLoader model_loader;
20782078

2079-
if (!model_loader.init_from_file(input_path)) {
2080-
LOG_ERROR("init model loader from file failed: '%s'", input_path);
2081-
return false;
2079+
if (model_path != NULL && strlen(model_path) > 0) {
2080+
if (!model_loader.init_from_file(model_path)) {
2081+
LOG_ERROR("init model loader from file failed: '%s'", model_path);
2082+
return false;
2083+
}
2084+
}
2085+
2086+
if (clip_l_path != NULL && strlen(clip_l_path) > 0) {
2087+
if (!model_loader.init_from_file(clip_l_path, "text_encoders.clip_l.transformer.")) {
2088+
LOG_ERROR("init model loader from file failed: '%s'", clip_l_path);
2089+
return false;
2090+
}
2091+
}
2092+
2093+
if (clip_g_path != NULL && strlen(clip_g_path) > 0) {
2094+
if (!model_loader.init_from_file(clip_g_path, "text_encoders.clip_g.transformer.")) {
2095+
LOG_ERROR("init model loader from file failed: '%s'", clip_g_path);
2096+
return false;
2097+
}
2098+
}
2099+
if (t5xxl_path != NULL && strlen(t5xxl_path) > 0) {
2100+
if (!model_loader.init_from_file(t5xxl_path, "text_encoders.t5xxl.transformer.")) {
2101+
LOG_ERROR("init model loader from file failed: '%s'", t5xxl_path);
2102+
return false;
2103+
}
2104+
}
2105+
2106+
if (diffusion_model_path != NULL && strlen(diffusion_model_path) > 0) {
2107+
if (!model_loader.init_from_file(diffusion_model_path, "model.diffusion_model.")) {
2108+
LOG_ERROR("init model loader from file failed: '%s'", diffusion_model_path);
2109+
return false;
2110+
}
20822111
}
20832112

20842113
if (vae_path != NULL && strlen(vae_path) > 0) {

‎stable-diffusion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ SD_API void free_upscaler_ctx(upscaler_ctx_t* upscaler_ctx);
231231
SD_API sd_image_t upscale(upscaler_ctx_t* upscaler_ctx, sd_image_t input_image, uint32_t upscale_factor);
232232

233233
SD_API void setConvertImatrixCollector(void * collector);
234-
SD_API bool convert(const char* input_path, const char* vae_path, const char* output_path, enum sd_type_t output_type);
234+
SD_API bool convert(const char* model_path, const char* clip_l_path, const char* clip_g_path, const char* t5xxl_path, const char* diffusion_model_path, const char* vae_path, const char* output_path, enum sd_type_t output_type);
235235

236236
SD_API uint8_t* preprocess_canny(uint8_t* img,
237237
int width,

0 commit comments

Comments
 (0)