@@ -239,30 +239,6 @@ int convert_sd3(const convert_params& params, const SDVersion ver) {
239
239
ModelLoader loader;
240
240
bool loaded = false ;
241
241
242
- bool ignore_vae = false ;
243
- if (params.diffusion_model_file_path .empty ()) {
244
- loaded = loader.init_from_safetensors_file (params.model_path , " transformer/diffusion_pytorch_model" , params.output_type , " transformer." );
245
- } else {
246
- ignore_vae = true ;
247
- loaded = loader.init_from_file (params.diffusion_model_file_path );
248
- }
249
- if (!loaded) {
250
- LOG_ERROR (" Failed to load transformer model" );
251
- return 1 ;
252
- }
253
-
254
- if (!ignore_vae || !params.vae_model_file_path .empty ()) {
255
- if (params.vae_model_file_path .empty ()) {
256
- loaded = loader.init_from_safetensors_file (params.model_path , " vae/diffusion_pytorch_model" , params.vae_output_type , " vae." );
257
- } else {
258
- loaded = loader.init_from_file (params.vae_model_file_path , " vae." );
259
- }
260
- if (!loaded) {
261
- LOG_ERROR (" Failed to load vae model" );
262
- return 1 ;
263
- }
264
- }
265
-
266
242
if (params.clip_l_model_file_path .empty ()) {
267
243
loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder/model" , params.clip_output_type , " te." );
268
244
} else {
@@ -293,27 +269,9 @@ int convert_sd3(const convert_params& params, const SDVersion ver) {
293
269
return 1 ;
294
270
}
295
271
296
- return !loader.save_to_gguf_file (params.output_file_path , params.output_type , params.vae_output_type , params.clip_output_type );
297
- }
298
-
299
- int convert_flux (const convert_params& params, const SDVersion ver) {
300
- ModelLoader loader;
301
- bool loaded = false ;
302
-
303
272
bool ignore_vae = false ;
304
- if (params.diffusion_model_file_path .empty ()) {
305
- if (ver == VERSION_FLUX_DEV) {
306
- loaded = loader.init_from_safetensors_file (params.model_path , " flux1-dev" , params.output_type , " transformer." );
307
- } else {
308
- loaded = loader.init_from_safetensors_file (params.model_path , " flux1-schnell" , params.output_type , " transformer." );
309
- }
310
- } else {
273
+ if (!params.diffusion_model_file_path .empty ()) {
311
274
ignore_vae = true ;
312
- loaded = loader.init_from_file (params.diffusion_model_file_path );
313
- }
314
- if (!loaded) {
315
- LOG_ERROR (" Failed to load transformer model" );
316
- return 1 ;
317
275
}
318
276
319
277
if (!ignore_vae || !params.vae_model_file_path .empty ()) {
@@ -328,6 +286,23 @@ int convert_flux(const convert_params& params, const SDVersion ver) {
328
286
}
329
287
}
330
288
289
+ if (params.diffusion_model_file_path .empty ()) {
290
+ loaded = loader.init_from_safetensors_file (params.model_path , " transformer/diffusion_pytorch_model" , params.output_type , " transformer." );
291
+ } else {
292
+ loaded = loader.init_from_file (params.diffusion_model_file_path );
293
+ }
294
+ if (!loaded) {
295
+ LOG_ERROR (" Failed to load transformer model" );
296
+ return 1 ;
297
+ }
298
+
299
+ return !loader.save_to_gguf_file (params.output_file_path , params.output_type , params.vae_output_type , params.clip_output_type );
300
+ }
301
+
302
+ int convert_flux (const convert_params& params, const SDVersion ver) {
303
+ ModelLoader loader;
304
+ bool loaded = false ;
305
+
331
306
if (params.clip_l_model_file_path .empty ()) {
332
307
loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder/model" , params.clip_output_type , " te." );
333
308
} else {
@@ -348,23 +323,9 @@ int convert_flux(const convert_params& params, const SDVersion ver) {
348
323
return 1 ;
349
324
}
350
325
351
- return !loader.save_to_gguf_file (params.output_file_path , params.output_type , params.vae_output_type , params.clip_output_type );
352
- }
353
-
354
- int convert_sdxl (const convert_params& params, const SDVersion ver) {
355
- ModelLoader loader;
356
- bool loaded = false ;
357
-
358
326
bool ignore_vae = false ;
359
- if (params.diffusion_model_file_path .empty ()) {
360
- loaded = loader.init_from_safetensors_file (params.model_path , " unet/diffusion_pytorch_model" , params.output_type , " unet." );
361
- } else {
327
+ if (!params.diffusion_model_file_path .empty ()) {
362
328
ignore_vae = true ;
363
- loaded = loader.init_from_file (params.diffusion_model_file_path );
364
- }
365
- if (!loaded) {
366
- LOG_ERROR (" Failed to load unet model" );
367
- return 1 ;
368
329
}
369
330
370
331
if (!ignore_vae || !params.vae_model_file_path .empty ()) {
@@ -379,6 +340,27 @@ int convert_sdxl(const convert_params& params, const SDVersion ver) {
379
340
}
380
341
}
381
342
343
+ if (params.diffusion_model_file_path .empty ()) {
344
+ if (ver == VERSION_FLUX_DEV) {
345
+ loaded = loader.init_from_safetensors_file (params.model_path , " flux1-dev" , params.output_type , " transformer." );
346
+ } else {
347
+ loaded = loader.init_from_safetensors_file (params.model_path , " flux1-schnell" , params.output_type , " transformer." );
348
+ }
349
+ } else {
350
+ loaded = loader.init_from_file (params.diffusion_model_file_path , " model.diffusion_model." );
351
+ }
352
+ if (!loaded) {
353
+ LOG_ERROR (" Failed to load transformer model" );
354
+ return 1 ;
355
+ }
356
+
357
+ return !loader.save_to_gguf_file (params.output_file_path , params.output_type , params.vae_output_type , params.clip_output_type );
358
+ }
359
+
360
+ int convert_sdxl (const convert_params& params, const SDVersion ver) {
361
+ ModelLoader loader;
362
+ bool loaded = false ;
363
+
382
364
if (params.clip_l_model_file_path .empty ()) {
383
365
if (is_directory (path_join (params.model_path , " text_encoder" ))) {
384
366
loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder/model" , params.clip_output_type , " te." );
@@ -401,25 +383,55 @@ int convert_sdxl(const convert_params& params, const SDVersion ver) {
401
383
return 1 ;
402
384
}
403
385
386
+ bool ignore_vae = false ;
387
+ if (!params.diffusion_model_file_path .empty ()) {
388
+ ignore_vae = true ;
389
+ }
390
+
391
+ if (!ignore_vae || !params.vae_model_file_path .empty ()) {
392
+ if (params.vae_model_file_path .empty ()) {
393
+ loaded = loader.init_from_safetensors_file (params.model_path , " vae/diffusion_pytorch_model" , params.vae_output_type , " vae." );
394
+ } else {
395
+ loaded = loader.init_from_file (params.vae_model_file_path , " vae." );
396
+ }
397
+ if (!loaded) {
398
+ LOG_ERROR (" Failed to load vae model" );
399
+ return 1 ;
400
+ }
401
+ }
402
+
403
+ if (params.diffusion_model_file_path .empty ()) {
404
+ loaded = loader.init_from_safetensors_file (params.model_path , " unet/diffusion_pytorch_model" , params.output_type , " unet." );
405
+ } else {
406
+ loaded = loader.init_from_file (params.diffusion_model_file_path );
407
+ }
408
+ if (!loaded) {
409
+ LOG_ERROR (" Failed to load unet model" );
410
+ return 1 ;
411
+ }
412
+
404
413
return !loader.save_to_gguf_file (params.output_file_path , params.output_type , params.vae_output_type , params.clip_output_type );
405
414
}
406
415
407
416
int convert_sd (const convert_params& params, const SDVersion ver) {
408
417
ModelLoader loader;
409
418
bool loaded = false ;
410
419
411
- bool ignore_vae = false ;
412
- if (params.diffusion_model_file_path .empty ()) {
413
- loaded = loader.init_from_safetensors_file (params.model_path , " unet/diffusion_pytorch_model" , params.output_type , " unet." );
420
+ if (params.clip_l_model_file_path .empty ()) {
421
+ loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder/model" , params.clip_output_type , " te." );
414
422
} else {
415
- ignore_vae = true ;
416
- loaded = loader.init_from_file (params.diffusion_model_file_path );
423
+ loaded = loader.init_from_file (params.clip_l_model_file_path , " te." );
417
424
}
418
425
if (!loaded) {
419
- LOG_ERROR (" Failed to load unet model" );
426
+ LOG_ERROR (" Failed to load text encoder model" );
420
427
return 1 ;
421
428
}
422
429
430
+ bool ignore_vae = false ;
431
+ if (!params.diffusion_model_file_path .empty ()) {
432
+ ignore_vae = true ;
433
+ }
434
+
423
435
if (!ignore_vae || !params.vae_model_file_path .empty ()) {
424
436
if (params.vae_model_file_path .empty ()) {
425
437
loaded = loader.init_from_safetensors_file (params.model_path , " vae/diffusion_pytorch_model" , params.vae_output_type , " vae." );
@@ -432,13 +444,13 @@ int convert_sd(const convert_params& params, const SDVersion ver) {
432
444
}
433
445
}
434
446
435
- if (params.clip_l_model_file_path .empty ()) {
436
- loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder/model " , params.clip_output_type , " te ." );
447
+ if (params.diffusion_model_file_path .empty ()) {
448
+ loaded = loader.init_from_safetensors_file (params.model_path , " unet/diffusion_pytorch_model " , params.output_type , " unet ." );
437
449
} else {
438
- loaded = loader.init_from_file (params.clip_l_model_file_path , " te. " );
450
+ loaded = loader.init_from_file (params.diffusion_model_file_path );
439
451
}
440
452
if (!loaded) {
441
- LOG_ERROR (" Failed to load text encoder model" );
453
+ LOG_ERROR (" Failed to load unet model" );
442
454
return 1 ;
443
455
}
444
456
@@ -505,11 +517,13 @@ int main(int argc, char** argv) {
505
517
return 1 ;
506
518
}
507
519
auto text_encoder_config = load_json (text_encoder_config_path);
508
- auto guidance_embeds = text_encoder_config.at (" guidance_embeds" ).get <bool >();
509
- if (guidance_embeds) {
510
- ver = VERSION_FLUX_DEV;
520
+ ver = VERSION_FLUX_SCHNELL;
521
+ if (text_encoder_config.contains (" guidance_embeds" )) {
522
+ auto guidance_embeds = text_encoder_config.at (" guidance_embeds" ).get <bool >();
523
+ if (guidance_embeds) {
524
+ ver = VERSION_FLUX_DEV;
525
+ }
511
526
} else {
512
- ver = VERSION_FLUX_SCHNELL;
513
527
}
514
528
} else if (class_name == " StableDiffusionXLPipeline" || class_name == " StableDiffusionXLImg2ImgPipeline" ) {
515
529
ver = VERSION_SDXL;
0 commit comments