Skip to content

Commit 048a6de

Browse files
committed
Model: merge split models when converting
1 parent bfc1616 commit 048a6de

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
@@ -794,7 +794,7 @@ int main(int argc, const char* argv[]) {
794794
}
795795

796796
if (params.mode == CONVERT) {
797-
bool success = convert(params.model_path.c_str(), params.vae_path.c_str(), params.output_path.c_str(), params.wtype, params.tensor_type_rules.c_str());
797+
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, params.tensor_type_rules.c_str());
798798
if (!success) {
799799
fprintf(stderr,
800800
"convert '%s'/'%s' to '%s' failed\n",

model.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,12 +2267,41 @@ void setConvertImatrixCollector(void* collector) {
22672267
imatrix_collector = ((IMatrixCollector*)collector);
22682268
}
22692269

2270-
bool convert(const char* input_path, const char* vae_path, const char* output_path, sd_type_t output_type, const char* tensor_type_rules) {
2270+
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, const char* tensor_type_rules) {
22712271
ModelLoader model_loader;
22722272

2273-
if (!model_loader.init_from_file(input_path)) {
2274-
LOG_ERROR("init model loader from file failed: '%s'", input_path);
2275-
return false;
2273+
if (model_path != NULL && strlen(model_path) > 0) {
2274+
if (!model_loader.init_from_file(model_path)) {
2275+
LOG_ERROR("init model loader from file failed: '%s'", model_path);
2276+
return false;
2277+
}
2278+
}
2279+
2280+
if (clip_l_path != NULL && strlen(clip_l_path) > 0) {
2281+
if (!model_loader.init_from_file(clip_l_path, "text_encoders.clip_l.transformer.")) {
2282+
LOG_ERROR("init model loader from file failed: '%s'", clip_l_path);
2283+
return false;
2284+
}
2285+
}
2286+
2287+
if (clip_g_path != NULL && strlen(clip_g_path) > 0) {
2288+
if (!model_loader.init_from_file(clip_g_path, "text_encoders.clip_g.transformer.")) {
2289+
LOG_ERROR("init model loader from file failed: '%s'", clip_g_path);
2290+
return false;
2291+
}
2292+
}
2293+
if (t5xxl_path != NULL && strlen(t5xxl_path) > 0) {
2294+
if (!model_loader.init_from_file(t5xxl_path, "text_encoders.t5xxl.transformer.")) {
2295+
LOG_ERROR("init model loader from file failed: '%s'", t5xxl_path);
2296+
return false;
2297+
}
2298+
}
2299+
2300+
if (diffusion_model_path != NULL && strlen(diffusion_model_path) > 0) {
2301+
if (!model_loader.init_from_file(diffusion_model_path, "model.diffusion_model.")) {
2302+
LOG_ERROR("init model loader from file failed: '%s'", diffusion_model_path);
2303+
return false;
2304+
}
22762305
}
22772306

22782307
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
@@ -243,7 +243,7 @@ SD_API void free_upscaler_ctx(upscaler_ctx_t* upscaler_ctx);
243243

244244
SD_API sd_image_t upscale(upscaler_ctx_t* upscaler_ctx, sd_image_t input_image, uint32_t upscale_factor);
245245

246-
SD_API bool convert(const char* input_path,
246+
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,
247247
const char* vae_path,
248248
const char* output_path,
249249
enum sd_type_t output_type,

0 commit comments

Comments
 (0)