Skip to content

Commit 934710b

Browse files
committed
Model: merge split models when converting
1 parent 665abff commit 934710b

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

examples/cli/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ int main(int argc, const char* argv[]) {
952952
}
953953

954954
if (params.mode == CONVERT) {
955-
bool success = convert(params.model_path.c_str(), params.vae_path.c_str(), params.output_path.c_str(), params.wtype);
955+
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);
956956
if (!success) {
957957
fprintf(stderr,
958958
"convert '%s'/'%s' to '%s' failed\n",

model.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,12 +2076,41 @@ void setConvertImatrixCollector(void* collector) {
20762076
imatrix_collector = ((IMatrixCollector*)collector);
20772077
}
20782078

2079-
bool convert(const char* input_path, const char* vae_path, const char* output_path, sd_type_t output_type) {
2079+
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) {
20802080
ModelLoader model_loader;
20812081

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

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

stable-diffusion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ SD_API void free_upscaler_ctx(upscaler_ctx_t* upscaler_ctx);
253253
SD_API sd_image_t upscale(upscaler_ctx_t* upscaler_ctx, sd_image_t input_image, uint32_t upscale_factor);
254254

255255
SD_API void setConvertImatrixCollector(void * collector);
256-
SD_API bool convert(const char* input_path, const char* vae_path, const char* output_path, enum sd_type_t output_type);
256+
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);
257257

258258
SD_API uint8_t* preprocess_canny(uint8_t* img,
259259
int width,

0 commit comments

Comments
 (0)