mirror of
https://github.com/twitter/the-algorithm-ml.git
synced 2025-01-10 23:09:05 +01:00
escaped conditional trap with for loop
optimizer selection logic for improved readability and maintainability.
This commit is contained in:
parent
ca8db6ddf4
commit
c4c5072402
@ -72,11 +72,7 @@ class OptimizerConfig(base_config.BaseConfig):
|
||||
|
||||
|
||||
def get_optimizer_algorithm_config(optimizer_config: OptimizerConfig):
|
||||
if optimizer_config.adam is not None:
|
||||
return optimizer_config.adam
|
||||
elif optimizer_config.sgd is not None:
|
||||
return optimizer_config.sgd
|
||||
elif optimizer_config.adagrad is not None:
|
||||
return optimizer_config.adagrad
|
||||
else:
|
||||
for optz in (optimizer_config.adam, optimizer_config.sgd, optimizer_config.adagrad):
|
||||
if optz is not None:
|
||||
return optz
|
||||
raise ValueError(f"No optimizer selected in optimizer_config, passed {optimizer_config}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user