Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] Add more test cases #45

Merged
merged 16 commits into from
Jan 29, 2022
Prev Previous commit
Next Next commit
update: check_valid_parameters
  • Loading branch information
kozistr committed Jan 29, 2022
commit ea2fc515e7cbdd3430af0f3a005685cdbb67266a
14 changes: 14 additions & 0 deletions pytorch_optimizer/ranger21.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def __init__(
self.norm_loss_factor = norm_loss_factor
self.eps = eps

self.check_valid_parameters()

# lookahead
self.lookahead_step: int = 0

Expand Down Expand Up @@ -124,6 +126,18 @@ def __init__(
self.start_warm_down: int = num_iterations - self.num_warm_down_iterations
self.warm_down_lr_delta: float = self.starting_lr - self.min_lr

def check_valid_parameters(self):
if self.lr < 0.0:
raise ValueError(f'Invalid learning rate : {self.lr}')
if not 0.0 <= self.betas[0] < 1.0:
raise ValueError(f'Invalid beta_0 : {self.betas[0]}')
if not 0.0 <= self.betas[1] < 1.0:
raise ValueError(f'Invalid beta_1 : {self.betas[1]}')
if self.weight_decay < 0.0:
raise ValueError(f'Invalid weight_decay : {self.weight_decay}')
if self.eps < 0.0:
raise ValueError(f'Invalid eps : {self.eps}')

def __setstate__(self, state: STATE):
super().__setstate__(state)

Expand Down