"Repeating" scheduler modes

This commit is contained in:
Alex "mcmonkey" Goodwin
2023-06-18 09:06:45 -07:00
parent f02cacfc92
commit ed76841842
2 changed files with 31 additions and 19 deletions
+15 -4
View File
@@ -3,7 +3,7 @@ import torch, math
######################### DynThresh Core #########################
class DynThresh:
def __init__(self, mimic_scale, threshold_percentile, mimic_mode, mimic_scale_min, cfg_mode, cfg_scale_min, power_val, experiment_mode, maxSteps):
def __init__(self, mimic_scale, threshold_percentile, mimic_mode, mimic_scale_min, cfg_mode, cfg_scale_min, sched_val, experiment_mode, maxSteps):
self.mimic_scale = mimic_scale
self.threshold_percentile = threshold_percentile
self.mimic_mode = mimic_mode
@@ -12,7 +12,7 @@ class DynThresh:
self.cfg_scale_min = cfg_scale_min
self.mimic_scale_min = mimic_scale_min
self.experiment_mode = experiment_mode
self.power_val = power_val
self.sched_val = sched_val
def interpretScale(self, scale, mode, min):
scale -= min
@@ -32,9 +32,20 @@ class DynThresh:
elif mode == "Cosine Up":
scale *= 1.0 - math.cos((self.step / max) * 1.5707)
elif mode == "Power Up":
scale *= math.pow(self.step / max, self.power_val)
scale *= math.pow(self.step / max, self.sched_val)
elif mode == "Power Down":
scale *= 1.0 - math.pow(self.step / max, self.power_val)
scale *= 1.0 - math.pow(self.step / max, self.sched_val)
elif mode == "Linear Repeating":
portion = ((self.step / max) * self.sched_val) % 1.0
start = math.floor(portion)
portion -= start
scale *= (0.5 - portion) * 2 if portion < 0.5 else (portion - 0.5) * 2
elif mode == "Cosine Repeating":
curved = 1.0 - (math.cos((self.step / max) * 3.14159 * self.sched_val) * 0.5 + 0.5)
portion = curved % 1.0
start = math.floor(portion)
portion -= start
scale *= (0.5 - portion) * 2 if portion < 0.5 else (portion - 0.5) * 2
scale += min
return scale