docstr: Recurrent Neural Network Model (RNNs).
  
  This class provides three variants of RNNs:
  
  * Vanilla RNN
  
  * LSTM
  
  * GRU
  
  RNNModel is fully recurrent in the sense that, at prediction time, an output is computed using these inputs:
  
  - previous target value, which will be set to the last known target value for the first prediction,
    and for all other predictions it will be set to the previous prediction (in an auto-regressive fashion),
  - the previous hidden state,
  - the covariates at time `t` for forecasting the target at time `t` (if the model was trained with covariates),
  
  This model supports future covariates; and it requires these covariates to extend far enough in the past
  and the future (it's a so-called "dual covariates" model as the future covariates have to be provided both
  in the past and the future). The model will complain if the provided `future_covariates` series doesn't have
  an appropriate time span.
  
  For a block version using an RNN model as an encoder only and supporting past
  covariates, checkout `BlockRNNModel`.
  
  Parameters
  ----------
  input_chunk_length
      Number of past time steps that are fed to the forecasting module at prediction time.
  model
      Either a string specifying the RNN module type ("RNN", "LSTM" or "GRU"), or a subclass of
      :class:`CustomRNNModule` (the class itself, not an object of the class) with a custom logic.
  hidden_dim
      Size for feature maps for each hidden RNN layer (:math:`h_n`).
  n_rnn_layers
      The number of recurrent layers.
  dropout
      Fraction of neurons afected by Dropout.
  training_length
      The length of both input (target and covariates) and output (target) time series used during
      training. Generally speaking, `training_length` should have a higher value than `input_chunk_length`
      because otherwise during training the RNN is never run for as many iterations as it will during
      inference. For more information on this parameter, please see `darts.utils.data.ShiftedDataset`
  **kwargs
      Optional arguments to initialize the pytorch_lightning.Module, pytorch_lightning.Trainer, and
      Darts' :class:`TorchForecastingModel`.
  
  loss_fn
      PyTorch loss function used for training.
      This parameter will be ignored for probabilistic models if the ``likelihood`` parameter is specified.
      Default: ``torch.nn.MSELoss()``.
  likelihood
      One of Darts' :meth:`Likelihood <darts.utils.likelihood_models.Likelihood>` models to be used for
      probabilistic forecasts. Default: ``None``.
  torch_metrics
      A torch metric or a ``MetricCollection`` used for evaluation. A full list of available metrics can be found
      at https://torchmetrics.readthedocs.io/en/latest/. Default: ``None``.
  optimizer_cls
      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. Default: ``None``.
  lr_scheduler_cls
      Optionally, the PyTorch learning rate scheduler class to be used. Specifying ``None`` corresponds
      to using a constant learning rate. Default: ``None``.
  lr_scheduler_kwargs
      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. Default: ``32``.
  n_epochs
      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
      of the name is formatted with the local date and time, while PID is the processed ID (preventing models
      spawned at the same time by different processes to share the same model_name). E.g.,
      ``"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.
  log_tensorboard
      If set, use Tensorboard to log the different parameters. The logs will be located in:
      ``"{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). Default: ``1``.
  force_reset
      If set to ``True``, any previously-existing model with the same name will be reset (all checkpoints will
      be discarded). Default: ``False``.
  save_checkpoints
      Whether 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()` and loaded using :func:`load()`. 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
      will be used as index encoders. Additionally, a transformer such as Darts' :class:`Scaler` can be added to
      transform the generated covariates. This happens all under one hood and only needs to be specified at
      model creation.
      Read :meth:`SequentialEncoder <darts.dataprocessing.encoders.SequentialEncoder>` to find out more about
      ``add_encoders``. Default: ``None``. An example showing some of ``add_encoders`` features:
  
      .. highlight:: python
      .. code-block:: python
  
          def encode_year(idx):
              return (idx.year - 1950) / 50
  
          add_encoders={
              'cyclic': {'future': ['month']},
              'datetime_attribute': {'future': ['hour', 'dayofweek']},
              'position': {'past': ['relative'], 'future': ['relative']},
              'custom': {'past': [encode_year]},
              'transformer': Scaler(),
              'tz': 'CET'
          }
      ..
  random_state
      Control the randomness of the weights initialization. Check this
      `link <https://scikit-learn.org/stable/glossary.html#term-random_state>`_ 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
      checkpointing, tensorboard logging, setting the torch device and more.
      With ``pl_trainer_kwargs`` you can add additional kwargs to instantiate the PyTorch Lightning trainer
      object. Check the `PL Trainer documentation
      <https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html>`_ for more information about the
      supported kwargs. Default: ``None``.
      Running on GPU(s) is also possible using ``pl_trainer_kwargs`` by specifying keys ``"accelerator",
      "devices", and "auto_select_gpus"``. Some examples for setting the devices inside the ``pl_trainer_kwargs``
      dict:
  
      - ``{"accelerator": "cpu"}`` for CPU,
      - ``{"accelerator": "gpu", "devices": [i]}`` to use only GPU ``i`` (``i`` must be an integer),
      - ``{"accelerator": "gpu", "devices": -1, "auto_select_gpus": True}`` to use all available GPUS.
  
      For more info, see here:
      https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html#trainer-flags , and
      https://pytorch-lightning.readthedocs.io/en/stable/accelerators/gpu_basic.html#train-on-multiple-gpus
  
      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
      specifications. For more information on callbacks, visit:
      `PyTorch Lightning Callbacks
      <https://pytorch-lightning.readthedocs.io/en/stable/extensions/callbacks.html>`_
  
      .. highlight:: python
      .. code-block:: python
  
          from pytorch_lightning.callbacks.early_stopping import EarlyStopping
  
          # stop training when validation loss does not decrease more than 0.05 (`min_delta`) over
          # a period of 5 epochs (`patience`)
          my_stopper = EarlyStopping(
              monitor="val_loss",
              patience=5,
              min_delta=0.05,
              mode='min',
          )
  
          pl_trainer_kwargs={"callbacks": [my_stopper]}
      ..
  
      Note that you can also use a custom PyTorch Lightning Trainer for training and prediction with optional
      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. Default: ``False``.
  
  Examples
  --------
  >>> from darts.datasets import WeatherDataset
  >>> from darts.models import RNNModel
  >>> series = WeatherDataset().load()
  >>> # predicting atmospheric pressure
  >>> target = series['p (mbar)'][:100]
  >>> # optionally, use future temperatures (pretending this component is a forecast)
  >>> future_cov = series['T (degC)'][:106]
  >>> # `training_length` > `input_chunk_length` to mimic inference constraints
  >>> model = RNNModel(
  >>>     model="RNN",
  >>>     input_chunk_length=6,
  >>>     training_length=18,
  >>>     n_epochs=20,
  >>> )
  >>> model.fit(target, future_covariates=future_cov)
  >>> pred = model.predict(6)
  >>> pred.values()
  array([[ 3.18922903],
         [ 1.17791019],
         [ 0.39992814],
         [ 0.13277921],
         [ 0.02523252],
         [-0.01829086]])
  
  .. note::
      `RNN example notebook <https://unit8co.github.io/darts/examples/04-RNN-examples.html>`_ presents techniques
      that can be used to improve the forecasts quality compared to this simple usage example.
docstr_tok: ["Recurrent","Neural","Network","Model","(","RNNs",")",".","This","class","provides","three","variants","of","RNNs",":","*","Vanilla","RNN","*","LSTM","*","GRU","RNNModel","is","fully","recurrent","in","the","sense","that",",","at","prediction","time",",","an","output","is","computed","using","these","inputs",":","-","previous","target","value",",","which","will","be","set","to","the","last","known","target","value","for","the","first","prediction",",","and","for","all","other","predictions","it","will","be","set","to","the","previous","prediction","(","in","an","auto-regressive","fashion",")",",","-","the","previous","hidden","state",",","-","the","covariates","at","time","`","t","`","for","forecasting","the","target","at","time","`","t","`","(","if","the","model","was","trained","with","covariates",")",",","This","model","supports","future","covariates",";","and","it","requires","these","covariates","to","extend","far","enough","in","the","past","and","the","future","(","it","'s","a","so-called","``","dual","covariates","''","model","as","the","future","covariates","have","to","be","provided","both","in","the","past","and","the","future",")",".","The","model","will","complain","if","the","provided","`","future_covariates","`","series","does","n't","have","an","appropriate","time","span",".","For","a","block","version","using","an","RNN","model","as","an","encoder","only","and","supporting","past","covariates",",","checkout","`","BlockRNNModel","`",".","Parameters","--","--","--","--","--","input_chunk_length","Number","of","past","time","steps","that","are","fed","to","the","forecasting","module","at","prediction","time",".","model","Either","a","string","specifying","the","RNN","module","type","(","``","RNN","''",",","``","LSTM","''","or","``","GRU","''",")",",","or","a","subclass","of",":","class",":","`","CustomRNNModule","`","(","the","class","itself",",","not","an","object","of","the","class",")","with","a","custom","logic",".","hidden_dim","Size","for","feature","maps","for","each","hidden","RNN","layer","(",":","math",":","`","h_n","`",")",".","n_rnn_layers","The","number","of","recurrent","layers",".","dropout","Fraction","of","neurons","afected","by","Dropout",".","training_length","The","length","of","both","input","(","target","and","covariates",")","and","output","(","target",")","time","series","used","during","training",".","Generally","speaking",",","`","training_length","`","should","have","a","higher","value","than","`","input_chunk_length","`","because","otherwise","during","training","the","RNN","is","never","run","for","as","many","iterations","as","it","will","during","inference",".","For","more","information","on","this","parameter",",","please","see","`","darts.utils.data.ShiftedDataset","`","*","*","kwargs","Optional","arguments","to","initialize","the","pytorch_lightning.Module",",","pytorch_lightning.Trainer",",","and","Darts","'",":","class",":","`","TorchForecastingModel","`",".","loss_fn","PyTorch","loss","function","used","for","training",".","This","parameter","will","be","ignored","for","probabilistic","models","if","the","``","likelihood","``","parameter","is","specified",".","Default",":","``","torch.nn.MSELoss","(",")","``",".","likelihood","One","of","Darts","'",":","meth",":","`","Likelihood","<","darts.utils.likelihood_models.Likelihood",">","`","models","to","be","used","for","probabilistic","forecasts",".","Default",":","``","None","``",".","torch_metrics","A","torch","metric","or","a","``","MetricCollection","``","used","for","evaluation",".","A","full","list","of","available","metrics","can","be","found","at","https",":","\/\/torchmetrics.readthedocs.io\/en\/latest\/",".","Default",":","``","None","``",".","optimizer_cls","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",".","Default",":","``","None","``",".","lr_scheduler_cls","Optionally",",","the","PyTorch","learning","rate","scheduler","class","to","be","used",".","Specifying","``","None","``","corresponds","to","using","a","constant","learning","rate",".","Default",":","``","None","``",".","lr_scheduler_kwargs","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",".","Default",":","``","32","``",".","n_epochs","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","of","the","name","is","formatted","with","the","local","date","and","time",",","while","PID","is","the","processed","ID","(","preventing","models","spawned","at","the","same","time","by","different","processes","to","share","the","same","model_name",")",".","E.g.",",","``","``","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",".","log_tensorboard","If","set",",","use","Tensorboard","to","log","the","different","parameters",".","The","logs","will","be","located","in",":","``","``","{","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",")",".","Default",":","``","1","``",".","force_reset","If","set","to","``","True","``",",","any","previously-existing","model","with","the","same","name","will","be","reset","(","all","checkpoints","will","be","discarded",")",".","Default",":","``","False","``",".","save_checkpoints","Whether","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","(",")","`","and","loaded","using",":","func",":","`","load","(",")","`",".","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","will","be","used","as","index","encoders",".","Additionally",",","a","transformer","such","as","Darts","'",":","class",":","`","Scaler","`","can","be","added","to","transform","the","generated","covariates",".","This","happens","all","under","one","hood","and","only","needs","to","be","specified","at","model","creation",".","Read",":","meth",":","`","SequentialEncoder","<","darts.dataprocessing.encoders.SequentialEncoder",">","`","to","find","out","more","about","``","add_encoders","``",".","Default",":","``","None","``",".","An","example","showing","some","of","``","add_encoders","``","features",":","..","highlight",":",":","python","..","code-block",":",":","python","def","encode_year","(","idx",")",":","return","(","idx.year","-","1950",")","\/","50","add_encoders=","{","'cyclic","'",":","{","'future","'",":","[","'month","'","]","}",",","'datetime_attribute","'",":","{","'future","'",":","[","'hour","'",",","'dayofweek","'","]","}",",","'position","'",":","{","'past","'",":","[","'relative","'","]",",","'future","'",":","[","'relative","'","]","}",",","'custom","'",":","{","'past","'",":","[","encode_year","]","}",",","'transformer","'",":","Scaler","(",")",",","'tz","'",":","'CET'","}","..","random_state","Control","the","randomness","of","the","weights","initialization",".","Check","this","`","link","<","https",":","\/\/scikit-learn.org\/stable\/glossary.html","#","term-random_state",">","`","_","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","checkpointing",",","tensorboard","logging",",","setting","the","torch","device","and","more",".","With","``","pl_trainer_kwargs","``","you","can","add","additional","kwargs","to","instantiate","the","PyTorch","Lightning","trainer","object",".","Check","the","`","PL","Trainer","documentation","<","https",":","\/\/pytorch-lightning.readthedocs.io\/en\/stable\/common\/trainer.html",">","`","_","for","more","information","about","the","supported","kwargs",".","Default",":","``","None","``",".","Running","on","GPU","(","s",")","is","also","possible","using","``","pl_trainer_kwargs","``","by","specifying","keys","``","``","accelerator","''",",","``","devices","''",",","and","``","auto_select_gpus","''","``",".","Some","examples","for","setting","the","devices","inside","the","``","pl_trainer_kwargs","``","dict",":","-","``","{","``","accelerator","''",":","``","cpu","''","}","``","for","CPU",",","-","``","{","``","accelerator","''",":","``","gpu","''",",","``","devices","''",":","[","i","]","}","``","to","use","only","GPU","``","i","``","(","``","i","``","must","be","an","integer",")",",","-","``","{","``","accelerator","''",":","``","gpu","''",",","``","devices","''",":","-1",",","``","auto_select_gpus","''",":","True","}","``","to","use","all","available","GPUS",".","For","more","info",",","see","here",":","https",":","\/\/pytorch-lightning.readthedocs.io\/en\/stable\/common\/trainer.html","#","trainer-flags",",","and","https",":","\/\/pytorch-lightning.readthedocs.io\/en\/stable\/accelerators\/gpu_basic.html","#","train-on-multiple-gpus","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","specifications",".","For","more","information","on","callbacks",",","visit",":","`","PyTorch","Lightning","Callbacks","<","https",":","\/\/pytorch-lightning.readthedocs.io\/en\/stable\/extensions\/callbacks.html",">","`","_","..","highlight",":",":","python","..","code-block",":",":","python","from","pytorch_lightning.callbacks.early_stopping","import","EarlyStopping","#","stop","training","when","validation","loss","does","not","decrease","more","than","0.05","(","`","min_delta","`",")","over","#","a","period","of","5","epochs","(","`","patience","`",")","my_stopper","=","EarlyStopping","(","monitor=","''","val_loss","''",",","patience=5",",","min_delta=0.05",",","mode='min","'",",",")","pl_trainer_kwargs=","{","``","callbacks","''",":","[","my_stopper","]","}","..","Note","that","you","can","also","use","a","custom","PyTorch","Lightning","Trainer","for","training","and","prediction","with","optional","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",".","Default",":","``","False","``",".","Examples","--","--","--","--",">",">",">","from","darts.datasets","import","WeatherDataset",">",">",">","from","darts.models","import","RNNModel",">",">",">","series","=","WeatherDataset","(",")",".load","(",")",">",">",">","#","predicting","atmospheric","pressure",">",">",">","target","=","series","[","'","p","(","mbar",")","'","]","[",":100","]",">",">",">","#","optionally",",","use","future","temperatures","(","pretending","this","component","is","a","forecast",")",">",">",">","future_cov","=","series","[","'T","(","degC",")","'","]","[",":106","]",">",">",">","#","`","training_length","`",">","`","input_chunk_length","`","to","mimic","inference","constraints",">",">",">","model","=","RNNModel","(",">",">",">","model=","''","RNN","''",",",">",">",">","input_chunk_length=6",",",">",">",">","training_length=18",",",">",">",">","n_epochs=20",",",">",">",">",")",">",">",">","model.fit","(","target",",","future_covariates=future_cov",")",">",">",">","pred","=","model.predict","(","6",")",">",">",">","pred.values","(",")","array","(","[","[","3.18922903","]",",","[","1.17791019","]",",","[","0.39992814","]",",","[","0.13277921","]",",","[","0.02523252","]",",","[","-0.01829086","]","]",")","..","note",":",":","`","RNN","example","notebook","<","https",":","\/\/unit8co.github.io\/darts\/examples\/04-RNN-examples.html",">","`","_","presents","techniques","that","can","be","used","to","improve","the","forecasts","quality","compared","to","this","simple","usage","example","."]
code: def __init__(
      self,
      input_chunk_length: int,
      model: Union[str, Type[CustomRNNModule]] = "RNN",
      hidden_dim: int = 25,
      n_rnn_layers: int = 1,
      dropout: float = 0.0,
      training_length: int = 24,
      **kwargs,
  ):
      """Recurrent Neural Network Model (RNNs).
  
      This class provides three variants of RNNs:
  
      * Vanilla RNN
  
      * LSTM
  
      * GRU
  
      RNNModel is fully recurrent in the sense that, at prediction time, an output is computed using these inputs:
  
      - previous target value, which will be set to the last known target value for the first prediction,
        and for all other predictions it will be set to the previous prediction (in an auto-regressive fashion),
      - the previous hidden state,
      - the covariates at time `t` for forecasting the target at time `t` (if the model was trained with covariates),
  
      This model supports future covariates; and it requires these covariates to extend far enough in the past
      and the future (it's a so-called "dual covariates" model as the future covariates have to be provided both
      in the past and the future). The model will complain if the provided `future_covariates` series doesn't have
      an appropriate time span.
  
      For a block version using an RNN model as an encoder only and supporting past
      covariates, checkout `BlockRNNModel`.
  
      Parameters
      ----------
      input_chunk_length
          Number of past time steps that are fed to the forecasting module at prediction time.
      model
          Either a string specifying the RNN module type ("RNN", "LSTM" or "GRU"), or a subclass of
          :class:`CustomRNNModule` (the class itself, not an object of the class) with a custom logic.
      hidden_dim
          Size for feature maps for each hidden RNN layer (:math:`h_n`).
      n_rnn_layers
          The number of recurrent layers.
      dropout
          Fraction of neurons afected by Dropout.
      training_length
          The length of both input (target and covariates) and output (target) time series used during
          training. Generally speaking, `training_length` should have a higher value than `input_chunk_length`
          because otherwise during training the RNN is never run for as many iterations as it will during
          inference. For more information on this parameter, please see `darts.utils.data.ShiftedDataset`
      **kwargs
          Optional arguments to initialize the pytorch_lightning.Module, pytorch_lightning.Trainer, and
          Darts' :class:`TorchForecastingModel`.
  
      loss_fn
          PyTorch loss function used for training.
          This parameter will be ignored for probabilistic models if the ``likelihood`` parameter is specified.
          Default: ``torch.nn.MSELoss()``.
      likelihood
          One of Darts' :meth:`Likelihood <darts.utils.likelihood_models.Likelihood>` models to be used for
          probabilistic forecasts. Default: ``None``.
      torch_metrics
          A torch metric or a ``MetricCollection`` used for evaluation. A full list of available metrics can be found
          at https://torchmetrics.readthedocs.io/en/latest/. Default: ``None``.
      optimizer_cls
          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. Default: ``None``.
      lr_scheduler_cls
          Optionally, the PyTorch learning rate scheduler class to be used. Specifying ``None`` corresponds
          to using a constant learning rate. Default: ``None``.
      lr_scheduler_kwargs
          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. Default: ``32``.
      n_epochs
          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
          of the name is formatted with the local date and time, while PID is the processed ID (preventing models
          spawned at the same time by different processes to share the same model_name). E.g.,
          ``"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.
      log_tensorboard
          If set, use Tensorboard to log the different parameters. The logs will be located in:
          ``"{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). Default: ``1``.
      force_reset
          If set to ``True``, any previously-existing model with the same name will be reset (all checkpoints will
          be discarded). Default: ``False``.
      save_checkpoints
          Whether 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()` and loaded using :func:`load()`. 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
          will be used as index encoders. Additionally, a transformer such as Darts' :class:`Scaler` can be added to
          transform the generated covariates. This happens all under one hood and only needs to be specified at
          model creation.
          Read :meth:`SequentialEncoder <darts.dataprocessing.encoders.SequentialEncoder>` to find out more about
          ``add_encoders``. Default: ``None``. An example showing some of ``add_encoders`` features:
  
          .. highlight:: python
          .. code-block:: python
  
              def encode_year(idx):
                  return (idx.year - 1950) / 50
  
              add_encoders={
                  'cyclic': {'future': ['month']},
                  'datetime_attribute': {'future': ['hour', 'dayofweek']},
                  'position': {'past': ['relative'], 'future': ['relative']},
                  'custom': {'past': [encode_year]},
                  'transformer': Scaler(),
                  'tz': 'CET'
              }
          ..
      random_state
          Control the randomness of the weights initialization. Check this
          `link <https://scikit-learn.org/stable/glossary.html#term-random_state>`_ 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
          checkpointing, tensorboard logging, setting the torch device and more.
          With ``pl_trainer_kwargs`` you can add additional kwargs to instantiate the PyTorch Lightning trainer
          object. Check the `PL Trainer documentation
          <https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html>`_ for more information about the
          supported kwargs. Default: ``None``.
          Running on GPU(s) is also possible using ``pl_trainer_kwargs`` by specifying keys ``"accelerator",
          "devices", and "auto_select_gpus"``. Some examples for setting the devices inside the ``pl_trainer_kwargs``
          dict:
  
          - ``{"accelerator": "cpu"}`` for CPU,
          - ``{"accelerator": "gpu", "devices": [i]}`` to use only GPU ``i`` (``i`` must be an integer),
          - ``{"accelerator": "gpu", "devices": -1, "auto_select_gpus": True}`` to use all available GPUS.
  
          For more info, see here:
          https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html#trainer-flags , and
          https://pytorch-lightning.readthedocs.io/en/stable/accelerators/gpu_basic.html#train-on-multiple-gpus
  
          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
          specifications. For more information on callbacks, visit:
          `PyTorch Lightning Callbacks
          <https://pytorch-lightning.readthedocs.io/en/stable/extensions/callbacks.html>`_
  
          .. highlight:: python
          .. code-block:: python
  
              from pytorch_lightning.callbacks.early_stopping import EarlyStopping
  
              # stop training when validation loss does not decrease more than 0.05 (`min_delta`) over
              # a period of 5 epochs (`patience`)
              my_stopper = EarlyStopping(
                  monitor="val_loss",
                  patience=5,
                  min_delta=0.05,
                  mode='min',
              )
  
              pl_trainer_kwargs={"callbacks": [my_stopper]}
          ..
  
          Note that you can also use a custom PyTorch Lightning Trainer for training and prediction with optional
          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. Default: ``False``.
  
      Examples
      --------
      >>> from darts.datasets import WeatherDataset
      >>> from darts.models import RNNModel
      >>> series = WeatherDataset().load()
      >>> # predicting atmospheric pressure
      >>> target = series['p (mbar)'][:100]
      >>> # optionally, use future temperatures (pretending this component is a forecast)
      >>> future_cov = series['T (degC)'][:106]
      >>> # `training_length` > `input_chunk_length` to mimic inference constraints
      >>> model = RNNModel(
      >>>     model="RNN",
      >>>     input_chunk_length=6,
      >>>     training_length=18,
      >>>     n_epochs=20,
      >>> )
      >>> model.fit(target, future_covariates=future_cov)
      >>> pred = model.predict(6)
      >>> pred.values()
      array([[ 3.18922903],
             [ 1.17791019],
             [ 0.39992814],
             [ 0.13277921],
             [ 0.02523252],
             [-0.01829086]])
  
      .. note::
          `RNN example notebook <https://unit8co.github.io/darts/examples/04-RNN-examples.html>`_ presents techniques
          that can be used to improve the forecasts quality compared to this simple usage example.
      """
      # create copy of model parameters
      model_kwargs = {
          key: val for key, val in self.model_params.items()
      }
  
      for kwarg, default_value in zip(
          ["output_chunk_length", "use_reversible_instance_norm"],
          [1, False],
      ):
          if model_kwargs.get(kwarg) is not None:
              logger.warning(
                  f"ignoring user defined `{kwarg}`. RNNModel uses a fixed "
                  f"`{kwarg}={default_value}`."
              )
          model_kwargs[kwarg] = default_value
  
      super().__init__(
          **self._extract_torch_model_params(**model_kwargs)
      )
  
      # extract pytorch lightning module kwargs
      self.pl_module_params = self._extract_pl_module_params(
          **model_kwargs
      )
  
      # check we got right model type specified:
      if model not in ["RNN", "LSTM", "GRU"]:
          if not inspect.isclass(model) or not issubclass(
              model, CustomRNNModule
          ):
              raise_log(
                  ValueError(
                      "`model` is not a valid RNN model. Please specify 'RNN', 'LSTM', 'GRU', or give a subclass "
                      "(not an instance) of darts.models.forecasting.rnn_model.CustomRNNModule."
                  ),
                  logger=logger,
              )
  
      self.rnn_type_or_module = model
      self.dropout = dropout
      self.hidden_dim = hidden_dim
      self.n_rnn_layers = n_rnn_layers
      self.training_length = training_length
  
imports: import inspect
  from abc import ABC, abstractmethod
  from typing import Optional, Sequence, Tuple, Type, Union
  import torch
  import torch.nn
  from darts.logging import get_logger, raise_if_not, raise_log
  from darts.models.forecasting.pl_forecasting_module import PLDualCovariatesModule, io_processor
  from darts.models.forecasting.torch_forecasting_model import DualCovariatesTorchModel
  from darts.timeseries import TimeSeries
  from darts.utils.data import DualCovariatesShiftedDataset, TrainingDataset
label_desc: Use image node_id 1 to create a new RNNModel object from inherited base classes: DualCovariatesTorchModel with example: obj = RNNModel(input_chunk_length, model, hidden_dim, n_rnn_layers, dropout, training_length)