summaryrefslogtreecommitdiffstats
path: root/training/optimization.py
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2022-12-28 21:00:34 +0100
committerVolpeon <git@volpeon.ink>2022-12-28 21:00:34 +0100
commit54d72ba4a8331d822a48bad9e381b47d39598125 (patch)
tree7db884984f7f940cc3198c3caca86d5b28eb7a21 /training/optimization.py
parentIntegrated updates from diffusers (diff)
downloadtextual-inversion-diff-54d72ba4a8331d822a48bad9e381b47d39598125.tar.gz
textual-inversion-diff-54d72ba4a8331d822a48bad9e381b47d39598125.tar.bz2
textual-inversion-diff-54d72ba4a8331d822a48bad9e381b47d39598125.zip
Updated 1-cycle scheduler
Diffstat (limited to 'training/optimization.py')
-rw-r--r--training/optimization.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/training/optimization.py b/training/optimization.py
index 3809f3b..a0c8673 100644
--- a/training/optimization.py
+++ b/training/optimization.py
@@ -6,7 +6,7 @@ from diffusers.utils import logging
6logger = logging.get_logger(__name__) 6logger = logging.get_logger(__name__)
7 7
8 8
9def get_one_cycle_schedule(optimizer, num_training_steps, annealing="cos", min_lr=0.01, mid_point=0.4, last_epoch=-1): 9def get_one_cycle_schedule(optimizer, num_training_steps, annealing="cos", min_lr=0.04, mid_point=0.3, last_epoch=-1):
10 """ 10 """
11 Create a schedule with a learning rate that decreases linearly from the initial lr set in the optimizer to 0, after 11 Create a schedule with a learning rate that decreases linearly from the initial lr set in the optimizer to 0, after
12 a warmup period during which it increases linearly from 0 to the initial lr set in the optimizer. 12 a warmup period during which it increases linearly from 0 to the initial lr set in the optimizer.
@@ -35,8 +35,12 @@ def get_one_cycle_schedule(optimizer, num_training_steps, annealing="cos", min_l
35 35
36 progress = float(num_training_steps - current_step) / float(max(1, num_training_steps - thresh_down)) 36 progress = float(num_training_steps - current_step) / float(max(1, num_training_steps - thresh_down))
37 return max(0.0, progress) * min_lr 37 return max(0.0, progress) * min_lr
38 else: 38
39 progress = float(current_step - thresh_up) / float(max(1, num_training_steps - thresh_up)) 39 progress = float(current_step - thresh_up) / float(max(1, num_training_steps - thresh_up))
40
41 if annealing == "half_cos":
40 return max(0.0, 1.0 + math.cos(math.pi * (0.5 + 0.5 * progress))) 42 return max(0.0, 1.0 + math.cos(math.pi * (0.5 + 0.5 * progress)))
41 43
44 return max(0.0, 0.5 * (1.0 + math.cos(math.pi * progress)))
45
42 return LambdaLR(optimizer, lr_lambda, last_epoch) 46 return LambdaLR(optimizer, lr_lambda, last_epoch)