docstr: PyTorch module implementing the N-HiTS architecture.
  
  Parameters
  ----------
  input_dim
      The number of input components (target + optional covariates)
  output_dim
      Number of output components in the target
  nr_params
      The number of parameters of the likelihood (or 1 if no likelihood is used).
  num_stacks
      The number of stacks that make up the whole model.
  num_blocks
      The number of blocks making up every stack.
  num_layers
      The number of fully connected layers preceding the final forking layers in each block of every stack.
  layer_widths
      Determines the number of neurons that make up each fully connected layer in each block of every stack.
      If a list is passed, it must have a length equal to `num_stacks` and every entry in that list corresponds
      to the layer width of the corresponding stack. If an integer is passed, every stack will have blocks
      with FC layers of the same width.
  pooling_kernel_sizes
      size of pooling kernels for every stack and every block
  n_freq_downsample
      downsampling factors to apply for every stack and every block
  batch_norm
      Whether to apply batch norm on first block of the first stack
  dropout
      Dropout probability
  activation
      The activation function of encoder/decoder intermediate layer.
  MaxPool1d
      Use MaxPool1d pooling. False uses AvgPool1d
  **kwargs
      all parameters required for :class:`darts.model.forecasting_models.PLForecastingModule` base class.
  
  Inputs
  ------
  x of shape `(batch_size, input_chunk_length)`
      Tensor containing the input sequence.
  
  Outputs
  -------
  y of shape `(batch_size, output_chunk_length, target_size/output_dim, nr_params)`
      Tensor containing the output of the NBEATS module.
docstr_tok: ["PyTorch","module","implementing","the","N-HiTS","architecture",".","Parameters","--","--","--","--","--","input_dim","The","number","of","input","components","(","target","+","optional","covariates",")","output_dim","Number","of","output","components","in","the","target","nr_params","The","number","of","parameters","of","the","likelihood","(","or","1","if","no","likelihood","is","used",")",".","num_stacks","The","number","of","stacks","that","make","up","the","whole","model",".","num_blocks","The","number","of","blocks","making","up","every","stack",".","num_layers","The","number","of","fully","connected","layers","preceding","the","final","forking","layers","in","each","block","of","every","stack",".","layer_widths","Determines","the","number","of","neurons","that","make","up","each","fully","connected","layer","in","each","block","of","every","stack",".","If","a","list","is","passed",",","it","must","have","a","length","equal","to","`","num_stacks","`","and","every","entry","in","that","list","corresponds","to","the","layer","width","of","the","corresponding","stack",".","If","an","integer","is","passed",",","every","stack","will","have","blocks","with","FC","layers","of","the","same","width",".","pooling_kernel_sizes","size","of","pooling","kernels","for","every","stack","and","every","block","n_freq_downsample","downsampling","factors","to","apply","for","every","stack","and","every","block","batch_norm","Whether","to","apply","batch","norm","on","first","block","of","the","first","stack","dropout","Dropout","probability","activation","The","activation","function","of","encoder\/decoder","intermediate","layer",".","MaxPool1d","Use","MaxPool1d","pooling",".","False","uses","AvgPool1d","*","*","kwargs","all","parameters","required","for",":","class",":","`","darts.model.forecasting_models.PLForecastingModule","`","base","class",".","Inputs","--","--","--","x","of","shape","`","(","batch_size",",","input_chunk_length",")","`","Tensor","containing","the","input","sequence",".","Outputs","--","--","--","-","y","of","shape","`","(","batch_size",",","output_chunk_length",",","target_size\/output_dim",",","nr_params",")","`","Tensor","containing","the","output","of","the","NBEATS","module","."]
code: def __init__(
      self,
      input_dim: int,
      output_dim: int,
      nr_params: int,
      num_stacks: int,
      num_blocks: int,
      num_layers: int,
      layer_widths: List[int],
      pooling_kernel_sizes: Tuple[Tuple[int]],
      n_freq_downsample: Tuple[Tuple[int]],
      batch_norm: bool,
      dropout: float,
      activation: str,
      MaxPool1d: bool,
      **kwargs,
  ):
      """PyTorch module implementing the N-HiTS architecture.
  
      Parameters
      ----------
      input_dim
          The number of input components (target + optional covariates)
      output_dim
          Number of output components in the target
      nr_params
          The number of parameters of the likelihood (or 1 if no likelihood is used).
      num_stacks
          The number of stacks that make up the whole model.
      num_blocks
          The number of blocks making up every stack.
      num_layers
          The number of fully connected layers preceding the final forking layers in each block of every stack.
      layer_widths
          Determines the number of neurons that make up each fully connected layer in each block of every stack.
          If a list is passed, it must have a length equal to `num_stacks` and every entry in that list corresponds
          to the layer width of the corresponding stack. If an integer is passed, every stack will have blocks
          with FC layers of the same width.
      pooling_kernel_sizes
          size of pooling kernels for every stack and every block
      n_freq_downsample
          downsampling factors to apply for every stack and every block
      batch_norm
          Whether to apply batch norm on first block of the first stack
      dropout
          Dropout probability
      activation
          The activation function of encoder/decoder intermediate layer.
      MaxPool1d
          Use MaxPool1d pooling. False uses AvgPool1d
      **kwargs
          all parameters required for :class:`darts.model.forecasting_models.PLForecastingModule` base class.
  
      Inputs
      ------
      x of shape `(batch_size, input_chunk_length)`
          Tensor containing the input sequence.
  
      Outputs
      -------
      y of shape `(batch_size, output_chunk_length, target_size/output_dim, nr_params)`
          Tensor containing the output of the NBEATS module.
  
      """
      super().__init__(**kwargs)
  
      self.input_dim = input_dim
      self.output_dim = output_dim
      self.nr_params = nr_params
      self.input_chunk_length_multi = (
          self.input_chunk_length * input_dim
      )
  
      # TODO: shouldn't this be output_dim?
      self.output_chunk_length_multi = (
          self.output_chunk_length * input_dim
      )
  
      self.stacks_list = [
          _Stack(
              self.input_chunk_length_multi,
              self.output_chunk_length_multi,
              num_blocks,
              num_layers,
              layer_widths[i],
              nr_params,
              pooling_kernel_sizes[i],
              n_freq_downsample[i],
              batch_norm=(
                  batch_norm and i == 0
              ),  # batch norm only on first block of first stack
              dropout=dropout,
              activation=activation,
              MaxPool1d=MaxPool1d,
          )
          for i in range(num_stacks)
      ]
  
      self.stacks = nn.ModuleList(self.stacks_list)
  
      # setting the last backcast "branch" to be not trainable (without next block/stack, it doesn't need to be
      # backpropagated). Removing this line would cause logtensorboard to crash, since no gradient is stored
      # on this params (the last block backcast is not part of the final output of the net).
      self.stacks_list[-1].blocks[
          -1
      ].backcast_linear_layer.requires_grad_(False)
  
imports: from typing import List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from darts.logging import get_logger, raise_if_not
  from darts.models.forecasting.pl_forecasting_module import PLPastCovariatesModule, io_processor
  from darts.models.forecasting.torch_forecasting_model import PastCovariatesTorchModel
  from darts.utils.torch import MonteCarloDropout
label_desc: Use image node_id 1 to create a new _NHiTSModule object from inherited base classes: PLPastCovariatesModule with example: obj = _NHiTSModule(input_dim, output_dim, nr_params, num_stacks, num_blocks, num_layers, layer_widths, pooling_kernel_sizes, n_freq_downsample, batch_norm, dropout, activation, MaxPool1d)