From 7ca78015e502b23cbba3054cb501a7c202d2faf7 Mon Sep 17 00:00:00 2001 From: Dennis Bader Date: Mon, 28 Feb 2022 20:11:24 +0100 Subject: [PATCH] added val loss to progess bar and updated docs (#825) --- darts/models/forecasting/block_rnn_model.py | 32 ++++++++++--------- darts/models/forecasting/nbeats.py | 32 ++++++++++--------- .../forecasting/pl_forecasting_module.py | 15 +++++---- darts/models/forecasting/rnn_model.py | 32 ++++++++++--------- darts/models/forecasting/tcn_model.py | 32 ++++++++++--------- darts/models/forecasting/tft_model.py | 29 +++++++++-------- .../forecasting/torch_forecasting_model.py | 23 ++++++------- darts/models/forecasting/transformer_model.py | 32 ++++++++++--------- 8 files changed, 120 insertions(+), 107 deletions(-) diff --git a/darts/models/forecasting/block_rnn_model.py b/darts/models/forecasting/block_rnn_model.py index 3daafbd6d8..cd45edd0fe 100644 --- a/darts/models/forecasting/block_rnn_model.py +++ b/darts/models/forecasting/block_rnn_model.py @@ -181,22 +181,23 @@ def __init__( This parameter will be ignored for probabilistic models if the ``likelihood`` parameter is specified. Default: ``torch.nn.MSELoss()``. likelihood - The likelihood model to be used for probabilistic forecasts. + One of Darts' :meth:`Likelihood ` models to be used for + probabilistic forecasts. Default: ``None``. optimizer_cls - The PyTorch optimizer class to be used (default: ``torch.optim.Adam``). + The PyTorch optimizer class to be used. Default: ``torch.optim.Adam``. optimizer_kwargs Optionally, some keyword arguments for the PyTorch optimizer (e.g., ``{'lr': 1e-3}`` for specifying a learning rate). Otherwise the default values of the selected ``optimizer_cls`` - will be used. + will be used. Default: ``None``. lr_scheduler_cls Optionally, the PyTorch learning rate scheduler class to be used. Specifying ``None`` corresponds - to using a constant learning rate. + to using a constant learning rate. Default: ``None``. lr_scheduler_kwargs - Optionally, some keyword arguments for the PyTorch learning rate scheduler. + Optionally, some keyword arguments for the PyTorch learning rate scheduler. Default: ``None``. batch_size - Number of time series (input and output sequences) used in each training pass. + Number of time series (input and output sequences) used in each training pass. Default: ``32``. n_epochs - Number of epochs over which to train the model. + Number of epochs over which to train the model. Default: ``100``. model_name Name of the model. Used for creating checkpoints and saving tensorboard data. If not specified, defaults to the following string ``"YYYY-mm-dd_HH:MM:SS_torch_model_run_PID"``, where the initial part @@ -205,13 +206,13 @@ def __init__( ``"2021-06-14_09:53:32_torch_model_run_44607"``. work_dir Path of the working directory, where to save checkpoints and Tensorboard summaries. - (default: current working directory). + Default: current working directory. log_tensorboard If set, use Tensorboard to log the different parameters. The logs will be located in: - ``"{work_dir}/darts_logs/{model_name}/logs/"``. + ``"{work_dir}/darts_logs/{model_name}/logs/"``. Default: ``False``. nr_epochs_val_period Number of epochs to wait before evaluating the validation loss (if a validation - ``TimeSeries`` is passed to the :func:`fit()` method). + ``TimeSeries`` is passed to the :func:`fit()` method). Default: ``1``. torch_device_str Optionally, a string indicating the torch device to use. By default, ``torch_device_str`` is ``None`` which will run on CPU. Set it to ``"cuda"`` to use all available GPUs or ``"cuda:i"`` to only use @@ -232,13 +233,13 @@ def __init__( https://pytorch-lightning.readthedocs.io/en/stable/advanced/multi_gpu.html#select-gpu-devices force_reset If set to ``True``, any previously-existing model with the same name will be reset (all checkpoints will - be discarded). + be discarded). Default: ``False``. save_checkpoints Whether or not to automatically save the untrained model and checkpoints from training. To load the model from checkpoint, call :func:`MyModelClass.load_from_checkpoint()`, where :class:`MyModelClass` is the :class:`TorchForecastingModel` class that was used (such as :class:`TFTModel`, :class:`NBEATSModel`, etc.). If set to ``False``, the model can still be manually saved using - :func:`save_model()` and loaded using :func:`load_model()`. + :func:`save_model()` and loaded using :func:`load_model()`. Default: ``False``. add_encoders A large number of past and future covariates can be automatically generated with `add_encoders`. This can be done by adding multiple pre-defined index encoders and/or custom user-made functions that @@ -246,7 +247,7 @@ def __init__( transform the generated covariates. This happens all under one hood and only needs to be specified at model creation. Read :meth:`SequentialEncoder ` to find out more about - ``add_encoders``. An example showing some of ``add_encoders`` features: + ``add_encoders``. Default: ``None``. An example showing some of ``add_encoders`` features: .. highlight:: python .. code-block:: python @@ -262,6 +263,7 @@ def __init__( random_state Control the randomness of the weights initialization. Check this `link `_ for more details. + Default: ``None``. pl_trainer_kwargs By default :class:`TorchForecastingModel` creates a PyTorch Lightning Trainer with several useful presets that performs the training, validation and prediction processes. These presets include automatic @@ -269,7 +271,7 @@ def __init__( With ``pl_trainer_kwargs`` you can add additional kwargs to instantiate the PyTorch Lightning trainer object. Check the `PL Trainer documentation `_ for more information about the - supported kwargs. + supported kwargs. Default: ``None``. With parameter ``"callbacks"`` you can add custom or PyTorch-Lightning built-in callbacks to Darts' :class:`TorchForecastingModel`. Below is an example for adding EarlyStopping to the training process. The model will stop training early if the validation loss `val_loss` does not improve beyond @@ -298,7 +300,7 @@ def __init__( parameter ``trainer`` in :func:`fit()` and :func:`predict()`. show_warnings whether to show warnings raised from PyTorch Lightning. Useful to detect potential issues of - your forecasting use case. + your forecasting use case. Default: ``False``. """ super().__init__(**self._extract_torch_model_params(**self.model_params)) diff --git a/darts/models/forecasting/nbeats.py b/darts/models/forecasting/nbeats.py index 5580a816a9..6b4d611bd2 100644 --- a/darts/models/forecasting/nbeats.py +++ b/darts/models/forecasting/nbeats.py @@ -514,22 +514,23 @@ def __init__( This parameter will be ignored for probabilistic models if the ``likelihood`` parameter is specified. Default: ``torch.nn.MSELoss()``. likelihood - The likelihood model to be used for probabilistic forecasts. + One of Darts' :meth:`Likelihood ` models to be used for + probabilistic forecasts. Default: ``None``. optimizer_cls - The PyTorch optimizer class to be used (default: ``torch.optim.Adam``). + The PyTorch optimizer class to be used. Default: ``torch.optim.Adam``. optimizer_kwargs Optionally, some keyword arguments for the PyTorch optimizer (e.g., ``{'lr': 1e-3}`` for specifying a learning rate). Otherwise the default values of the selected ``optimizer_cls`` - will be used. + will be used. Default: ``None``. lr_scheduler_cls Optionally, the PyTorch learning rate scheduler class to be used. Specifying ``None`` corresponds - to using a constant learning rate. + to using a constant learning rate. Default: ``None``. lr_scheduler_kwargs - Optionally, some keyword arguments for the PyTorch learning rate scheduler. + Optionally, some keyword arguments for the PyTorch learning rate scheduler. Default: ``None``. batch_size - Number of time series (input and output sequences) used in each training pass. + Number of time series (input and output sequences) used in each training pass. Default: ``32``. n_epochs - Number of epochs over which to train the model. + Number of epochs over which to train the model. Default: ``100``. model_name Name of the model. Used for creating checkpoints and saving tensorboard data. If not specified, defaults to the following string ``"YYYY-mm-dd_HH:MM:SS_torch_model_run_PID"``, where the initial part @@ -538,13 +539,13 @@ def __init__( ``"2021-06-14_09:53:32_torch_model_run_44607"``. work_dir Path of the working directory, where to save checkpoints and Tensorboard summaries. - (default: current working directory). + Default: current working directory. log_tensorboard If set, use Tensorboard to log the different parameters. The logs will be located in: - ``"{work_dir}/darts_logs/{model_name}/logs/"``. + ``"{work_dir}/darts_logs/{model_name}/logs/"``. Default: ``False``. nr_epochs_val_period Number of epochs to wait before evaluating the validation loss (if a validation - ``TimeSeries`` is passed to the :func:`fit()` method). + ``TimeSeries`` is passed to the :func:`fit()` method). Default: ``1``. torch_device_str Optionally, a string indicating the torch device to use. By default, ``torch_device_str`` is ``None`` which will run on CPU. Set it to ``"cuda"`` to use all available GPUs or ``"cuda:i"`` to only use @@ -565,13 +566,13 @@ def __init__( https://pytorch-lightning.readthedocs.io/en/stable/advanced/multi_gpu.html#select-gpu-devices force_reset If set to ``True``, any previously-existing model with the same name will be reset (all checkpoints will - be discarded). + be discarded). Default: ``False``. save_checkpoints Whether or not to automatically save the untrained model and checkpoints from training. To load the model from checkpoint, call :func:`MyModelClass.load_from_checkpoint()`, where :class:`MyModelClass` is the :class:`TorchForecastingModel` class that was used (such as :class:`TFTModel`, :class:`NBEATSModel`, etc.). If set to ``False``, the model can still be manually saved using - :func:`save_model()` and loaded using :func:`load_model()`. + :func:`save_model()` and loaded using :func:`load_model()`. Default: ``False``. add_encoders A large number of past and future covariates can be automatically generated with `add_encoders`. This can be done by adding multiple pre-defined index encoders and/or custom user-made functions that @@ -579,7 +580,7 @@ def __init__( transform the generated covariates. This happens all under one hood and only needs to be specified at model creation. Read :meth:`SequentialEncoder ` to find out more about - ``add_encoders``. An example showing some of ``add_encoders`` features: + ``add_encoders``. Default: ``None``. An example showing some of ``add_encoders`` features: .. highlight:: python .. code-block:: python @@ -595,6 +596,7 @@ def __init__( random_state Control the randomness of the weights initialization. Check this `link `_ for more details. + Default: ``None``. pl_trainer_kwargs By default :class:`TorchForecastingModel` creates a PyTorch Lightning Trainer with several useful presets that performs the training, validation and prediction processes. These presets include automatic @@ -602,7 +604,7 @@ def __init__( With ``pl_trainer_kwargs`` you can add additional kwargs to instantiate the PyTorch Lightning trainer object. Check the `PL Trainer documentation `_ for more information about the - supported kwargs. + supported kwargs. Default: ``None``. With parameter ``"callbacks"`` you can add custom or PyTorch-Lightning built-in callbacks to Darts' :class:`TorchForecastingModel`. Below is an example for adding EarlyStopping to the training process. The model will stop training early if the validation loss `val_loss` does not improve beyond @@ -631,7 +633,7 @@ def __init__( parameter ``trainer`` in :func:`fit()` and :func:`predict()`. show_warnings whether to show warnings raised from PyTorch Lightning. Useful to detect potential issues of - your forecasting use case. + your forecasting use case. Default: ``False``. References ---------- diff --git a/darts/models/forecasting/pl_forecasting_module.py b/darts/models/forecasting/pl_forecasting_module.py index ff469de967..40a1698d8e 100644 --- a/darts/models/forecasting/pl_forecasting_module.py +++ b/darts/models/forecasting/pl_forecasting_module.py @@ -55,18 +55,19 @@ def __init__( This parameter will be ignored for probabilistic models if the ``likelihood`` parameter is specified. Default: ``torch.nn.MSELoss()``. likelihood - The likelihood model to be used for probabilistic forecasts. + One of Darts' :meth:`Likelihood ` models to be used for + probabilistic forecasts. Default: ``None``. optimizer_cls - The PyTorch optimizer class to be used (default: ``torch.optim.Adam``). + The PyTorch optimizer class to be used. Default: ``torch.optim.Adam``. optimizer_kwargs Optionally, some keyword arguments for the PyTorch optimizer (e.g., ``{'lr': 1e-3}`` for specifying a learning rate). Otherwise the default values of the selected ``optimizer_cls`` - will be used. + will be used. Default: ``None``. lr_scheduler_cls Optionally, the PyTorch learning rate scheduler class to be used. Specifying ``None`` corresponds - to using a constant learning rate. + to using a constant learning rate. Default: ``None``. lr_scheduler_kwargs - Optionally, some keyword arguments for the PyTorch learning rate scheduler. + Optionally, some keyword arguments for the PyTorch learning rate scheduler. Default: ``None``. """ super().__init__() @@ -117,7 +118,7 @@ def training_step(self, train_batch, batch_idx) -> torch.Tensor: -1 ] # By convention target is always the last element returned by datasets loss = self._compute_loss(output, target) - self.log("train_loss", loss, batch_size=train_batch[0].shape[0]) + self.log("train_loss", loss, batch_size=train_batch[0].shape[0], prog_bar=True) return loss def validation_step(self, val_batch, batch_idx) -> torch.Tensor: @@ -125,7 +126,7 @@ def validation_step(self, val_batch, batch_idx) -> torch.Tensor: output = self._produce_train_output(val_batch[:-1]) target = val_batch[-1] loss = self._compute_loss(output, target) - self.log("val_loss", loss, batch_size=val_batch[0].shape[0]) + self.log("val_loss", loss, batch_size=val_batch[0].shape[0], prog_bar=True) return loss def predict_step( diff --git a/darts/models/forecasting/rnn_model.py b/darts/models/forecasting/rnn_model.py index 7b6f0d6165..1135eef9e2 100644 --- a/darts/models/forecasting/rnn_model.py +++ b/darts/models/forecasting/rnn_model.py @@ -247,22 +247,23 @@ def __init__( This parameter will be ignored for probabilistic models if the ``likelihood`` parameter is specified. Default: ``torch.nn.MSELoss()``. likelihood - The likelihood model to be used for probabilistic forecasts. + One of Darts' :meth:`Likelihood ` models to be used for + probabilistic forecasts. Default: ``None``. optimizer_cls - The PyTorch optimizer class to be used (default: ``torch.optim.Adam``). + The PyTorch optimizer class to be used. Default: ``torch.optim.Adam``. optimizer_kwargs Optionally, some keyword arguments for the PyTorch optimizer (e.g., ``{'lr': 1e-3}`` for specifying a learning rate). Otherwise the default values of the selected ``optimizer_cls`` - will be used. + will be used. Default: ``None``. lr_scheduler_cls Optionally, the PyTorch learning rate scheduler class to be used. Specifying ``None`` corresponds - to using a constant learning rate. + to using a constant learning rate. Default: ``None``. lr_scheduler_kwargs - Optionally, some keyword arguments for the PyTorch learning rate scheduler. + Optionally, some keyword arguments for the PyTorch learning rate scheduler. Default: ``None``. batch_size - Number of time series (input and output sequences) used in each training pass. + Number of time series (input and output sequences) used in each training pass. Default: ``32``. n_epochs - Number of epochs over which to train the model. + Number of epochs over which to train the model. Default: ``100``. model_name Name of the model. Used for creating checkpoints and saving tensorboard data. If not specified, defaults to the following string ``"YYYY-mm-dd_HH:MM:SS_torch_model_run_PID"``, where the initial part @@ -271,13 +272,13 @@ def __init__( ``"2021-06-14_09:53:32_torch_model_run_44607"``. work_dir Path of the working directory, where to save checkpoints and Tensorboard summaries. - (default: current working directory). + Default: current working directory. log_tensorboard If set, use Tensorboard to log the different parameters. The logs will be located in: - ``"{work_dir}/darts_logs/{model_name}/logs/"``. + ``"{work_dir}/darts_logs/{model_name}/logs/"``. Default: ``False``. nr_epochs_val_period Number of epochs to wait before evaluating the validation loss (if a validation - ``TimeSeries`` is passed to the :func:`fit()` method). + ``TimeSeries`` is passed to the :func:`fit()` method). Default: ``1``. torch_device_str Optionally, a string indicating the torch device to use. By default, ``torch_device_str`` is ``None`` which will run on CPU. Set it to ``"cuda"`` to use all available GPUs or ``"cuda:i"`` to only use @@ -298,13 +299,13 @@ def __init__( https://pytorch-lightning.readthedocs.io/en/stable/advanced/multi_gpu.html#select-gpu-devices force_reset If set to ``True``, any previously-existing model with the same name will be reset (all checkpoints will - be discarded). + be discarded). Default: ``False``. save_checkpoints Whether or not to automatically save the untrained model and checkpoints from training. To load the model from checkpoint, call :func:`MyModelClass.load_from_checkpoint()`, where :class:`MyModelClass` is the :class:`TorchForecastingModel` class that was used (such as :class:`TFTModel`, :class:`NBEATSModel`, etc.). If set to ``False``, the model can still be manually saved using - :func:`save_model()` and loaded using :func:`load_model()`. + :func:`save_model()` and loaded using :func:`load_model()`. Default: ``False``. add_encoders A large number of past and future covariates can be automatically generated with `add_encoders`. This can be done by adding multiple pre-defined index encoders and/or custom user-made functions that @@ -312,7 +313,7 @@ def __init__( transform the generated covariates. This happens all under one hood and only needs to be specified at model creation. Read :meth:`SequentialEncoder ` to find out more about - ``add_encoders``. An example showing some of ``add_encoders`` features: + ``add_encoders``. Default: ``None``. An example showing some of ``add_encoders`` features: .. highlight:: python .. code-block:: python @@ -328,6 +329,7 @@ def __init__( random_state Control the randomness of the weights initialization. Check this `link `_ for more details. + Default: ``None``. pl_trainer_kwargs By default :class:`TorchForecastingModel` creates a PyTorch Lightning Trainer with several useful presets that performs the training, validation and prediction processes. These presets include automatic @@ -335,7 +337,7 @@ def __init__( With ``pl_trainer_kwargs`` you can add additional kwargs to instantiate the PyTorch Lightning trainer object. Check the `PL Trainer documentation `_ for more information about the - supported kwargs. + supported kwargs. Default: ``None``. With parameter ``"callbacks"`` you can add custom or PyTorch-Lightning built-in callbacks to Darts' :class:`TorchForecastingModel`. Below is an example for adding EarlyStopping to the training process. The model will stop training early if the validation loss `val_loss` does not improve beyond @@ -364,7 +366,7 @@ def __init__( parameter ``trainer`` in :func:`fit()` and :func:`predict()`. show_warnings whether to show warnings raised from PyTorch Lightning. Useful to detect potential issues of - your forecasting use case. + your forecasting use case. Default: ``False``. """ # create copy of model parameters model_kwargs = {key: val for key, val in self.model_params.items()} diff --git a/darts/models/forecasting/tcn_model.py b/darts/models/forecasting/tcn_model.py index 2ddba3f68d..bd8006d1c0 100644 --- a/darts/models/forecasting/tcn_model.py +++ b/darts/models/forecasting/tcn_model.py @@ -300,22 +300,23 @@ def __init__( This parameter will be ignored for probabilistic models if the ``likelihood`` parameter is specified. Default: ``torch.nn.MSELoss()``. likelihood - The likelihood model to be used for probabilistic forecasts. + One of Darts' :meth:`Likelihood ` models to be used for + probabilistic forecasts. Default: ``None``. optimizer_cls - The PyTorch optimizer class to be used (default: ``torch.optim.Adam``). + The PyTorch optimizer class to be used. Default: ``torch.optim.Adam``. optimizer_kwargs Optionally, some keyword arguments for the PyTorch optimizer (e.g., ``{'lr': 1e-3}`` for specifying a learning rate). Otherwise the default values of the selected ``optimizer_cls`` - will be used. + will be used. Default: ``None``. lr_scheduler_cls Optionally, the PyTorch learning rate scheduler class to be used. Specifying ``None`` corresponds - to using a constant learning rate. + to using a constant learning rate. Default: ``None``. lr_scheduler_kwargs - Optionally, some keyword arguments for the PyTorch learning rate scheduler. + Optionally, some keyword arguments for the PyTorch learning rate scheduler. Default: ``None``. batch_size - Number of time series (input and output sequences) used in each training pass. + Number of time series (input and output sequences) used in each training pass. Default: ``32``. n_epochs - Number of epochs over which to train the model. + Number of epochs over which to train the model. Default: ``100``. model_name Name of the model. Used for creating checkpoints and saving tensorboard data. If not specified, defaults to the following string ``"YYYY-mm-dd_HH:MM:SS_torch_model_run_PID"``, where the initial part @@ -324,13 +325,13 @@ def __init__( ``"2021-06-14_09:53:32_torch_model_run_44607"``. work_dir Path of the working directory, where to save checkpoints and Tensorboard summaries. - (default: current working directory). + Default: current working directory. log_tensorboard If set, use Tensorboard to log the different parameters. The logs will be located in: - ``"{work_dir}/darts_logs/{model_name}/logs/"``. + ``"{work_dir}/darts_logs/{model_name}/logs/"``. Default: ``False``. nr_epochs_val_period Number of epochs to wait before evaluating the validation loss (if a validation - ``TimeSeries`` is passed to the :func:`fit()` method). + ``TimeSeries`` is passed to the :func:`fit()` method). Default: ``1``. torch_device_str Optionally, a string indicating the torch device to use. By default, ``torch_device_str`` is ``None`` which will run on CPU. Set it to ``"cuda"`` to use all available GPUs or ``"cuda:i"`` to only use @@ -351,13 +352,13 @@ def __init__( https://pytorch-lightning.readthedocs.io/en/stable/advanced/multi_gpu.html#select-gpu-devices force_reset If set to ``True``, any previously-existing model with the same name will be reset (all checkpoints will - be discarded). + be discarded). Default: ``False``. save_checkpoints Whether or not to automatically save the untrained model and checkpoints from training. To load the model from checkpoint, call :func:`MyModelClass.load_from_checkpoint()`, where :class:`MyModelClass` is the :class:`TorchForecastingModel` class that was used (such as :class:`TFTModel`, :class:`NBEATSModel`, etc.). If set to ``False``, the model can still be manually saved using - :func:`save_model()` and loaded using :func:`load_model()`. + :func:`save_model()` and loaded using :func:`load_model()`. Default: ``False``. add_encoders A large number of past and future covariates can be automatically generated with `add_encoders`. This can be done by adding multiple pre-defined index encoders and/or custom user-made functions that @@ -365,7 +366,7 @@ def __init__( transform the generated covariates. This happens all under one hood and only needs to be specified at model creation. Read :meth:`SequentialEncoder ` to find out more about - ``add_encoders``. An example showing some of ``add_encoders`` features: + ``add_encoders``. Default: ``None``. An example showing some of ``add_encoders`` features: .. highlight:: python .. code-block:: python @@ -381,6 +382,7 @@ def __init__( random_state Control the randomness of the weights initialization. Check this `link `_ for more details. + Default: ``None``. pl_trainer_kwargs By default :class:`TorchForecastingModel` creates a PyTorch Lightning Trainer with several useful presets that performs the training, validation and prediction processes. These presets include automatic @@ -388,7 +390,7 @@ def __init__( With ``pl_trainer_kwargs`` you can add additional kwargs to instantiate the PyTorch Lightning trainer object. Check the `PL Trainer documentation `_ for more information about the - supported kwargs. + supported kwargs. Default: ``None``. With parameter ``"callbacks"`` you can add custom or PyTorch-Lightning built-in callbacks to Darts' :class:`TorchForecastingModel`. Below is an example for adding EarlyStopping to the training process. The model will stop training early if the validation loss `val_loss` does not improve beyond @@ -417,7 +419,7 @@ def __init__( parameter ``trainer`` in :func:`fit()` and :func:`predict()`. show_warnings whether to show warnings raised from PyTorch Lightning. Useful to detect potential issues of - your forecasting use case. + your forecasting use case. Default: ``False``. References ---------- diff --git a/darts/models/forecasting/tft_model.py b/darts/models/forecasting/tft_model.py index fa1b25be6d..0282e3dc97 100644 --- a/darts/models/forecasting/tft_model.py +++ b/darts/models/forecasting/tft_model.py @@ -609,20 +609,20 @@ def __init__( Darts' :class:`TorchForecastingModel`. optimizer_cls - The PyTorch optimizer class to be used (default: ``torch.optim.Adam``). + The PyTorch optimizer class to be used. Default: ``torch.optim.Adam``. optimizer_kwargs Optionally, some keyword arguments for the PyTorch optimizer (e.g., ``{'lr': 1e-3}`` for specifying a learning rate). Otherwise the default values of the selected ``optimizer_cls`` - will be used. + will be used. Default: ``None``. lr_scheduler_cls Optionally, the PyTorch learning rate scheduler class to be used. Specifying ``None`` corresponds - to using a constant learning rate. + to using a constant learning rate. Default: ``None``. lr_scheduler_kwargs - Optionally, some keyword arguments for the PyTorch learning rate scheduler. + Optionally, some keyword arguments for the PyTorch learning rate scheduler. Default: ``None``. batch_size - Number of time series (input and output sequences) used in each training pass. + Number of time series (input and output sequences) used in each training pass. Default: ``32``. n_epochs - Number of epochs over which to train the model. + Number of epochs over which to train the model. Default: ``100``. model_name Name of the model. Used for creating checkpoints and saving tensorboard data. If not specified, defaults to the following string ``"YYYY-mm-dd_HH:MM:SS_torch_model_run_PID"``, where the initial part @@ -631,13 +631,13 @@ def __init__( ``"2021-06-14_09:53:32_torch_model_run_44607"``. work_dir Path of the working directory, where to save checkpoints and Tensorboard summaries. - (default: current working directory). + Default: current working directory. log_tensorboard If set, use Tensorboard to log the different parameters. The logs will be located in: - ``"{work_dir}/darts_logs/{model_name}/logs/"``. + ``"{work_dir}/darts_logs/{model_name}/logs/"``. Default: ``False``. nr_epochs_val_period Number of epochs to wait before evaluating the validation loss (if a validation - ``TimeSeries`` is passed to the :func:`fit()` method). + ``TimeSeries`` is passed to the :func:`fit()` method). Default: ``1``. torch_device_str Optionally, a string indicating the torch device to use. By default, ``torch_device_str`` is ``None`` which will run on CPU. Set it to ``"cuda"`` to use all available GPUs or ``"cuda:i"`` to only use @@ -658,13 +658,13 @@ def __init__( https://pytorch-lightning.readthedocs.io/en/stable/advanced/multi_gpu.html#select-gpu-devices force_reset If set to ``True``, any previously-existing model with the same name will be reset (all checkpoints will - be discarded). + be discarded). Default: ``False``. save_checkpoints Whether or not to automatically save the untrained model and checkpoints from training. To load the model from checkpoint, call :func:`MyModelClass.load_from_checkpoint()`, where :class:`MyModelClass` is the :class:`TorchForecastingModel` class that was used (such as :class:`TFTModel`, :class:`NBEATSModel`, etc.). If set to ``False``, the model can still be manually saved using - :func:`save_model()` and loaded using :func:`load_model()`. + :func:`save_model()` and loaded using :func:`load_model()`. Default: ``False``. add_encoders A large number of past and future covariates can be automatically generated with `add_encoders`. This can be done by adding multiple pre-defined index encoders and/or custom user-made functions that @@ -672,7 +672,7 @@ def __init__( transform the generated covariates. This happens all under one hood and only needs to be specified at model creation. Read :meth:`SequentialEncoder ` to find out more about - ``add_encoders``. An example showing some of ``add_encoders`` features: + ``add_encoders``. Default: ``None``. An example showing some of ``add_encoders`` features: .. highlight:: python .. code-block:: python @@ -688,6 +688,7 @@ def __init__( random_state Control the randomness of the weights initialization. Check this `link `_ for more details. + Default: ``None``. pl_trainer_kwargs By default :class:`TorchForecastingModel` creates a PyTorch Lightning Trainer with several useful presets that performs the training, validation and prediction processes. These presets include automatic @@ -695,7 +696,7 @@ def __init__( With ``pl_trainer_kwargs`` you can add additional kwargs to instantiate the PyTorch Lightning trainer object. Check the `PL Trainer documentation `_ for more information about the - supported kwargs. + supported kwargs. Default: ``None``. With parameter ``"callbacks"`` you can add custom or PyTorch-Lightning built-in callbacks to Darts' :class:`TorchForecastingModel`. Below is an example for adding EarlyStopping to the training process. The model will stop training early if the validation loss `val_loss` does not improve beyond @@ -724,7 +725,7 @@ def __init__( parameter ``trainer`` in :func:`fit()` and :func:`predict()`. show_warnings whether to show warnings raised from PyTorch Lightning. Useful to detect potential issues of - your forecasting use case. + your forecasting use case. Default: ``False``. References ---------- diff --git a/darts/models/forecasting/torch_forecasting_model.py b/darts/models/forecasting/torch_forecasting_model.py index c1b7231947..deb7f2b3f7 100644 --- a/darts/models/forecasting/torch_forecasting_model.py +++ b/darts/models/forecasting/torch_forecasting_model.py @@ -118,7 +118,7 @@ def __init__( model_name: str = None, work_dir: str = os.path.join(os.getcwd(), DEFAULT_DARTS_FOLDER), log_tensorboard: bool = False, - nr_epochs_val_period: int = 10, + nr_epochs_val_period: int = 1, torch_device_str: Optional[str] = None, force_reset: bool = False, save_checkpoints: bool = False, @@ -142,9 +142,9 @@ def __init__( Parameters ---------- batch_size - Number of time series (input and output sequences) used in each training pass. + Number of time series (input and output sequences) used in each training pass. Default: ``32``. n_epochs - Number of epochs over which to train the model. + Number of epochs over which to train the model. Default: ``100``. model_name Name of the model. Used for creating checkpoints and saving tensorboard data. If not specified, defaults to the following string ``"YYYY-mm-dd_HH:MM:SS_torch_model_run_PID"``, where the initial part @@ -153,13 +153,13 @@ def __init__( ``"2021-06-14_09:53:32_torch_model_run_44607"``. work_dir Path of the working directory, where to save checkpoints and Tensorboard summaries. - (default: current working directory). + Default: current working directory. log_tensorboard If set, use Tensorboard to log the different parameters. The logs will be located in: - ``"{work_dir}/darts_logs/{model_name}/logs/"``. + ``"{work_dir}/darts_logs/{model_name}/logs/"``. Default: ``False``. nr_epochs_val_period Number of epochs to wait before evaluating the validation loss (if a validation - ``TimeSeries`` is passed to the :func:`fit()` method). + ``TimeSeries`` is passed to the :func:`fit()` method). Default: ``1``. torch_device_str Optionally, a string indicating the torch device to use. By default, ``torch_device_str`` is ``None`` which will run on CPU. Set it to ``"cuda"`` to use all available GPUs or ``"cuda:i"`` to only use @@ -180,13 +180,13 @@ def __init__( https://pytorch-lightning.readthedocs.io/en/stable/advanced/multi_gpu.html#select-gpu-devices force_reset If set to ``True``, any previously-existing model with the same name will be reset (all checkpoints will - be discarded). + be discarded). Default: ``False``. save_checkpoints Whether or not to automatically save the untrained model and checkpoints from training. To load the model from checkpoint, call :func:`MyModelClass.load_from_checkpoint()`, where :class:`MyModelClass` is the :class:`TorchForecastingModel` class that was used (such as :class:`TFTModel`, :class:`NBEATSModel`, etc.). If set to ``False``, the model can still be manually saved using - :func:`save_model()` and loaded using :func:`load_model()`. + :func:`save_model()` and loaded using :func:`load_model()`. Default: ``False``. add_encoders A large number of past and future covariates can be automatically generated with `add_encoders`. This can be done by adding multiple pre-defined index encoders and/or custom user-made functions that @@ -194,7 +194,7 @@ def __init__( transform the generated covariates. This happens all under one hood and only needs to be specified at model creation. Read :meth:`SequentialEncoder ` to find out more about - ``add_encoders``. An example showing some of ``add_encoders`` features: + ``add_encoders``. Default: ``None``. An example showing some of ``add_encoders`` features: .. highlight:: python .. code-block:: python @@ -210,6 +210,7 @@ def __init__( random_state Control the randomness of the weights initialization. Check this `link `_ for more details. + Default: ``None``. pl_trainer_kwargs By default :class:`TorchForecastingModel` creates a PyTorch Lightning Trainer with several useful presets that performs the training, validation and prediction processes. These presets include automatic @@ -217,7 +218,7 @@ def __init__( With ``pl_trainer_kwargs`` you can add additional kwargs to instantiate the PyTorch Lightning trainer object. Check the `PL Trainer documentation `_ for more information about the - supported kwargs. + supported kwargs. Default: ``None``. With parameter ``"callbacks"`` you can add custom or PyTorch-Lightning built-in callbacks to Darts' :class:`TorchForecastingModel`. Below is an example for adding EarlyStopping to the training process. The model will stop training early if the validation loss `val_loss` does not improve beyond @@ -246,7 +247,7 @@ def __init__( parameter ``trainer`` in :func:`fit()` and :func:`predict()`. show_warnings whether to show warnings raised from PyTorch Lightning. Useful to detect potential issues of - your forecasting use case. + your forecasting use case. Default: ``False``. """ super().__init__() suppress_lightning_warnings(suppress_all=not show_warnings) diff --git a/darts/models/forecasting/transformer_model.py b/darts/models/forecasting/transformer_model.py index ae53e6cdca..023ad6991b 100644 --- a/darts/models/forecasting/transformer_model.py +++ b/darts/models/forecasting/transformer_model.py @@ -257,22 +257,23 @@ def __init__( This parameter will be ignored for probabilistic models if the ``likelihood`` parameter is specified. Default: ``torch.nn.MSELoss()``. likelihood - The likelihood model to be used for probabilistic forecasts. + One of Darts' :meth:`Likelihood ` models to be used for + probabilistic forecasts. Default: ``None``. optimizer_cls - The PyTorch optimizer class to be used (default: ``torch.optim.Adam``). + The PyTorch optimizer class to be used. Default: ``torch.optim.Adam``. optimizer_kwargs Optionally, some keyword arguments for the PyTorch optimizer (e.g., ``{'lr': 1e-3}`` for specifying a learning rate). Otherwise the default values of the selected ``optimizer_cls`` - will be used. + will be used. Default: ``None``. lr_scheduler_cls Optionally, the PyTorch learning rate scheduler class to be used. Specifying ``None`` corresponds - to using a constant learning rate. + to using a constant learning rate. Default: ``None``. lr_scheduler_kwargs - Optionally, some keyword arguments for the PyTorch learning rate scheduler. + Optionally, some keyword arguments for the PyTorch learning rate scheduler. Default: ``None``. batch_size - Number of time series (input and output sequences) used in each training pass. + Number of time series (input and output sequences) used in each training pass. Default: ``32``. n_epochs - Number of epochs over which to train the model. + Number of epochs over which to train the model. Default: ``100``. model_name Name of the model. Used for creating checkpoints and saving tensorboard data. If not specified, defaults to the following string ``"YYYY-mm-dd_HH:MM:SS_torch_model_run_PID"``, where the initial part @@ -281,13 +282,13 @@ def __init__( ``"2021-06-14_09:53:32_torch_model_run_44607"``. work_dir Path of the working directory, where to save checkpoints and Tensorboard summaries. - (default: current working directory). + Default: current working directory. log_tensorboard If set, use Tensorboard to log the different parameters. The logs will be located in: - ``"{work_dir}/darts_logs/{model_name}/logs/"``. + ``"{work_dir}/darts_logs/{model_name}/logs/"``. Default: ``False``. nr_epochs_val_period Number of epochs to wait before evaluating the validation loss (if a validation - ``TimeSeries`` is passed to the :func:`fit()` method). + ``TimeSeries`` is passed to the :func:`fit()` method). Default: ``1``. torch_device_str Optionally, a string indicating the torch device to use. By default, ``torch_device_str`` is ``None`` which will run on CPU. Set it to ``"cuda"`` to use all available GPUs or ``"cuda:i"`` to only use @@ -308,13 +309,13 @@ def __init__( https://pytorch-lightning.readthedocs.io/en/stable/advanced/multi_gpu.html#select-gpu-devices force_reset If set to ``True``, any previously-existing model with the same name will be reset (all checkpoints will - be discarded). + be discarded). Default: ``False``. save_checkpoints Whether or not to automatically save the untrained model and checkpoints from training. To load the model from checkpoint, call :func:`MyModelClass.load_from_checkpoint()`, where :class:`MyModelClass` is the :class:`TorchForecastingModel` class that was used (such as :class:`TFTModel`, :class:`NBEATSModel`, etc.). If set to ``False``, the model can still be manually saved using - :func:`save_model()` and loaded using :func:`load_model()`. + :func:`save_model()` and loaded using :func:`load_model()`. Default: ``False``. add_encoders A large number of past and future covariates can be automatically generated with `add_encoders`. This can be done by adding multiple pre-defined index encoders and/or custom user-made functions that @@ -322,7 +323,7 @@ def __init__( transform the generated covariates. This happens all under one hood and only needs to be specified at model creation. Read :meth:`SequentialEncoder ` to find out more about - ``add_encoders``. An example showing some of ``add_encoders`` features: + ``add_encoders``. Default: ``None``. An example showing some of ``add_encoders`` features: .. highlight:: python .. code-block:: python @@ -338,6 +339,7 @@ def __init__( random_state Control the randomness of the weights initialization. Check this `link `_ for more details. + Default: ``None``. pl_trainer_kwargs By default :class:`TorchForecastingModel` creates a PyTorch Lightning Trainer with several useful presets that performs the training, validation and prediction processes. These presets include automatic @@ -345,7 +347,7 @@ def __init__( With ``pl_trainer_kwargs`` you can add additional kwargs to instantiate the PyTorch Lightning trainer object. Check the `PL Trainer documentation `_ for more information about the - supported kwargs. + supported kwargs. Default: ``None``. With parameter ``"callbacks"`` you can add custom or PyTorch-Lightning built-in callbacks to Darts' :class:`TorchForecastingModel`. Below is an example for adding EarlyStopping to the training process. The model will stop training early if the validation loss `val_loss` does not improve beyond @@ -374,7 +376,7 @@ def __init__( parameter ``trainer`` in :func:`fit()` and :func:`predict()`. show_warnings whether to show warnings raised from PyTorch Lightning. Useful to detect potential issues of - your forecasting use case. + your forecasting use case. Default: ``False``. References ----------