scheduler.py 560 B

1234567891011121314151617181920
  1. import math
  2. def get_cosine_schedule_with_warmup_lr_lambda(
  3. current_step: int,
  4. *,
  5. num_warmup_steps: int,
  6. num_training_steps: int,
  7. num_cycles: float = 0.5,
  8. final_lr_ratio: float = 0.0,
  9. ):
  10. if current_step < num_warmup_steps:
  11. return float(current_step) / float(max(1, num_warmup_steps))
  12. progress = float(current_step - num_warmup_steps) / float(
  13. max(1, num_training_steps - num_warmup_steps)
  14. )
  15. return max(
  16. final_lr_ratio, 0.5 * (1.0 + math.cos(math.pi * float(num_cycles) * 2.0 * progress))
  17. )