@@ -298,6 +298,7 @@ class NeuralProphet:
298298 >>> m = NeuralProphet(collect_metrics=["MSE", "MAE", "RMSE"])
299299 >>> # use custorm torchmetrics names
300300 >>> m = NeuralProphet(collect_metrics={"MAPE": "MeanAbsolutePercentageError", "MSLE": "MeanSquaredLogError",
301+
301302 scheduler : str, torch.optim.lr_scheduler._LRScheduler
302303 Type of learning rate scheduler to use.
303304
@@ -446,7 +447,8 @@ def __init__(
446447 batch_size : Optional [int ] = None ,
447448 loss_func : Union [str , torch .nn .modules .loss ._Loss , Callable ] = "SmoothL1Loss" ,
448449 optimizer : Union [str , Type [torch .optim .Optimizer ]] = "AdamW" ,
449- scheduler : Optional [str ] = "onecyclelr" ,
450+ scheduler : Optional [Union [str , Type [torch .optim .lr_scheduler .LRScheduler ]]] = "onecyclelr" ,
451+ scheduler_args : Optional [dict ] = None ,
450452 newer_samples_weight : float = 2 ,
451453 newer_samples_start : float = 0.0 ,
452454 quantiles : List [float ] = [],
@@ -521,6 +523,7 @@ def __init__(
521523 quantiles = quantiles ,
522524 learning_rate = learning_rate ,
523525 scheduler = scheduler ,
526+ scheduler_args = scheduler_args ,
524527 epochs = epochs ,
525528 batch_size = batch_size ,
526529 loss_func = loss_func ,
@@ -932,7 +935,8 @@ def fit(
932935 continue_training : bool = False ,
933936 num_workers : int = 0 ,
934937 deterministic : bool = False ,
935- scheduler : Optional [str ] = None ,
938+ scheduler : Optional [Union [str , Type [torch .optim .lr_scheduler .LRScheduler ]]] = None ,
939+ scheduler_args : Optional [dict ] = None ,
936940 ):
937941 """Train, and potentially evaluate model.
938942
@@ -1002,20 +1006,30 @@ def fit(
10021006 "Model has been fitted already. If you want to continue training please set the flag continue_training."
10031007 )
10041008
1005- if continue_training and epochs is None :
1006- raise ValueError ("Continued training requires setting the number of epochs to train for." )
1007-
10081009 if continue_training :
1009- if scheduler is not None :
1010- self .config_train .scheduler = scheduler
1011- else :
1010+ if epochs is None :
1011+ raise ValueError ("Continued training requires setting the number of epochs to train for." )
1012+
1013+ if continue_training and self .metrics_logger .checkpoint_path is None :
1014+ log .error ("Continued training requires checkpointing in model to continue from last epoch." )
1015+
1016+ # if scheduler is not None:
1017+ # log.warning(
1018+ # "Scheduler can only be set in fit when continuing training. Please set the scheduler when initializing the model."
1019+ # )
1020+
1021+ if scheduler is None :
1022+ log .warning (
1023+ "No scheduler specified for continued training. Using a fallback scheduler for continued training."
1024+ )
10121025 self .config_train .scheduler = None
1013- self .config_train .set_scheduler ()
1026+ self .config_train .scheduler_args = None
1027+ self .config_train .set_scheduler ()
10141028
1015- if scheduler is not None and not continue_training :
1016- log . warning (
1017- "Scheduler can only be set in fit when continuing training. Please set the scheduler when initializing the model."
1018- )
1029+ if scheduler is not None :
1030+ self . config_train . scheduler = scheduler
1031+ self . config_train . scheduler_args = scheduler_args
1032+ self . config_train . set_scheduler ( )
10191033
10201034 # Configuration
10211035 if epochs is not None :
@@ -1061,6 +1075,7 @@ def fit(
10611075 log .info ("When Global modeling with local normalization, metrics are displayed in normalized scale." )
10621076
10631077 if minimal :
1078+ # overrides these settings:
10641079 checkpointing = False
10651080 self .metrics = False
10661081 progress = None
@@ -1101,9 +1116,6 @@ def fit(
11011116 or any (value != 1 for value in self .num_seasonalities_modelled_dict .values ())
11021117 )
11031118
1104- if continue_training and self .metrics_logger .checkpoint_path is None :
1105- log .error ("Continued training requires checkpointing in model to continue from last epoch." )
1106-
11071119 self .max_lags = df_utils .get_max_num_lags (
11081120 n_lags = self .n_lags , config_lagged_regressors = self .config_lagged_regressors
11091121 )
0 commit comments