forked from ClownsharkBatwing/RES4LYF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sigmas.py
807 lines (654 loc) · 27.3 KB
/
sigmas.py
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
import torch
import numpy as np
from math import *
import builtins
from comfy.k_diffusion.sampling import get_sigmas_polyexponential, get_sigmas_karras
def rescale_linear(input, input_min, input_max, output_min, output_max):
output = ((input - input_min) / (input_max - input_min)) * (output_max - output_min) + output_min;
return output;
class sigmas_concatenate:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas_1": ("SIGMAS", {"forceInput": True}),
"sigmas_2": ("SIGMAS", {"forceInput": True}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas_1, sigmas_2):
return (torch.cat((sigmas_1, sigmas_2)),)
class sigmas_truncate:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
"sigmas_until": ("INT", {"default": 10, "min": 0,"max": 1000,"step": 1}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas, sigmas_until):
return (sigmas[:sigmas_until],)
class sigmas_start:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
"sigmas_until": ("INT", {"default": 10, "min": 0,"max": 1000,"step": 1}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas, sigmas_until):
return (sigmas[sigmas_until:],)
class sigmas_split:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
"sigmas_start": ("INT", {"default": 0, "min": 0,"max": 1000,"step": 1}),
"sigmas_end": ("INT", {"default": 1000, "min": 0,"max": 1000,"step": 1}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas, sigmas_start, sigmas_end):
sigmas_stop_step = sigmas_end - sigmas_start
return (sigmas[sigmas_start:][:sigmas_stop_step],)
class sigmas_pad:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
"value": ("FLOAT", {"default": 0.0, "min": -10000,"max": 10000,"step": 0.01})
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas, value):
return (torch.cat((sigmas, torch.tensor([value]))),)
class sigmas_unpad:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas):
return (sigmas[:-1],)
class sigmas_set_floor:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
"floor": ("FLOAT", {"default": 0.0291675, "min": -10000,"max": 10000,"step": 0.01}),
"new_floor": ("FLOAT", {"default": 0.0291675, "min": -10000,"max": 10000,"step": 0.01})
}
}
RETURN_TYPES = ("SIGMAS",)
FUNCTION = "set_floor"
CATEGORY = "sampling/custom_sampling/sigmas"
def set_floor(self, sigmas, floor, new_floor):
sigmas[sigmas <= floor] = new_floor
return (sigmas,)
class sigmas_delete_below_floor:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
"floor": ("FLOAT", {"default": 0.0291675, "min": -10000,"max": 10000,"step": 0.01})
}
}
RETURN_TYPES = ("SIGMAS",)
FUNCTION = "delete_below_floor"
CATEGORY = "sampling/custom_sampling/sigmas"
def delete_below_floor(self, sigmas, floor):
return (sigmas[sigmas >= floor],)
class sigmas_delete_value:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
"value": ("FLOAT", {"default": 0.0, "min": -1000,"max": 1000,"step": 0.01})
}
}
RETURN_TYPES = ("SIGMAS",)
FUNCTION = "delete_value"
CATEGORY = "sampling/custom_sampling/sigmas"
def delete_value(self, sigmas, value):
return (sigmas[sigmas != value],)
class sigmas_delete_consecutive_duplicates:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas_1": ("SIGMAS", {"forceInput": True})
}
}
RETURN_TYPES = ("SIGMAS",)
FUNCTION = "delete_consecutive_duplicates"
CATEGORY = "sampling/custom_sampling/sigmas"
def delete_consecutive_duplicates(self, sigmas_1):
mask = sigmas_1[:-1] != sigmas_1[1:]
mask = torch.cat((mask, torch.tensor([True])))
return (sigmas_1[mask],)
class sigmas_cleanup:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
"sigmin": ("FLOAT", {"default": 0.0291675, "min": 0,"max": 1000,"step": 0.01})
}
}
RETURN_TYPES = ("SIGMAS",)
FUNCTION = "cleanup"
CATEGORY = "sampling/custom_sampling/sigmas"
def cleanup(self, sigmas, sigmin):
sigmas_culled = sigmas[sigmas >= sigmin]
mask = sigmas_culled[:-1] != sigmas_culled[1:]
mask = torch.cat((mask, torch.tensor([True])))
filtered_sigmas = sigmas_culled[mask]
return (torch.cat((filtered_sigmas,torch.tensor([0]))),)
class sigmas_mult:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
"multiplier": ("FLOAT", {"default": 1, "min": -10000,"max": 10000,"step": 0.01})
},
"optional": {
"sigmas2": ("SIGMAS", {"forceInput": False})
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas, multiplier, sigmas2=None):
if sigmas2 is not None:
return (sigmas * sigmas2 * multiplier,)
else:
return (sigmas * multiplier,)
class sigmas_modulus:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
"divisor": ("FLOAT", {"default": 1, "min": -1000,"max": 1000,"step": 0.01})
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas, divisor):
return (sigmas % divisor,)
class sigmas_quotient:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
"divisor": ("FLOAT", {"default": 1, "min": -1000,"max": 1000,"step": 0.01})
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas, divisor):
return (sigmas // divisor,)
class sigmas_add:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
"addend": ("FLOAT", {"default": 1, "min": -1000,"max": 1000,"step": 0.01})
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas, addend):
return (sigmas + addend,)
class sigmas_power:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True}),
"power": ("FLOAT", {"default": 1, "min": -100,"max": 100,"step": 0.01})
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas, power):
return (sigmas ** power,)
class sigmas_abs:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas": ("SIGMAS", {"forceInput": True})
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas):
return (abs(sigmas),)
class sigmas2_mult:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas_1": ("SIGMAS", {"forceInput": True}),
"sigmas_2": ("SIGMAS", {"forceInput": True}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas_1, sigmas_2):
return (sigmas_1 * sigmas_2,)
class sigmas2_add:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sigmas_1": ("SIGMAS", {"forceInput": True}),
"sigmas_2": ("SIGMAS", {"forceInput": True}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, sigmas_1, sigmas_2):
return (sigmas_1 + sigmas_2,)
class sigmas_math1:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"start": ("INT", {"default": 0, "min": 0,"max": 10000,"step": 1}),
"stop": ("INT", {"default": 0, "min": 0,"max": 10000,"step": 1}),
"trim": ("INT", {"default": 0, "min": -10000,"max": 0,"step": 1}),
"x": ("FLOAT", {"default": 1, "min": -10000,"max": 10000,"step": 0.01}),
"y": ("FLOAT", {"default": 1, "min": -10000,"max": 10000,"step": 0.01}),
"z": ("FLOAT", {"default": 1, "min": -10000,"max": 10000,"step": 0.01}),
"f1": ("STRING", {"default": "s", "multiline": True}),
"rescale" : ("BOOLEAN", {"default": False}),
"max1": ("FLOAT", {"default": 14.614642, "min": -10000,"max": 10000,"step": 0.01}),
"min1": ("FLOAT", {"default": 0.0291675, "min": -10000,"max": 10000,"step": 0.01}),
},
"optional": {
"a": ("SIGMAS", {"forceInput": False}),
"b": ("SIGMAS", {"forceInput": False}),
"c": ("SIGMAS", {"forceInput": False}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, start=0, stop=0, trim=0, a=None, b=None, c=None, x=1.0, y=1.0, z=1.0, f1="s", rescale=False, min1=1.0, max1=1.0):
if stop == 0:
t_lens = [len(tensor) for tensor in [a, b, c] if tensor is not None]
t_len = stop = min(t_lens) if t_lens else 0
else:
stop = stop + 1
t_len = stop - start
stop = stop + trim
t_len = t_len + trim
t_a = t_b = t_c = None
if a is not None:
t_a = a[start:stop]
if b is not None:
t_b = b[start:stop]
if c is not None:
t_c = c[start:stop]
t_s = torch.arange(0.0, t_len)
t_x = torch.full((t_len,), x)
t_y = torch.full((t_len,), y)
t_z = torch.full((t_len,), z)
eval_namespace = {"__builtins__": None, "round": builtins.round, "np": np, "a": t_a, "b": t_b, "c": t_c, "x": t_x, "y": t_y, "z": t_z, "s": t_s, "torch": torch}
eval_namespace.update(np.__dict__)
s_out_1 = eval(f1, eval_namespace)
if rescale == True:
s_out_1 = ((s_out_1 - min(s_out_1)) * (max1 - min1)) / (max(s_out_1) - min(s_out_1)) + min1
return (s_out_1,)
class sigmas_math3:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"start": ("INT", {"default": 0, "min": 0,"max": 10000,"step": 1}),
"stop": ("INT", {"default": 0, "min": 0,"max": 10000,"step": 1}),
"trim": ("INT", {"default": 0, "min": -10000,"max": 0,"step": 1}),
},
"optional": {
"a": ("SIGMAS", {"forceInput": False}),
"b": ("SIGMAS", {"forceInput": False}),
"c": ("SIGMAS", {"forceInput": False}),
"x": ("FLOAT", {"default": 1, "min": -10000,"max": 10000,"step": 0.01}),
"y": ("FLOAT", {"default": 1, "min": -10000,"max": 10000,"step": 0.01}),
"z": ("FLOAT", {"default": 1, "min": -10000,"max": 10000,"step": 0.01}),
"f1": ("STRING", {"default": "s", "multiline": True}),
"max1": ("FLOAT", {"default": 14.614642, "min": -10000,"max": 10000,"step": 0.01}),
"min1": ("FLOAT", {"default": 0.0291675, "min": -10000,"max": 10000,"step": 0.01}),
"f2": ("STRING", {"default": "s", "multiline": True}),
"max2": ("FLOAT", {"default": 14.614642, "min": -10000,"max": 10000,"step": 0.01}),
"min2": ("FLOAT", {"default": 0.0291675, "min": -10000,"max": 10000,"step": 0.01}),
"f3": ("STRING", {"default": "s", "multiline": True}),
"max3": ("FLOAT", {"default": 14.614642, "min": -10000,"max": 10000,"step": 0.01}),
"min3": ("FLOAT", {"default": 0.0291675, "min": -10000,"max": 10000,"step": 0.01}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS","SIGMAS","SIGMAS")
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, start=0, stop=0, trim=0, a=None, b=None, c=None, x=1.0, y=1.0, z=1.0, f1="s", f2="s", f3="s", min1=1.0, max1=1.0, min2=1.0, max2=1.0, min3=1.0, max3=1.0):
if stop == 0:
t_lens = [len(tensor) for tensor in [a, b, c] if tensor is not None]
t_len = stop = min(t_lens) if t_lens else 0
else:
stop = stop + 1
t_len = stop - start
stop = stop + trim
t_len = t_len + trim
t_a = t_b = t_c = None
if a is not None:
t_a = a[start:stop]
if b is not None:
t_b = b[start:stop]
if c is not None:
t_c = c[start:stop]
t_s = torch.arange(0.0, t_len)
t_x = torch.full((t_len,), x)
t_y = torch.full((t_len,), y)
t_z = torch.full((t_len,), z)
eval_namespace = {"__builtins__": None, "np": np, "a": t_a, "b": t_b, "c": t_c, "x": t_x, "y": t_y, "z": t_z, "s": t_s, "torch": torch}
eval_namespace.update(np.__dict__)
s_out_1 = eval(f1, eval_namespace)
s_out_2 = eval(f2, eval_namespace)
s_out_3 = eval(f3, eval_namespace)
scaled_s_out_1 = ((s_out_1 - min(s_out_1)) * (max1 - min1)) / (max(s_out_1) - min(s_out_1)) + min1
scaled_s_out_2 = ((s_out_2 - min(s_out_2)) * (max2 - min2)) / (max(s_out_2) - min(s_out_2)) + min2
scaled_s_out_3 = ((s_out_3 - min(s_out_3)) * (max3 - min3)) / (max(s_out_3) - min(s_out_3)) + min3
return scaled_s_out_1, scaled_s_out_2, scaled_s_out_3
class sigmas_iteration_karras:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"steps_up": ("INT", {"default": 30, "min": 0,"max": 10000,"step": 1}),
"steps_down": ("INT", {"default": 30, "min": 0,"max": 10000,"step": 1}),
"rho_up": ("FLOAT", {"default": 3, "min": -10000,"max": 10000,"step": 0.01}),
"rho_down": ("FLOAT", {"default": 4, "min": -10000,"max": 10000,"step": 0.01}),
"s_min_start": ("FLOAT", {"default":0.0291675, "min": -10000,"max": 10000,"step": 0.01}),
"s_max": ("FLOAT", {"default": 2, "min": -10000,"max": 10000,"step": 0.01}),
"s_min_end": ("FLOAT", {"default": 0.0291675, "min": -10000,"max": 10000,"step": 0.01}),
},
"optional": {
"momentums": ("SIGMAS", {"forceInput": False}),
"sigmas": ("SIGMAS", {"forceInput": False}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS","SIGMAS")
RETURN_NAMES = ("momentums","sigmas")
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, steps_up, steps_down, rho_up, rho_down, s_min_start, s_max, s_min_end, sigmas=None, momentums=None):
s_up = get_sigmas_karras(steps_up, s_min_start, s_max, rho_up)
s_down = get_sigmas_karras(steps_down, s_min_end, s_max, rho_down)
s_up = s_up[:-1]
s_down = s_down[:-1]
s_up = torch.flip(s_up, dims=[0])
sigmas_new = torch.cat((s_up, s_down), dim=0)
momentums_new = torch.cat((s_up, -1*s_down), dim=0)
if sigmas is not None:
sigmas = torch.cat([sigmas, sigmas_new])
else:
sigmas = sigmas_new
if momentums is not None:
momentums = torch.cat([momentums, momentums_new])
else:
momentums = momentums_new
return (momentums,sigmas)
class sigmas_iteration_polyexp:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"steps_up": ("INT", {"default": 30, "min": 0,"max": 10000,"step": 1}),
"steps_down": ("INT", {"default": 30, "min": 0,"max": 10000,"step": 1}),
"rho_up": ("FLOAT", {"default": 0.6, "min": -10000,"max": 10000,"step": 0.01}),
"rho_down": ("FLOAT", {"default": 0.8, "min": -10000,"max": 10000,"step": 0.01}),
"s_min_start": ("FLOAT", {"default":0.0291675, "min": -10000,"max": 10000,"step": 0.01}),
"s_max": ("FLOAT", {"default": 2, "min": -10000,"max": 10000,"step": 0.01}),
"s_min_end": ("FLOAT", {"default": 0.0291675, "min": -10000,"max": 10000,"step": 0.01}),
},
"optional": {
"momentums": ("SIGMAS", {"forceInput": False}),
"sigmas": ("SIGMAS", {"forceInput": False}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS","SIGMAS")
RETURN_NAMES = ("momentums","sigmas")
CATEGORY = "sampling/custom_sampling/sigmas"
def main(self, steps_up, steps_down, rho_up, rho_down, s_min_start, s_max, s_min_end, sigmas=None, momentums=None):
s_up = get_sigmas_polyexponential(steps_up, s_min_start, s_max, rho_up)
s_down = get_sigmas_polyexponential(steps_down, s_min_end, s_max, rho_down)
s_up = s_up[:-1]
s_down = s_down[:-1]
s_up = torch.flip(s_up, dims=[0])
sigmas_new = torch.cat((s_up, s_down), dim=0)
momentums_new = torch.cat((s_up, -1*s_down), dim=0)
if sigmas is not None:
sigmas = torch.cat([sigmas, sigmas_new])
else:
sigmas = sigmas_new
if momentums is not None:
momentums = torch.cat([momentums, momentums_new])
else:
momentums = momentums_new
return (momentums,sigmas)
class tan_scheduler:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"steps": ("INT", {"default": 20, "min": 0,"max": 100000,"step": 1}),
"offset": ("FLOAT", {"default": 20, "min": 0,"max": 100000,"step": 0.1}),
"slope": ("FLOAT", {"default": 20, "min": -100000,"max": 100000,"step": 0.1}),
"start": ("FLOAT", {"default": 20, "min": -100000,"max": 100000,"step": 0.1}),
"end": ("FLOAT", {"default": 20, "min": -100000,"max": 100000,"step": 0.1}),
"sgm" : ("BOOLEAN", {"default": False}),
"pad" : ("BOOLEAN", {"default": False}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
CATEGORY = "sampling/custom_sampling/schedulers"
def main(self, steps, slope, offset, start, end, sgm, pad):
smax = ((2/pi)*atan(-slope*(0-offset))+1)/2
smin = ((2/pi)*atan(-slope*((steps-1)-offset))+1)/2
srange = smax-smin
sscale = start - end
if sgm:
steps+=1
sigmas = [ ( (((2/pi)*atan(-slope*(x-offset))+1)/2) - smin) * (1/srange) * sscale + end for x in range(steps)]
if sgm:
sigmas = sigmas[:-1]
if pad:
sigmas = torch.tensor(sigmas+[0])
else:
sigmas = torch.tensor(sigmas)
return (sigmas,)
class tan_scheduler_2stage:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"steps": ("INT", {"default": 40, "min": 0,"max": 100000,"step": 1}),
"midpoint": ("INT", {"default": 20, "min": 0,"max": 100000,"step": 1}),
"pivot_1": ("INT", {"default": 10, "min": 0,"max": 100000,"step": 1}),
"pivot_2": ("INT", {"default": 30, "min": 0,"max": 100000,"step": 1}),
"slope_1": ("FLOAT", {"default": 1, "min": -100000,"max": 100000,"step": 0.1}),
"slope_2": ("FLOAT", {"default": 1, "min": -100000,"max": 100000,"step": 0.1}),
"start": ("FLOAT", {"default": 1.0, "min": -100000,"max": 100000,"step": 0.1}),
"middle": ("FLOAT", {"default": 0.5, "min": -100000,"max": 100000,"step": 0.1}),
"end": ("FLOAT", {"default": 0.0, "min": -100000,"max": 100000,"step": 0.1}),
"pad" : ("BOOLEAN", {"default": False}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
RETURN_NAMES = ("sigmas",)
CATEGORY = "sampling/custom_sampling/schedulers"
def get_tan_sigmas(self, steps, slope, pivot, start, end):
smax = ((2/pi)*atan(-slope*(0-pivot))+1)/2
smin = ((2/pi)*atan(-slope*((steps-1)-pivot))+1)/2
srange = smax-smin
sscale = start - end
sigmas = [ ( (((2/pi)*atan(-slope*(x-pivot))+1)/2) - smin) * (1/srange) * sscale + end for x in range(steps)]
return sigmas
def main(self, steps, midpoint, start, middle, end, pivot_1, pivot_2, slope_1, slope_2, pad):
steps += 2
stage_2_len = steps - midpoint
stage_1_len = steps - stage_2_len
tan_sigmas_1 = self.get_tan_sigmas(stage_1_len, slope_1, pivot_1, start, middle)
tan_sigmas_2 = self.get_tan_sigmas(stage_2_len, slope_2, pivot_2 - stage_1_len, middle, end)
tan_sigmas_1 = tan_sigmas_1[:-1]
if pad:
tan_sigmas_2 = tan_sigmas_2+[0]
tan_sigmas = torch.tensor(tan_sigmas_1 + tan_sigmas_2)
return (tan_sigmas,)
class tan_scheduler_2stage_simple:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"steps": ("INT", {"default": 40, "min": 0,"max": 100000,"step": 1}),
"pivot_1": ("FLOAT", {"default": 1, "min": -100000,"max": 100000,"step": 0.05}),
"pivot_2": ("FLOAT", {"default": 1, "min": -100000,"max": 100000,"step": 0.05}),
"slope_1": ("FLOAT", {"default": 1, "min": -100000,"max": 100000,"step": 0.1}),
"slope_2": ("FLOAT", {"default": 1, "min": -100000,"max": 100000,"step": 0.1}),
"start": ("FLOAT", {"default": 1.0, "min": -100000,"max": 100000,"step": 0.1}),
"middle": ("FLOAT", {"default": 0.5, "min": -100000,"max": 100000,"step": 0.1}),
"end": ("FLOAT", {"default": 0.0, "min": -100000,"max": 100000,"step": 0.1}),
"pad" : ("BOOLEAN", {"default": False}),
}
}
FUNCTION = "main"
RETURN_TYPES = ("SIGMAS",)
RETURN_NAMES = ("sigmas",)
CATEGORY = "sampling/custom_sampling/schedulers"
def get_tan_sigmas(self, steps, slope, pivot, start, end):
smax = ((2/pi)*atan(-slope*(0-pivot))+1)/2
smin = ((2/pi)*atan(-slope*((steps-1)-pivot))+1)/2
srange = smax-smin
sscale = start - end
sigmas = [ ( (((2/pi)*atan(-slope*(x-pivot))+1)/2) - smin) * (1/srange) * sscale + end for x in range(steps)]
return sigmas
def main(self, steps, start, middle, end, pivot_1, pivot_2, slope_1, slope_2, pad):
steps += 2
midpoint = int( (steps*pivot_1 + steps*pivot_2) / 2 )
pivot_1 = int(steps * pivot_1)
pivot_2 = int(steps * pivot_2)
slope_1 = slope_1 / (steps/40)
slope_2 = slope_2 / (steps/40)
stage_2_len = steps - midpoint
stage_1_len = steps - stage_2_len
tan_sigmas_1 = self.get_tan_sigmas(stage_1_len, slope_1, pivot_1, start, middle)
tan_sigmas_2 = self.get_tan_sigmas(stage_2_len, slope_2, pivot_2 - stage_1_len, middle, end)
tan_sigmas_1 = tan_sigmas_1[:-1]
if pad:
tan_sigmas_2 = tan_sigmas_2+[0]
tan_sigmas = torch.tensor(tan_sigmas_1 + tan_sigmas_2)
return (tan_sigmas,)
def get_sigmas_simple_exponential(model, steps):
s = model.model_sampling
sigs = []
ss = len(s.sigmas) / steps
for x in range(steps):
sigs += [float(s.sigmas[-(1 + int(x * ss))])]
sigs += [0.0]
sigs = torch.FloatTensor(sigs)
exp = torch.exp(torch.log(torch.linspace(1, 0, steps + 1)))
return sigs * exp
extra_schedulers = {
"simple_exponential": get_sigmas_simple_exponential
}