docstr: Forward network
docstr_tok: ["Forward","network"]
code: def forward(
      self, x: Dict[str, torch.Tensor], n_samples: int = None
  ) -> Dict[str, torch.Tensor]:
      """
      Forward network
      """
      hidden_state = self.encode(x)
      # decode
      input_vector = self.construct_input_vector(
          x["decoder_cat"],
          x["decoder_cont"],
          one_off_target=x["encoder_cont"][
              torch.arange(
                  x["encoder_cont"].size(0),
                  device=x["encoder_cont"].device,
              ),
              x["encoder_lengths"] - 1,
              self.target_positions.unsqueeze(-1),
          ].T.contiguous(),
      )
  
      if self.training:
          assert (
              n_samples is None
          ), "cannot sample from decoder when training"
      output = self.decode(
          input_vector,
          decoder_lengths=x["decoder_lengths"],
          target_scale=x["target_scale"],
          hidden_state=hidden_state,
          n_samples=n_samples,
      )
      # return relevant part
      return self.to_network_output(prediction=output)
  
imports: from copy import copy, deepcopy
  from typing import Any, Dict, List, Literal, Optional, Tuple, Union
  import numpy
  import pandas
  import torch
  import torch.nn
  from torch.utils.data.dataloader import DataLoader
  from pytorch_forecasting.data.encoders import EncoderNormalizer, MultiNormalizer, NaNLabelEncoder
  from pytorch_forecasting.data.timeseries import TimeSeriesDataSet
  from pytorch_forecasting.metrics import MAE, MAPE, MASE, RMSE, SMAPE, DistributionLoss, Metric, MultiLoss, MultivariateDistributionLoss, NormalDistributionLoss
  from pytorch_forecasting.models.base_model import AutoRegressiveBaseModelWithCovariates, Prediction
  from pytorch_forecasting.models.nn import HiddenState, MultiEmbedding, get_rnn
  from pytorch_forecasting.utils import apply_to_list, to_list
label_desc: Use image node_id 7 for calling the DeepAR obj's underlying member method code with example usage: obj.forward(x, n_samples) and returns: self