@@ -34,9 +34,11 @@ struct convert_params {
34
34
std::string clip_g_model_file_path;
35
35
std::string t5xxl_model_file_path;
36
36
std::string output_file_path;
37
- ggml_type vae_output_type = GGML_TYPE_COUNT;
38
- ggml_type clip_output_type = GGML_TYPE_COUNT;
39
- ggml_type output_type = GGML_TYPE_F16;
37
+ ggml_type vae_output_type = GGML_TYPE_COUNT;
38
+ ggml_type clip_l_output_type = GGML_TYPE_COUNT;
39
+ ggml_type clip_g_output_type = GGML_TYPE_COUNT;
40
+ ggml_type t5xxl_output_type = GGML_TYPE_COUNT;
41
+ ggml_type output_type = GGML_TYPE_F16;
40
42
};
41
43
42
44
static void convert_params_print_usage (int , char ** argv, const convert_params& params) {
@@ -51,7 +53,9 @@ static void convert_params_print_usage(int, char** argv, const convert_params& p
51
53
printf (" --t5xxl-model path to t5xxl model file\n " );
52
54
printf (" --outfile path to write to\n " );
53
55
printf (" --vae-outtype output format of vae model, reuse --outtype if not specified\n " );
54
- printf (" --clip-outtype output format of clip_l/clip_g/t5xxl model, reuse --outtype if not specified\n " );
56
+ printf (" --clip-l-outtype output format of clip_l model, reuse --outtype if not specified\n " );
57
+ printf (" --clip-g-outtype output format of clip_g model, reuse --outtype if not specified\n " );
58
+ printf (" --t5xxl-outtype output format of t5xxl model, reuse --outtype if not specified\n " );
55
59
printf (" --outtype output format, select from fp32;fp16;q8_0;q5_1;q5_0;q4_1;q4_0;q4_k;q3_k;q2_k\n " );
56
60
}
57
61
@@ -157,14 +161,38 @@ static bool convert_params_parse(int argc, char** argv, convert_params& params)
157
161
continue ;
158
162
}
159
163
160
- if (!strcmp (flag, " --clip-outtype" )) {
164
+ if (!strcmp (flag, " --clip-l- outtype" )) {
161
165
if (i == argc) {
162
- missing (" --clip-outtype" );
166
+ missing (" --clip-l- outtype" );
163
167
}
164
- const char * outtype = argv[i++];
165
- params.clip_output_type = convert_str_to_ggml_type (outtype);
166
- if (params.clip_output_type >= GGML_TYPE_COUNT) {
167
- invalid (" --clip-outtype" );
168
+ const char * outtype = argv[i++];
169
+ params.clip_l_output_type = convert_str_to_ggml_type (outtype);
170
+ if (params.clip_l_output_type >= GGML_TYPE_COUNT) {
171
+ invalid (" --clip-l-outtype" );
172
+ }
173
+ continue ;
174
+ }
175
+
176
+ if (!strcmp (flag, " --clip-g-outtype" )) {
177
+ if (i == argc) {
178
+ missing (" --clip-g-outtype" );
179
+ }
180
+ const char * outtype = argv[i++];
181
+ params.clip_g_output_type = convert_str_to_ggml_type (outtype);
182
+ if (params.clip_g_output_type >= GGML_TYPE_COUNT) {
183
+ invalid (" --clip-g-outtype" );
184
+ }
185
+ continue ;
186
+ }
187
+
188
+ if (!strcmp (flag, " --t5xxl-outtype" )) {
189
+ if (i == argc) {
190
+ missing (" --t5xxl-outtype" );
191
+ }
192
+ const char * outtype = argv[i++];
193
+ params.t5xxl_output_type = convert_str_to_ggml_type (outtype);
194
+ if (params.t5xxl_output_type >= GGML_TYPE_COUNT) {
195
+ invalid (" --t5xxl-outtype" );
168
196
}
169
197
continue ;
170
198
}
@@ -252,7 +280,7 @@ int convert_sd3(const convert_params& params, const SDVersion ver) {
252
280
bool loaded = false ;
253
281
254
282
if (params.clip_l_model_file_path .empty ()) {
255
- loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder/model" , params.clip_output_type , " te." );
283
+ loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder/model" , params.clip_l_output_type , " te." );
256
284
} else {
257
285
loaded = loader.init_from_file (params.clip_l_model_file_path , " te." );
258
286
}
@@ -262,7 +290,7 @@ int convert_sd3(const convert_params& params, const SDVersion ver) {
262
290
}
263
291
264
292
if (params.clip_g_model_file_path .empty ()) {
265
- loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder_2/model" , params.clip_output_type , " te1." );
293
+ loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder_2/model" , params.clip_g_output_type , " te1." );
266
294
} else {
267
295
loaded = loader.init_from_file (params.clip_g_model_file_path , " te1." );
268
296
}
@@ -272,7 +300,7 @@ int convert_sd3(const convert_params& params, const SDVersion ver) {
272
300
}
273
301
274
302
if (params.t5xxl_model_file_path .empty ()) {
275
- loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder_3/model" , params.clip_output_type , " te2." );
303
+ loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder_3/model" , params.t5xxl_output_type , " te2." );
276
304
} else {
277
305
loaded = loader.init_from_file (params.t5xxl_model_file_path , " te2." );
278
306
}
@@ -308,15 +336,20 @@ int convert_sd3(const convert_params& params, const SDVersion ver) {
308
336
return 1 ;
309
337
}
310
338
311
- return !loader.save_to_gguf_file (params.output_file_path , params.output_type , params.vae_output_type , params.clip_output_type );
339
+ return !loader.save_to_gguf_file (params.output_file_path ,
340
+ params.output_type ,
341
+ params.vae_output_type ,
342
+ params.clip_l_output_type ,
343
+ params.clip_g_output_type ,
344
+ params.t5xxl_output_type );
312
345
}
313
346
314
347
int convert_flux (const convert_params& params, const SDVersion ver) {
315
348
ModelLoader loader;
316
349
bool loaded = false ;
317
350
318
351
if (params.clip_l_model_file_path .empty ()) {
319
- loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder/model" , params.clip_output_type , " te." );
352
+ loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder/model" , params.clip_l_output_type , " te." );
320
353
} else {
321
354
loaded = loader.init_from_file (params.clip_l_model_file_path , " te." );
322
355
}
@@ -326,7 +359,7 @@ int convert_flux(const convert_params& params, const SDVersion ver) {
326
359
}
327
360
328
361
if (params.t5xxl_model_file_path .empty ()) {
329
- loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder_2/model" , params.clip_output_type , " te1." );
362
+ loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder_2/model" , params.t5xxl_output_type , " te1." );
330
363
} else {
331
364
loaded = loader.init_from_file (params.t5xxl_model_file_path , " te1." );
332
365
}
@@ -366,7 +399,12 @@ int convert_flux(const convert_params& params, const SDVersion ver) {
366
399
return 1 ;
367
400
}
368
401
369
- return !loader.save_to_gguf_file (params.output_file_path , params.output_type , params.vae_output_type , params.clip_output_type );
402
+ return !loader.save_to_gguf_file (params.output_file_path ,
403
+ params.output_type ,
404
+ params.vae_output_type ,
405
+ params.clip_l_output_type ,
406
+ params.clip_g_output_type ,
407
+ params.t5xxl_output_type );
370
408
}
371
409
372
410
int convert_sdxl (const convert_params& params, const SDVersion ver) {
@@ -375,7 +413,9 @@ int convert_sdxl(const convert_params& params, const SDVersion ver) {
375
413
376
414
if (params.clip_l_model_file_path .empty ()) {
377
415
if (is_directory (path_join (params.model_path , " text_encoder" ))) {
378
- loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder/model" , params.clip_output_type , " te." );
416
+ loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder/model" , params.clip_l_output_type , " te." );
417
+ } else {
418
+ loaded = true ;
379
419
}
380
420
} else {
381
421
loaded = loader.init_from_file (params.clip_l_model_file_path , " te." );
@@ -386,7 +426,7 @@ int convert_sdxl(const convert_params& params, const SDVersion ver) {
386
426
}
387
427
388
428
if (params.clip_g_model_file_path .empty ()) {
389
- loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder_2/model" , params.clip_output_type , " te1." );
429
+ loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder_2/model" , params.clip_g_output_type , " te1." );
390
430
} else {
391
431
loaded = loader.init_from_file (params.clip_g_model_file_path , " te1." );
392
432
}
@@ -422,15 +462,20 @@ int convert_sdxl(const convert_params& params, const SDVersion ver) {
422
462
return 1 ;
423
463
}
424
464
425
- return !loader.save_to_gguf_file (params.output_file_path , params.output_type , params.vae_output_type , params.clip_output_type );
465
+ return !loader.save_to_gguf_file (params.output_file_path ,
466
+ params.output_type ,
467
+ params.vae_output_type ,
468
+ params.clip_l_output_type ,
469
+ params.clip_g_output_type ,
470
+ params.t5xxl_output_type );
426
471
}
427
472
428
473
int convert_sd (const convert_params& params, const SDVersion ver) {
429
474
ModelLoader loader;
430
475
bool loaded = false ;
431
476
432
477
if (params.clip_l_model_file_path .empty ()) {
433
- loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder/model" , params.clip_output_type , " te." );
478
+ loaded = loader.init_from_safetensors_file (params.model_path , " text_encoder/model" , params.clip_l_output_type , " te." );
434
479
} else {
435
480
loaded = loader.init_from_file (params.clip_l_model_file_path , " te." );
436
481
}
@@ -466,7 +511,12 @@ int convert_sd(const convert_params& params, const SDVersion ver) {
466
511
return 1 ;
467
512
}
468
513
469
- return !loader.save_to_gguf_file (params.output_file_path , params.output_type , params.vae_output_type , params.clip_output_type );
514
+ return !loader.save_to_gguf_file (params.output_file_path ,
515
+ params.output_type ,
516
+ params.vae_output_type ,
517
+ params.clip_l_output_type ,
518
+ params.clip_g_output_type ,
519
+ params.t5xxl_output_type );
470
520
}
471
521
472
522
int convert_file (const convert_params& params) {
0 commit comments