forked from mcmonkeyprojects/SwarmUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkflowGeneratorModelSupport.cs
More file actions
1406 lines (1319 loc) · 65.9 KB
/
Copy pathWorkflowGeneratorModelSupport.cs
File metadata and controls
1406 lines (1319 loc) · 65.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Text;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using SwarmUI.Core;
using SwarmUI.Text2Image;
using SwarmUI.Utils;
using Newtonsoft.Json.Linq;
using FreneticUtilities.FreneticExtensions;
namespace SwarmUI.Builtin_ComfyUIBackend;
public partial class WorkflowGenerator
{
/// <summary>
/// Map of model architecture IDs to Func(int width, int height, int batchSize, string id = null) => WGNodeData.
/// Used for custom model classes to implement <see cref="CreateEmptyImage"/>
/// </summary>
public static Dictionary<string, Func<int, int, int, string, WGNodeData>> EmptyImageCreators = [];
public bool IsModelCompatClass(T2IModelCompatClass targetClazz)
{
string clazz = CurrentCompatClass();
return clazz is not null && clazz == targetClazz.ID;
}
/// <summary>Returns true if the current model is Stable Cascade.</summary>
public bool IsCascade() => IsModelCompatClass(T2IModelClassSorter.CompatCascade);
/// <summary>Returns true if the current model is Stable Diffusion 3.</summary>
public bool IsSD3()
{
string clazz = CurrentCompatClass();
if (clazz is null)
{
return false;
}
return clazz.StartsWith("stable-diffusion-v3");
}
/// <summary>Returns true if the current model is Mochi Text2Video.</summary>
public bool IsMochi() => IsModelCompatClass(T2IModelClassSorter.CompatGenmoMochi);
/// <summary>Returns true if the current model is Lightricks LTX Video.</summary>
public bool IsLTXV() => IsModelCompatClass(T2IModelClassSorter.CompatLtxv);
/// <summary>Returns true if the current model is Lightricks LTX Video 2.</summary>
public bool IsLTXV2() => IsModelCompatClass(T2IModelClassSorter.CompatLtxv2);
/// <summary>Returns true if the current model is Black Forest Labs' Flux.1.</summary>
public bool IsFlux() => IsModelCompatClass(T2IModelClassSorter.CompatFlux);
/// <summary>Returns true if the current model is Black Forest Labs' Flux.2 Dev.</summary>
public bool IsFlux2Dev() => IsModelCompatClass(T2IModelClassSorter.CompatFlux2);
/// <summary>Returns true if the current model is Black Forest Labs' Flux.2 Klein (4B).</summary>
public bool IsFlux2Klein4B() => IsModelCompatClass(T2IModelClassSorter.CompatFlux2Klein4B);
/// <summary>Returns true if the current model is Black Forest Labs' Flux.2 Klein (9B).</summary>
public bool IsFlux2Klein9B() => IsModelCompatClass(T2IModelClassSorter.CompatFlux2Klein9B);
/// <summary>Returns true if the current model is any Black Forest Labs' Flux.2 variant.</summary>
public bool IsAnyFlux2() => IsFlux2Dev() || IsFlux2Klein4B() || IsFlux2Klein9B();
/// <summary>Returns true if the current model is Ernie Image.</summary>
public bool IsErnie() => IsModelCompatClass(T2IModelClassSorter.CompatErnieImage);
/// <summary>Returns true if the current model is AuraFlow.</summary>
public bool IsAuraFlow() => IsModelCompatClass(T2IModelClassSorter.CompatAuraFlow);
/// <summary>Returns true if the current model is Anima.</summary>
public bool IsAnima() => IsModelCompatClass(T2IModelClassSorter.CompatAnima);
/// <summary>Returns true if the current model is a Kontext model (eg Flux.1 Kontext Dev).</summary>
public bool IsKontext()
{
string clazz = CurrentModelClass()?.ID;
return clazz is not null && clazz.EndsWith("/kontext");
}
/// <summary>Returns true if the current model is Chroma.</summary>
public bool IsChroma() => IsModelCompatClass(T2IModelClassSorter.CompatChroma);
/// <summary>Returns true if the current model is Chroma Radiance.</summary>
public bool IsChromaRadiance() => IsModelCompatClass(T2IModelClassSorter.CompatChromaRadiance);
/// <summary>Returns true if the current model is HiDream-i1.</summary>
public bool IsHiDream() => IsModelCompatClass(T2IModelClassSorter.CompatHiDreamI1);
/// <summary>Returns true if the current model is HiDream-O1 Image.</summary>
public bool IsHiDreamO1() => IsModelCompatClass(T2IModelClassSorter.CompatHiDreamO1);
/// <summary>Returns true if the current model is Lens.</summary>
public bool IsLens() => IsModelCompatClass(T2IModelClassSorter.CompatLens);
/// <summary>Returns true if the current model supports Flux Guidance.</summary>
public bool HasFluxGuidance()
{
return (IsFlux() && CurrentModelClass()?.ID != "Flux.1-schnell") || IsAnyFlux2() || IsHunyuanVideo();
}
/// <summary>Returns true if the current model is NVIDIA Sana.</summary>
public bool IsSana() => IsModelCompatClass(T2IModelClassSorter.CompatSana);
/// <summary>Returns true if the current model is Alpha-VLLM's Lumina 2.</summary>
public bool IsLumina() => IsModelCompatClass(T2IModelClassSorter.CompatLumina2);
/// <summary>Returns true if the current model is a Z-Image model.</summary>
public bool IsZImage() => IsModelCompatClass(T2IModelClassSorter.CompatZImage);
/// <summary>Returns true if the current model is a Zeta Chroma model.</summary>
public bool IsZetaChroma() => IsModelCompatClass(T2IModelClassSorter.CompatZetaChroma);
/// <summary>Returns true if the current model is an Ovis model.</summary>
public bool IsOvis() => IsModelCompatClass(T2IModelClassSorter.CompatOvis);
/// <summary>Returns true if the current model is a Longcat Image model.</summary>
public bool IsLongcatImage() => IsModelCompatClass(T2IModelClassSorter.CompatLongcatImage);
/// <summary>Returns true if the current model is OmniGen.</summary>
public bool IsOmniGen()
{
string clazz = CurrentCompatClass();
return clazz is not null && clazz.StartsWith("omnigen-");
}
/// <summary>Returns true if the current model is Qwen Image.</summary>
public bool IsQwenImage()
{
string clazz = CurrentCompatClass();
return clazz is not null && clazz.StartsWith("qwen-image");
}
/// <summary>Returns true if the current model is Qwen Image Edit.</summary>
public bool IsQwenImageEdit()
{
string clazz = CurrentModelClass()?.ID;
return clazz is not null && clazz.StartsWith("qwen-image-edit");
}
/// <summary>Returns true if the current model is Qwen Image Edit Plus.</summary>
public bool IsQwenImageEditPlus()
{
string clazz = CurrentModelClass()?.ID;
return clazz is not null && clazz.StartsWith("qwen-image-edit-plus");
}
/// <summary>Returns true if the current model is Hunyuan Video (original / v1).</summary>
public bool IsHunyuanVideo() => IsModelCompatClass(T2IModelClassSorter.CompatHunyuanVideo);
/// <summary>Returns true if the current model is Hunyuan Video 1.5.</summary>
public bool IsHunyuanVideo15() => IsModelCompatClass(T2IModelClassSorter.CompatHunyuanVideo1_5);
/// <summary>Returns true if the current model is Hunyuan Video 1.5 SuperResolution.</summary>
public bool IsHunyuanVideo15SR()
{
string clazz = CurrentModelClass()?.ID;
return clazz is not null && clazz.StartsWith("hunyuan-video-1_5-sr");
}
/// <summary>Returns true if the current model is Hunyuan Image 2.1 Base.</summary>
public bool IsHunyuanImage() => IsModelCompatClass(T2IModelClassSorter.CompatHunyuanImage2_1);
/// <summary>Returns true if the current model is Hunyuan Image 2.1 Refiner.</summary>
public bool IsHunyuanImageRefiner() => IsModelCompatClass(T2IModelClassSorter.CompatHunyuanImage2_1Refiner);
/// <summary>Returns true if the current model is Hunyuan Video Image2Video.</summary>
public bool IsHunyuanVideoI2V()
{
string clazz = CurrentModelClass()?.ID;
return clazz is not null && (clazz == "hunyuan-video-i2v" || clazz == "hunyuan-video-i2v-v2");
}
/// <summary>Returns true if the current model is Hunyuan Video - Skyreels.</summary>
public bool IsHunyuanVideoSkyreels()
{
string clazz = CurrentModelClass()?.ID;
return clazz is not null && (clazz == "hunyuan-video-skyreels" || clazz == "hunyuan-video-skyreels-i2v");
}
/// <summary>Returns true if the current model is Nvidia Cosmos v1.</summary>
public bool IsNvidiaCosmos1() => IsModelCompatClass(T2IModelClassSorter.CompatCosmos);
/// <summary>Returns true if the current model is Nvidia Cosmos v2.</summary>
public bool IsNvidiaCosmos2()
{
string clazz = CurrentCompatClass();
return clazz is not null && clazz.StartsWith("nvidia-cosmos-predict2");
}
/// <summary>Returns true if the current model is Kandinsky 5 Image Lite.</summary>
public bool IsKandinsky5ImgLite() => IsModelCompatClass(T2IModelClassSorter.CompatKandinsky5ImgLite);
/// <summary>Returns true if the current model is Kandinsky 5 Video Lite.</summary>
public bool IsKandinsky5VidLite() => IsModelCompatClass(T2IModelClassSorter.CompatKandinsky5VidLite);
/// <summary>Returns true if the current model is Kandinsky 5 Video Pro.</summary>
public bool IsKandinsky5VidPro() => IsModelCompatClass(T2IModelClassSorter.CompatKandinsky5VidPro);
/// <summary>Returns true if the current model is any Kandinsky 5 variant.</summary>
public bool IsKandinsky5() => IsKandinsky5ImgLite() || IsKandinsky5VidLite() || IsKandinsky5VidPro();
/// <summary>Returns true if the current model is any Wan-2.1 variant.</summary>
public bool IsWanVideo()
{
string clazz = CurrentCompatClass();
return clazz is not null && clazz.StartsWith("wan-21");
}
/// <summary>Returns true if the current model is any Wan-2.2 variant.</summary>
public bool IsWanVideo22()
{
string clazz = CurrentCompatClass();
return clazz is not null && clazz.StartsWith("wan-22");
}
/// <summary>Returns true if the current model is any Wan-2.1 VACE variant.</summary>
public bool IsWanVace()
{
string clazz = CurrentModelClass()?.ID;
return clazz is not null && clazz.StartsWith("wan-2_1-vace-");
}
/// <summary>Returns true if the current model is any Wan variant.</summary>
public bool IsAnyWanModel()
{
return IsWanVideo() || IsWanVideo22();
}
/// <summary>Returns true if the current main text input model model is a Video model (as opposed to image).</summary>
public bool IsVideoModel()
{
return IsLTXV() || IsLTXV2() || IsMochi() || IsHunyuanVideo() || IsHunyuanVideo15() || IsNvidiaCosmos1() || IsAnyWanModel() || IsKandinsky5VidLite() || IsKandinsky5VidPro();
}
/// <summary>Returns true if the current model is Ace Step 1.5.</summary>
public bool IsAceStep15()
{
return IsModelCompatClass(T2IModelClassSorter.CompatAceStep15);
}
/// <summary>Returns true if the current model primarily operates on audio.</summary>
public bool IsAudioModel()
{
return CurrentCompat()?.IsAudioModel ?? false;
}
/// <summary>Creates an Empty Latent Image node.</summary>
public string CreateEmptyImage(int width, int height, int batchSize, string id = null)
{
return EmptyImage(width, height, batchSize, id).Path[0].ToString();
}
/// <summary>Creates an Empty Latent Image node.</summary>
public WGNodeData EmptyImage(int width, int height, int batchSize, string id = null)
{
if (EmptyImageCreators.TryGetValue(CurrentModelClass()?.ID ?? "", out Func<int, int, int, string, WGNodeData> creator))
{
return creator(width, height, batchSize, id);
}
WGNodeData resultImage(string node) => new([node, 0], this, WGNodeData.DT_LATENT_IMAGE, CurrentCompat()) { Width = width, Height = height };
WGNodeData resultVideo(string node, int frames) => new([node, 0], this, WGNodeData.DT_LATENT_VIDEO, CurrentCompat()) { Width = width, Height = height, Frames = frames };
WGNodeData resultAudio(string node) => new([node, 0], this, WGNodeData.DT_LATENT_AUDIO, CurrentCompat());
if (IsCascade())
{
return resultImage(CreateNode("StableCascade_EmptyLatentImage", new JObject()
{
["batch_size"] = batchSize,
["compression"] = UserInput.Get(T2IParamTypes.CascadeLatentCompression, 32),
["height"] = height,
["width"] = width
}, id));
}
else if (IsAnyFlux2() || IsErnie() || IsLens())
{
return resultImage(CreateNode("EmptyFlux2LatentImage", new JObject()
{
["batch_size"] = batchSize,
["height"] = height,
["width"] = width
}, id));
}
else if (IsSD3() || IsFlux() || IsHiDream() || IsChroma() || IsOmniGen() || IsQwenImage() || IsZImage() || IsOvis() || IsKandinsky5ImgLite() || IsAnima() || IsLongcatImage())
{
return resultImage(CreateNode("EmptySD3LatentImage", new JObject()
{
["batch_size"] = batchSize,
["height"] = height,
["width"] = width
}, id));
}
else if (IsHunyuanImage() || IsHunyuanImageRefiner())
{
return resultImage(CreateNode("EmptyHunyuanImageLatent", new JObject()
{
["batch_size"] = batchSize,
["height"] = height,
["width"] = width
}, id));
}
else if (IsSana())
{
return resultImage(CreateNode("EmptySanaLatentImage", new JObject()
{
["batch_size"] = batchSize,
["height"] = height,
["width"] = width
}, id));
}
else if (IsMochi())
{
int frames = UserInput.Get(T2IParamTypes.Text2VideoFrames, 25);
return resultVideo(CreateNode("EmptyMochiLatentVideo", new JObject()
{
["batch_size"] = batchSize,
["length"] = frames,
["height"] = height,
["width"] = width
}, id), frames);
}
else if (IsLTXV())
{
int frames = UserInput.Get(T2IParamTypes.Text2VideoFrames, 97);
return resultVideo(CreateNode("EmptyLTXVLatentVideo", new JObject()
{
["batch_size"] = batchSize,
["length"] = frames,
["height"] = height,
["width"] = width
}, id), frames);
}
else if (IsLTXV2())
{
int frames = UserInput.Get(T2IParamTypes.Text2VideoFrames, 97);
int fps = UserInput.Get(T2IParamTypes.VideoFPS, 24);
string emptyVideo = CreateNode("EmptyLTXVLatentVideo", new JObject()
{
["batch_size"] = batchSize,
["length"] = frames,
["height"] = height,
["width"] = width
}, id);
return new([emptyVideo, 0], this, WGNodeData.DT_LATENT_VIDEO, CurrentCompat()) { Width = width, Height = height, Frames = frames, FPS = fps };
}
else if (IsAceStep15())
{
return resultAudio(CreateNode("EmptyAceStep1.5LatentAudio", new JObject()
{
["batch_size"] = batchSize,
["seconds"] = UserInput.Get(T2IParamTypes.Text2AudioDuration, 120)
}, id));
}
else if (IsWanVideo22())
{
int frames = UserInput.Get(T2IParamTypes.Text2VideoFrames, 81);
return resultVideo(CreateNode("Wan22ImageToVideoLatent", new JObject()
{
["batch_size"] = batchSize,
["length"] = frames,
["height"] = height,
["width"] = width,
["vae"] = CurrentVae.Path
}, id), frames);
}
else if (IsHunyuanVideo15())
{
int frames = UserInput.Get(T2IParamTypes.Text2VideoFrames, 73);
return resultVideo(CreateNode("EmptyHunyuanVideo15Latent", new JObject()
{
["batch_size"] = batchSize,
["length"] = frames,
["height"] = height,
["width"] = width
}, id), frames);
}
else if (IsHunyuanVideo() || IsWanVideo() || IsKandinsky5VidLite() || IsKandinsky5VidPro())
{
int frames = 73;
if (IsWanVideo())
{
frames = 81;
}
frames = IsKandinsky5ImgLite() ? 1 : UserInput.Get(T2IParamTypes.Text2VideoFrames, frames);
return resultVideo(CreateNode("EmptyHunyuanLatentVideo", new JObject()
{
["batch_size"] = batchSize,
["length"] = frames,
["height"] = height,
["width"] = width
}, id), frames);
}
else if (IsNvidiaCosmos1())
{
int frames = UserInput.Get(T2IParamTypes.Text2VideoFrames, 121);
return resultVideo(CreateNode("EmptyCosmosLatentVideo", new JObject()
{
["batch_size"] = batchSize,
["length"] = frames,
["height"] = height,
["width"] = width
}, id), frames);
}
else if (IsChromaRadiance() || IsZetaChroma())
{
return resultImage(CreateNode("EmptyChromaRadianceLatentImage", new JObject()
{
["batch_size"] = batchSize,
["height"] = height,
["width"] = width
}, id));
}
else if (IsHiDreamO1())
{
return resultImage(CreateNode("EmptyHiDreamO1LatentImage", new JObject()
{
["batch_size"] = batchSize,
["height"] = height,
["width"] = width
}, id));
}
else if (UserInput.Get(ComfyUIBackendExtension.ShiftedLatentAverageInit, false))
{
double offA = 0, offB = 0, offC = 0, offD = 0;
switch (FinalLoadedModel.ModelClass?.CompatClass?.ID)
{
case "stable-diffusion-v1": // https://github.com/Birch-san/sdxl-diffusion-decoder/blob/4ba89847c02db070b766969c0eca3686a1e7512e/script/inference_decoder.py#L112
case "stable-diffusion-v2":
offA = 2.1335;
offB = 0.1237;
offC = 0.4052;
offD = -0.0940;
break;
case "stable-diffusion-xl-v1": // https://huggingface.co/datasets/Birchlabs/sdxl-latents-ffhq
offA = -2.8982;
offB = -0.9609;
offC = 0.2416;
offD = -0.3074;
break;
}
return resultImage(CreateNode("SwarmOffsetEmptyLatentImage", new JObject()
{
["batch_size"] = batchSize,
["height"] = height,
["width"] = width,
["off_a"] = offA,
["off_b"] = offB,
["off_c"] = offC,
["off_d"] = offD
}, id));
}
else
{
return resultImage(CreateNode("EmptyLatentImage", new JObject()
{
["batch_size"] = batchSize,
["height"] = height,
["width"] = width
}, id));
}
}
public class ModelLoadHelpers(WorkflowGenerator g)
{
public void DoVaeLoader(string defaultVal, T2IModelCompatClass compatClass, string knownName)
{
DoVaeLoader(defaultVal, compatClass?.ID, knownName);
}
public void DoVaeLoader(string defaultVal, string compatClass, string knownName)
{
string vaeFile = defaultVal;
string nodeId = null;
CommonModels.ModelInfo knownFile = knownName is null ? null : CommonModels.Known[knownName];
if (!g.NoVAEOverride && g.UserInput.TryGet(T2IParamTypes.VAE, out T2IModel vaeModel))
{
vaeFile = vaeModel.Name;
nodeId = "11";
}
if (vaeFile == "None")
{
vaeFile = null;
}
if (string.IsNullOrWhiteSpace(vaeFile) && knownFile is not null && Program.T2IModelSets["VAE"].Models.ContainsKey(knownFile.FileName))
{
vaeFile = knownFile.FileName;
}
if (string.IsNullOrWhiteSpace(vaeFile))
{
vaeModel = compatClass is null ? null : Program.T2IModelSets["VAE"].Models.Values.FirstOrDefault(m => m.ModelClass?.CompatClass?.ID == compatClass);
if (vaeModel is not null)
{
Logs.Debug($"Auto-selected first available VAE of compat class '{compatClass}', VAE '{vaeModel.Name}' will be applied");
vaeFile = vaeModel.Name;
}
}
if (string.IsNullOrWhiteSpace(vaeFile))
{
if (knownFile is null)
{
throw new SwarmUserErrorException("No default VAE for this model found, please download its VAE and set it as default in User Settings");
}
vaeFile = knownFile.FileName;
knownFile.DownloadNow().Wait();
Program.RefreshAllModelSets();
}
g.LoadingVAE = g.CreateVAELoader(vaeFile, nodeId);
}
public void AudioVaeLoad(string ckpt)
{
string avaeLoader = g.CreateNode("LTXVAudioVAELoader", new JObject()
{
["ckpt_name"] = ckpt
});
g.CurrentAudioVae = new WGNodeData([avaeLoader, 0], g, WGNodeData.DT_AUDIOVAE, g.CurrentCompat());
}
public string RequireClipModel(string name, string url, string hash, T2IRegisteredParam<T2IModel> param)
{
if (param is not null && g.UserInput.TryGet(param, out T2IModel model))
{
return model.Name;
}
if (ClipModelsValid.ContainsKey(name))
{
return name;
}
if (Program.T2IModelSets["Clip"].Models.ContainsKey(name))
{
ClipModelsValid.TryAdd(name, name);
return name;
}
string filePath = $"{Program.T2IModelSets["Clip"].DownloadFolderPath}/{name}";
g.DownloadModel(name, filePath, url, hash);
ClipModelsValid.TryAdd(name, name);
return name;
}
public string GetT5XXLModel()
{
return RequireClipModel("t5xxl_enconly.safetensors", "https://huggingface.co/mcmonkey/google_t5-v1_1-xxl_encoderonly/resolve/main/t5xxl_fp8_e4m3fn.safetensors", "7d330da4816157540d6bb7838bf63a0f02f573fc48ca4d8de34bb0cbfd514f09", T2IParamTypes.T5XXLModel);
}
public string GetOldT5XXLModel()
{
return RequireClipModel("old_t5xxl_cosmos.safetensors", "https://huggingface.co/comfyanonymous/cosmos_1.0_text_encoder_and_VAE_ComfyUI/resolve/main/text_encoders/oldt5_xxl_fp8_e4m3fn_scaled.safetensors", "1d0dd711ec9866173d4b39e86db3f45e1614a4e3f84919556f854f773352ea81", T2IParamTypes.T5XXLModel);
}
public string GetUniMaxT5XXLModel()
{
return RequireClipModel("umt5_xxl_fp8_e4m3fn_scaled.safetensors", "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/text_encoders/umt5_xxl_fp8_e4m3fn_scaled.safetensors", "c3355d30191f1f066b26d93fba017ae9809dce6c627dda5f6a66eaa651204f68", T2IParamTypes.T5XXLModel);
}
public string GetByT5SmallGlyphxl_tenc()
{
return RequireClipModel("byt5_small_glyphxl_fp16.safetensors", "https://huggingface.co/Comfy-Org/HunyuanImage_2.1_ComfyUI/resolve/main/split_files/text_encoders/byt5_small_glyphxl_fp16.safetensors", "516910bb4c9b225370290e40585d1b0e6c8cd3583690f7eec2f7fb593990fb48", T2IParamTypes.T5XXLModel);
}
public string GetPileT5XLAuraFlow()
{
return RequireClipModel("pile_t5xl_auraflow.safetensors", "https://huggingface.co/fal/AuraFlow-v0.2/resolve/main/text_encoder/model.safetensors", "0a07449cf1141c0ec86e653c00465f6f0d79c6e58a2c60c8bcf4203d0e4ec4f6", T2IParamTypes.T5XXLModel);
}
public string GetOmniQwenModel()
{
return RequireClipModel("qwen_2.5_vl_fp16.safetensors", "https://huggingface.co/Comfy-Org/Omnigen2_ComfyUI_repackaged/resolve/main/split_files/text_encoders/qwen_2.5_vl_fp16.safetensors", "ba05dd266ad6a6aa90f7b2936e4e775d801fb233540585b43933647f8bc4fbc3", T2IParamTypes.QwenModel);
}
public string GetQwenImage25_7b_tenc()
{
return RequireClipModel("qwen_2.5_vl_7b_fp8_scaled.safetensors", "https://huggingface.co/Comfy-Org/Qwen-Image_ComfyUI/resolve/main/split_files/text_encoders/qwen_2.5_vl_7b_fp8_scaled.safetensors", "cb5636d852a0ea6a9075ab1bef496c0db7aef13c02350571e388aea959c5c0b4", T2IParamTypes.QwenModel);
}
public string GetQwen3_600mModel()
{
return RequireClipModel("qwen_3_600m.safetensors", "https://huggingface.co/circlestone-labs/Anima/resolve/main/split_files/text_encoders/qwen_3_06b_base.safetensors", "cd2a512003e2f9f3cd3c32a9c3573f820bb28c940f73c57b1ddaa983d9223eba", T2IParamTypes.QwenModel);
}
public string GetQwen3_4bModel()
{
return RequireClipModel("qwen_3_4b.safetensors", "https://huggingface.co/Comfy-Org/z_image_turbo/resolve/main/split_files/text_encoders/qwen_3_4b_fp8_mixed.safetensors", "72450b19758172c5a7273cf7de729d1c17e7f434a104a00167624cba94f68f15", T2IParamTypes.QwenModel);
}
public string GetQwen3_8bModel()
{
return RequireClipModel("qwen_3_8b.safetensors", "https://huggingface.co/Comfy-Org/flux2-klein-9B/resolve/main/split_files/text_encoders/qwen_3_8b_fp4mixed.safetensors", "bbf16f981d98e16d080c566134814c4e9f6aadd0d0e1383c60bc44ba939d760d", T2IParamTypes.QwenModel);
}
public string GetOvisQwenModel()
{
return RequireClipModel("ovis_2.5.safetensors", "https://huggingface.co/Comfy-Org/Ovis-Image/resolve/main/split_files/text_encoders/ovis_2.5.safetensors", "f453ee5e7a25cb23cf2adf7aae3e5b405f22097cb67f2cfcca029688cb3f740d", T2IParamTypes.QwenModel);
}
public string GetMistralFlux2Model()
{
return RequireClipModel("mistral_3_small_flux2.safetensors", "https://huggingface.co/Comfy-Org/flux2-dev/resolve/main/split_files/text_encoders/mistral_3_small_flux2_fp4_mixed.safetensors", "1ee1ff334d78228d73049ef0ee4fcd21c1700536b5a45c06547af057f92463a7", T2IParamTypes.MistralModel);
}
public string GetMinistral3_3bModel()
{
return RequireClipModel("ministral-3-3b.safetensors", "https://huggingface.co/Comfy-Org/ERNIE-Image/resolve/main/text_encoders/ministral-3-3b.safetensors", "49a750a128863854eac7d85e1a277a7b44bf6ec3646405b84686dfeeca3708ca", T2IParamTypes.MistralModel);
}
public string GetGptOss_20bModel()
{
return RequireClipModel("gpt_oss_20b_nvfp4.safetensors", "https://huggingface.co/Comfy-Org/Lens/resolve/main/text_encoders/gpt_oss_20b_nvfp4.safetensors", "103d7759c720627e5ffdcb0d885595695085dad4201fa6a522a84d4b86335ca0", T2IParamTypes.GptOssModel);
}
public string GetClipLModel()
{
if (g.UserInput.TryGet(T2IParamTypes.ClipLModel, out T2IModel model))
{
return model.Name;
}
if (Program.T2IModelSets["Clip"].Models.ContainsKey("clip_l_sdxl_base.safetensors"))
{
return "clip_l_sdxl_base.safetensors";
}
return RequireClipModel("clip_l.safetensors", "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/text_encoder/model.fp16.safetensors", "660c6f5b1abae9dc498ac2d21e1347d2abdb0cf6c0c0c8576cd796491d9a6cdd", T2IParamTypes.ClipLModel);
}
public string GetClipGModel()
{
if (g.UserInput.TryGet(T2IParamTypes.ClipGModel, out T2IModel model))
{
return model.Name;
}
if (Program.T2IModelSets["Clip"].Models.ContainsKey("clip_g_sdxl_base.safetensors"))
{
return "clip_g_sdxl_base.safetensors";
}
return RequireClipModel("clip_g.safetensors", "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/text_encoder_2/model.fp16.safetensors", "ec310df2af79c318e24d20511b601a591ca8cd4f1fce1d8dff822a356bcdb1f4", T2IParamTypes.ClipGModel);
}
public string GetHiDreamClipLModel()
{
return RequireClipModel("long_clip_l_hi_dream.safetensors", "https://huggingface.co/Comfy-Org/HiDream-I1_ComfyUI/resolve/main/split_files/text_encoders/clip_l_hidream.safetensors", "706fdb88e22e18177b207837c02f4b86a652abca0302821f2bfa24ac6aea4f71", T2IParamTypes.ClipLModel);
}
public string GetHiDreamClipGModel()
{
return RequireClipModel("long_clip_g_hi_dream.safetensors", "https://huggingface.co/Comfy-Org/HiDream-I1_ComfyUI/resolve/main/split_files/text_encoders/clip_g_hidream.safetensors", "3771e70e36450e5199f30bad61a53faae85a2e02606974bcda0a6a573c0519d5", T2IParamTypes.ClipGModel);
}
public string GetLlava3Model()
{
return RequireClipModel("llava_llama3_fp8_scaled.safetensors", "https://huggingface.co/Comfy-Org/HunyuanVideo_repackaged/resolve/main/split_files/text_encoders/llava_llama3_fp8_scaled.safetensors", "2f0c3ad255c282cead3f078753af37d19099cafcfc8265bbbd511f133e7af250", T2IParamTypes.LLaVAModel);
}
public string GetLlama31_8b_Model()
{
return RequireClipModel("llama_3.1_8b_instruct_fp8_scaled.safetensors", "https://huggingface.co/Comfy-Org/HiDream-I1_ComfyUI/resolve/main/split_files/text_encoders/llama_3.1_8b_instruct_fp8_scaled.safetensors", "9f86897bbeb933ef4fd06297740edb8dd962c94efcd92b373a11460c33765ea6", T2IParamTypes.LLaMAModel);
}
public string GetGemma2Model()
{
return RequireClipModel("gemma_2_2b_fp16.safetensors", "https://huggingface.co/Comfy-Org/Lumina_Image_2.0_Repackaged/resolve/main/split_files/text_encoders/gemma_2_2b_fp16.safetensors", "29761442862f8d064d3f854bb6fabf4379dcff511a7f6ba9405a00bd0f7e2dbd", T2IParamTypes.GemmaModel);
}
public string GetGemma3_12bModel()
{
return RequireClipModel("gemma_3_12B_it.safetensors", "https://huggingface.co/Comfy-Org/ltx-2/resolve/main/split_files/text_encoders/gemma_3_12B_it_fp4_mixed.safetensors", "aaca463d11e6d8d2a4bdb0d6299214c15ef78a3f73e0ef8113d5a9d0219b3f6d", T2IParamTypes.GemmaModel);
}
public string GetLTX2EmbedClip()
{
// TODO: This is cursed and wrong.
return RequireClipModel("ltx2/ltx2-embeddings-connector-distill.safetensors", "https://huggingface.co/Kijai/LTXV2_comfy/resolve/main/text_encoders/ltx-2-19b-embeddings_connector_distill_bf16.safetensors", "8990ec3fe88396ca33ac1795c89b1771d88190e51e24084b21f54b25399acbed", null);
}
public void LoadClip(string type, string model)
{
string loaderType = "CLIPLoader";
if (model.EndsWith(".gguf"))
{
loaderType = "CLIPLoaderGGUF";
}
string singleClipLoader = g.CreateNode(loaderType, new JObject()
{
["clip_name"] = model,
["type"] = type,
["device"] = "default"
});
g.LoadingClip = [singleClipLoader, 0];
}
public void LoadClipAudio(string model, string ckpt)
{
string loaderType = "LTXAVTextEncoderLoader";
string clipLoader = g.CreateNode(loaderType, new JObject()
{
["text_encoder"] = model,
["ckpt_name"] = ckpt
});
g.LoadingClip = [clipLoader, 0];
}
public void LoadClip2(string type, string modelA, string modelB)
{
string loaderType = "DualCLIPLoader";
if (modelA.EndsWith(".gguf") || modelB.EndsWith(".gguf"))
{
loaderType = "DualCLIPLoaderGGUF";
}
string dualClipLoader = g.CreateNode(loaderType, new JObject()
{
["clip_name1"] = modelA,
["clip_name2"] = modelB,
["type"] = type,
["device"] = "default"
});
g.LoadingClip = [dualClipLoader, 0];
}
public void LoadClip3(string type, string modelA, string modelB, string modelC)
{
string loaderType = "TripleCLIPLoader";
if (modelA.EndsWith(".gguf") || modelB.EndsWith(".gguf") || modelC.EndsWith(".gguf"))
{
loaderType = "TripleCLIPLoaderGGUF";
}
string tripleClipLoader = g.CreateNode(loaderType, new JObject()
{
["clip_name1"] = modelA,
["clip_name2"] = modelB,
["clip_name3"] = modelC,
//["type"] = type // not currently used as only SD3 has triple thus far
});
g.LoadingClip = [tripleClipLoader, 0];
}
}
/// <summary>Creates a model loader and adapts it with any registered model adapters, and returns (Model, Clip, VAE).</summary>
[Obsolete("Use CreateModelLoader instead")]
public (T2IModel, JArray, JArray, JArray) CreateStandardModelLoader(T2IModel model, string type, string id = null, bool noCascadeFix = false, int sectionId = 0)
{
(T2IModel modelObj, WGNodeData modelNode, WGNodeData tencNode, WGNodeData vaeNode) = CreateModelLoader(model, type, id, noCascadeFix, sectionId);
return (modelObj, modelNode?.Path, tencNode?.Path, vaeNode?.Path);
}
/// <summary>Creates a model loader and adapts it with any registered model adapters, and returns (Model, Clip, VAE).</summary>
public (T2IModel, WGNodeData, WGNodeData, WGNodeData) CreateModelLoader(T2IModel model, string type, string id = null, bool noCascadeFix = false, int sectionId = 0)
{
ModelLoadHelpers helpers = new(this);
string helper = $"modelloader_{model.Name}_{type}";
if (NodeHelpers.TryGetValue(helper, out string alreadyLoaded))
{
string[] parts = alreadyLoaded.SplitFast(':');
LoadingModel = [parts[0], int.Parse(parts[1])];
LoadingClip = parts[2].Length == 0 ? null : [parts[2], int.Parse(parts[3])];
LoadingVAE = parts[4].Length == 0 ? null : [parts[4], int.Parse(parts[5])];
WGNodeData modelNode = new(LoadingModel, this, WGNodeData.DT_MODEL, CurrentCompat());
WGNodeData tencNode = LoadingClip is null ? null : new WGNodeData(LoadingClip, this, WGNodeData.DT_TEXTENC, CurrentCompat());
WGNodeData vaeNode = LoadingVAE is null ? null : new WGNodeData(LoadingVAE, this, WGNodeData.DT_VAE, CurrentCompat());
return (model, modelNode, tencNode, vaeNode);
}
IsDifferentialDiffusion = false;
LoadingModelType = type;
if (!noCascadeFix && model.ModelClass?.ID == "stable-cascade-v1-stage-b" && model.Name.Contains("stage_b") && Program.MainSDModels.Models.TryGetValue(model.Name.Replace("stage_b", "stage_c"), out T2IModel altCascadeModel))
{
model = altCascadeModel;
}
LoadingModel = null;
foreach (WorkflowGenStep step in ModelGenSteps.Where(s => s.Priority <= -100))
{
step.Action(this);
}
if (LoadingModel is not null)
{
// Custom action has loaded it for us.
}
else if (model.ModelClass?.ID.EndsWith("/tensorrt") ?? false)
{
string baseArch = model.ModelClass?.ID?.Before('/');
string trtType = ComfyUIWebAPI.ArchitecturesTRTCompat[baseArch];
string trtloader = CreateNode("TensorRTLoader", new JObject()
{
["unet_name"] = model.ToString(ModelFolderFormat),
["model_type"] = trtType
}, id, false);
LoadingModel = [trtloader, 0];
// TODO: This is a hack
T2IModel[] sameArch = [.. Program.MainSDModels.Models.Values.Where(m => m.ModelClass?.ID == baseArch)];
if (sameArch.Length == 0)
{
throw new SwarmUserErrorException($"No models found with architecture {baseArch}, cannot load CLIP/VAE for this Arch");
}
T2IModel matchedName = sameArch.FirstOrDefault(m => m.Name.Before('.') == model.Name.Before('.'));
matchedName ??= sameArch.First();
string secondaryNode = CreateNode("CheckpointLoaderSimple", new JObject()
{
["ckpt_name"] = matchedName.ToString(ModelFolderFormat)
});
LoadingClip = [secondaryNode, 1];
LoadingVAE = [secondaryNode, 2];
}
else if (model.Name.EndsWith(".engine"))
{
throw new SwarmUserErrorException($"Model {model.Name} appears to be TensorRT lacks metadata to identify its architecture, cannot load");
}
else if (model.ModelClass?.CompatClass?.ID == "pixart-ms-sigma-xl-2")
{
string pixartNode = CreateNode("PixArtCheckpointLoader", new JObject()
{
["ckpt_name"] = model.ToString(ModelFolderFormat),
["model"] = model.ModelClass.ID == "pixart-ms-sigma-xl-2-2k" ? "PixArtMS_Sigma_XL_2_2K" : "PixArtMS_Sigma_XL_2"
}, id, false);
LoadingModel = [pixartNode, 0];
string singleClipLoader = CreateNode("CLIPLoader", new JObject()
{
["clip_name"] = helpers.GetT5XXLModel(),
["type"] = "sd3"
});
LoadingClip = [singleClipLoader, 0];
helpers.DoVaeLoader(UserInput.SourceSession?.User?.Settings?.VAEs?.DefaultSDXLVAE, "stable-diffusion-xl-v1", "sdxl-vae");
}
else if (model.IsDiffusionModelsFormat)
{
if (model.Metadata?.SpecialFormat == "gguf")
{
if (!Features.Contains("gguf"))
{
throw new SwarmUserErrorException($"Model '{model.Name}' is in GGUF format, but the server does not have GGUF support installed. Cannot run.");
}
string modelNode = CreateNode("UnetLoaderGGUF", new JObject()
{
["unet_name"] = model.ToString(ModelFolderFormat)
}, id, false);
LoadingModel = [modelNode, 0];
}
else if (model.Metadata?.SpecialFormat == "nunchaku" || model.Metadata?.SpecialFormat == "nunchaku-fp4")
{
if (!Features.Contains("nunchaku"))
{
throw new SwarmUserErrorException($"Model '{model.Name}' is in Nunchaku format, but the server does not have Nunchaku support installed. Cannot run.");
}
if (IsFlux())
{
// TODO: Configuration of these params?
string modelNode = CreateNode("NunchakuFluxDiTLoader", new JObject()
{
["model_path"] = model.Name.EndsWith("/transformer_blocks.safetensors") ? model.Name.BeforeLast('/').Replace("/", ModelFolderFormat ?? $"{Path.DirectorySeparatorChar}") : model.ToString(ModelFolderFormat),
["cache_threshold"] = UserInput.Get(ComfyUIBackendExtension.NunchakuCacheThreshold, 0, sectionId: sectionId),
["attention"] = "nunchaku-fp16",
["cpu_offload"] = "auto",
["device_id"] = 0,
["data_type"] = model.Metadata?.SpecialFormat == "nunchaku-fp4" ? "bfloat16" : "float16",
["i2f_mode"] = "enabled"
}, id, false);
LoadingModel = [modelNode, 0];
}
else if (IsQwenImage())
{
string modelNode = CreateNode("NunchakuQwenImageDiTLoader", new JObject()
{
["model_name"] = model.Name.EndsWith("/transformer_blocks.safetensors") ? model.Name.BeforeLast('/').Replace("/", ModelFolderFormat ?? $"{Path.DirectorySeparatorChar}") : model.ToString(ModelFolderFormat),
["cpu_offload"] = "auto",
["num_blocks_on_gpu"] = 1, // TODO: If nunchaku doesn't fix automation here, add a param. Also enable cpu_offload if the param is given.
["use_pin_memory"] = "enable"
}, id, false);
LoadingModel = [modelNode, 0];
}
else if (IsZImage())
{
string modelNode = CreateNode("NunchakuZImageDiTLoader", new JObject()
{
["model_name"] = model.ToString(ModelFolderFormat),
}, id, false);
LoadingModel = [modelNode, 0];
}
else
{
throw new SwarmUserErrorException($"Cannot load nunchaku for model architecture '{model.ModelClass?.ID}'. If other model architectures are supported in the Nunchaku source, please report this on the SwarmUI GitHub or Discord.");
}
}
else if (model.Metadata?.SpecialFormat == "bnb_nf4" || model.Metadata?.SpecialFormat == "bnb_fp4")
{
if (!Features.Contains("bnb_nf4"))
{
throw new SwarmUserErrorException($"Model '{model.Name}' is in BitsAndBytes-NF4 format, but the server does not have BNB_NF4 support installed. Cannot run.");
}
string modelNode = CreateNode("UNETLoaderNF4", new JObject()
{
["unet_name"] = model.ToString(ModelFolderFormat),
["bnb_dtype"] = model.Metadata?.SpecialFormat == "bnb_fp4" ? "fp4" : "nf4"
}, id, false);
LoadingModel = [modelNode, 0];
}
else
{
if (model.RawFilePath.EndsWith(".gguf"))
{
Logs.Error($"Model '{model.Name}' likely has corrupt/invalid metadata, and needs to be reset.");
}
string dtype = UserInput.Get(ComfyUIBackendExtension.PreferredDType, "automatic", sectionId: sectionId);
if (dtype == "automatic")
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) // TODO: Or AMD?
{
dtype = "default";
}
else if (model.Metadata?.SpecialFormat == "fp8_scaled")
{
dtype = "default";
}
else if (IsNvidiaCosmos2() || IsOmniGen() || IsChroma() || IsChromaRadiance()) // Obligatory due to model issues
{
dtype = "default";
}
else if (IsZImage() || IsZetaChroma() || IsAnima() || IsLens()) // Model is small and dense, so trust user preferred download format
{
dtype = "default";
}
else if (IsAceStep15()) // ??
{
dtype = "default";
}
else
{
dtype = "fp8_e4m3fn";
if (Utilities.PresumeNVidia30xx && Program.ServerSettings.Performance.AllowGpuSpecificOptimizations && !IsQwenImage())
{
dtype = "fp8_e4m3fn_fast";
}
}
}
string modelNode = CreateNode("UNETLoader", new JObject()
{
["unet_name"] = model.ToString(ModelFolderFormat),
["weight_dtype"] = dtype
}, id, false);
LoadingModel = [modelNode, 0];
}
LoadingClip = null;
LoadingVAE = null;
}
else if (model.Metadata?.SpecialFormat == "bnb_nf4" || model.Metadata?.SpecialFormat == "bnb_fp4")
{
if (!Features.Contains("bnb_nf4"))
{
throw new SwarmUserErrorException($"Model '{model.Name}' is in BitsAndBytes-NF4 format, but the server does not have BNB_NF4 support installed. Cannot run.");
}
string modelNode = CreateNode("CheckpointLoaderNF4", new JObject()
{
["ckpt_name"] = model.ToString(ModelFolderFormat),
["bnb_dtype"] = model.Metadata?.SpecialFormat == "bnb_fp4" ? "fp4" : "nf4"
}, id, false);
LoadingModel = [modelNode, 0];
LoadingClip = [modelNode, 1];
LoadingVAE = [modelNode, 2];
}
else if (IsSana())
{
string sanaNode = CreateNode("SanaCheckpointLoader", new JObject()
{
["ckpt_name"] = model.ToString(ModelFolderFormat),
["model"] = "SanaMS_1600M_P1_D20"
}, id, false);
LoadingModel = [sanaNode, 0];
string clipLoader = CreateNode("GemmaLoader", new JObject()
{
["model_name"] = "unsloth/gemma-2-2b-it-bnb-4bit",
["device"] = "cpu",
["dtype"] = "default"
});
LoadingClip = [clipLoader, 0];
helpers.DoVaeLoader(null, "nvidia-sana-1600", "sana-dcae");
}
else
{
if (model.Metadata?.SpecialFormat == "gguf")
{
throw new SwarmUserErrorException($"Model '{model.Name}' is in GGUF format, but it's in your main Stable-Diffusion models folder. GGUF files are weird, and need to go in the special 'diffusion_models' folder.");
}
if (model.Metadata?.SpecialFormat == "nunchaku" || model.Metadata?.SpecialFormat == "nunchaku-fp4")
{
throw new SwarmUserErrorException($"Model '{model.Name}' is in Nunchaku format, but it's in your main Stable-Diffusion models folder. Nunchaku files are weird, and need to go in the special 'diffusion_models' folder with their own special subfolder.");
}
string modelNode = CreateNode("CheckpointLoaderSimple", new JObject()
{
["ckpt_name"] = model.ToString(ModelFolderFormat)
}, id, false);
LoadingModel = [modelNode, 0];
LoadingClip = [modelNode, 1];
LoadingVAE = [modelNode, 2];
if ((IsFlux() || IsFlux2Dev()) && (model.Metadata?.TextEncoders ?? "") == "")
{
LoadingClip = null;
LoadingVAE = null;
}
}
string predType = UserInput.Get(T2IParamTypes.OverridePredictionType, model.Metadata?.PredictionType, sectionId: sectionId);
if (IsSD3())
{
string sd3Node = CreateNode("ModelSamplingSD3", new JObject()
{
["model"] = LoadingModel,
["shift"] = UserInput.Get(T2IParamTypes.SigmaShift, 3, sectionId: sectionId)
});
LoadingModel = [sd3Node, 0];