def __init__(
        self,
        input_size: int,
        output_size: int,
        nr_params: int,
        d_model: int,
        nhead: int,
        num_encoder_layers: int,
        num_decoder_layers: int,
        dim_feedforward: int,
        dropout: float,
        activation: str,
        norm_type: Union[str, nn.Module, None] = None,
        custom_encoder: Optional[nn.Module] = None,
        custom_decoder: Optional[nn.Module] = None,
        **kwargs,
    ):
        """PyTorch module implementing a Transformer to be used in `TransformerModel`.

        PyTorch module implementing a simple encoder-decoder transformer architecture.

        Parameters
        ----------
        input_size
            The dimensionality of the TimeSeries instances that will be fed to the the fit and predict functions.
        output_size
            The dimensionality of the output time series.
        nr_params
            The number of parameters of the likelihood (or 1 if no likelihood is used).
        d_model
            The number of expected features in the transformer encoder/decoder inputs.
        nhead
            The number of heads in the multiheadattention model.
        num_encoder_layers
            The number of encoder layers in the encoder.
        num_decoder_layers
            The number of decoder layers in the decoder.
        dim_feedforward
            The dimension of the feedforward network model.
        dropout
            Fraction of neurons affected by Dropout.
        activation
            The activation function of encoder/decoder intermediate layer.
        norm_type: str | nn.Module | None
            The type of LayerNorm variant to use.
        custom_encoder
            A custom transformer encoder provided by the user (default=None).
        custom_decoder
            A custom transformer decoder provided by the user (default=None).
        **kwargs
            All parameters required for :class:`darts.models.forecasting.pl_forecasting_module.PLForecastingModule`
            base class.

        Inputs
        ------
        x of shape `(batch_size, input_chunk_length, input_size)`
            Tensor containing the features of the input sequence.

        Outputs
        -------
        y of shape `(batch_size, output_chunk_length, target_size, nr_params)`
            Tensor containing the prediction at the last time step of the sequence.
        """

        super().__init__(**kwargs)

        self.input_size = input_size
        self.target_size = output_size
        self.nr_params = nr_params
        self.target_length = self.output_chunk_length

        self.encoder = nn.Linear(input_size, d_model)
        self.positional_encoding = _PositionalEncoding(
            d_model, dropout, self.input_chunk_length
        )

        if isinstance(norm_type, str):
            try:
                self.layer_norm = getattr(layer_norm_variants, norm_type)
            except AttributeError:
                raise_log(
                    AttributeError("please provide a valid layer norm type"),
                )
        else:
            self.layer_norm = norm_type

        raise_if_not(activation in FFN, f"'{activation}' is not in {FFN}")
        if activation in GLU_FFN:
            raise_if(
                custom_encoder is not None or custom_decoder is not None,
                "Cannot use `custom_encoder` or `custom_decoder` along with an `activation` from "
                f"{GLU_FFN}",
                logger=logger,
            )
            # use glu variant feed-forward layers
            ffn_cls = getattr(glu_variants, activation)

            # custom feed-forward layers have activation built-in. reset activation
            activation = None

            custom_encoder = _generate_coder(
                d_model,
                dim_feedforward,
                dropout,
                nhead,
                num_encoder_layers,
                self.layer_norm if self.layer_norm else nn.LayerNorm,
                coder_cls=nn.TransformerEncoder,
                layer_cls=CustomFeedForwardEncoderLayer,
                ffn_cls=ffn_cls,
            )

            custom_decoder = _generate_coder(
                d_model,
                dim_feedforward,
                dropout,
                nhead,
                num_decoder_layers,
                self.layer_norm if self.layer_norm else nn.LayerNorm,
                coder_cls=nn.TransformerDecoder,
                layer_cls=CustomFeedForwardDecoderLayer,
                ffn_cls=ffn_cls,
            )

        # if layer norm set and no GLU variant is used
        if self.layer_norm and custom_decoder is None:
            custom_encoder = _generate_coder(
                d_model,
                dim_feedforward,
                dropout,
                nhead,
                num_encoder_layers,
                self.layer_norm,
                coder_cls=nn.TransformerEncoder,
                layer_cls=nn.TransformerEncoderLayer,
                ffn_cls=None,
            )

            custom_decoder = _generate_coder(
                d_model,
                dim_feedforward,
                dropout,
                nhead,
                num_decoder_layers,
                self.layer_norm,
                coder_cls=nn.TransformerDecoder,
                layer_cls=nn.TransformerDecoderLayer,
                ffn_cls=None,
            )

        # Defining the Transformer module
        self.transformer = nn.Transformer(
            d_model=d_model,
            nhead=nhead,
            num_encoder_layers=num_encoder_layers,
            num_decoder_layers=num_decoder_layers,
            dim_feedforward=dim_feedforward,
            dropout=dropout,
            activation=activation,
            custom_encoder=custom_encoder,
            custom_decoder=custom_decoder,
        )

        self.decoder = nn.Linear(
            d_model, self.target_length * self.target_size * self.nr_params
        )
PyTorch module implementing a Transformer to be used in `TransformerModel`.

        PyTorch module implementing a simple encoder-decoder transformer architecture.

        Parameters
        ----------
        input_size
            The dimensionality of the TimeSeries instances that will be fed to the the fit and predict functions.
        output_size
            The dimensionality of the output time series.
        nr_params
            The number of parameters of the likelihood (or 1 if no likelihood is used).
        d_model
            The number of expected features in the transformer encoder/decoder inputs.
        nhead
            The number of heads in the multiheadattention model.
        num_encoder_layers
            The number of encoder layers in the encoder.
        num_decoder_layers
            The number of decoder layers in the decoder.
        dim_feedforward
            The dimension of the feedforward network model.
        dropout
            Fraction of neurons affected by Dropout.
        activation
            The activation function of encoder/decoder intermediate layer.
        norm_type: str | nn.Module | None
            The type of LayerNorm variant to use.
        custom_encoder
            A custom transformer encoder provided by the user (default=None).
        custom_decoder
            A custom transformer decoder provided by the user (default=None).
        **kwargs
            All parameters required for :class:`darts.models.forecasting.pl_forecasting_module.PLForecastingModule`
            base class.

        Inputs
        ------
        x of shape `(batch_size, input_chunk_length, input_size)`
            Tensor containing the features of the input sequence.

        Outputs
        -------
        y of shape `(batch_size, output_chunk_length, target_size, nr_params)`
            Tensor containing the prediction at the last time step of the sequence.
        
darts/models/forecasting/transformer_model.py