docstr: Computes sample paths by decoding from the transformer.
  Parameters
  ----------
  static_feat : Tensor
      static features. Shape: (batch_size, num_static_features).
  past_target : Tensor
      target history. Shape: (batch_size, history_length, 1).
  time_feat : Tensor
      time features. Shape: (batch_size, prediction_length, num_time_features).
  scale : Tensor
      tensor containing the scale of each element in the batch. Shape: (batch_size, ).
  enc_out: Tensor
      output of the encoder. Shape: (batch_size, num_cells)
  Returns
  --------
  sample_paths : Tensor
      a tensor containing sampled paths. Shape: (batch_size, num_sample_paths, prediction_length).
docstr_tok: ["Computes","sample","paths","by","decoding","from","the","transformer",".","Parameters","--","--","--","--","--","static_feat",":","Tensor","static","features",".","Shape",":","(","batch_size",",","num_static_features",")",".","past_target",":","Tensor","target","history",".","Shape",":","(","batch_size",",","history_length",",","1",")",".","time_feat",":","Tensor","time","features",".","Shape",":","(","batch_size",",","prediction_length",",","num_time_features",")",".","scale",":","Tensor","tensor","containing","the","scale","of","each","element","in","the","batch",".","Shape",":","(","batch_size",",",")",".","enc_out",":","Tensor","output","of","the","encoder",".","Shape",":","(","batch_size",",","num_cells",")","Returns","--","--","--","--","sample_paths",":","Tensor","a","tensor","containing","sampled","paths",".","Shape",":","(","batch_size",",","num_sample_paths",",","prediction_length",")","."]
code: def sampling_decoder(
      self,
      static_feat: torch.Tensor,
      past_target: torch.Tensor,
      time_feat: torch.Tensor,
      scale: torch.Tensor,
      enc_out: torch.Tensor,
  ) -> torch.Tensor:
      """
      Computes sample paths by decoding from the transformer.
      Parameters
      ----------
      static_feat : Tensor
          static features. Shape: (batch_size, num_static_features).
      past_target : Tensor
          target history. Shape: (batch_size, history_length, 1).
      time_feat : Tensor
          time features. Shape: (batch_size, prediction_length, num_time_features).
      scale : Tensor
          tensor containing the scale of each element in the batch. Shape: (batch_size, ).
      enc_out: Tensor
          output of the encoder. Shape: (batch_size, num_cells)
      Returns
      --------
      sample_paths : Tensor
          a tensor containing sampled paths. Shape: (batch_size, num_sample_paths, prediction_length).
      """
  
      # blows-up the dimension of each tensor to batch_size * self.num_parallel_samples for increasing parallelism
      repeated_past_target = past_target.repeat_interleave(
          repeats=self.num_parallel_samples, dim=0
      )
  
      repeated_time_feat = time_feat.repeat_interleave(
          repeats=self.num_parallel_samples, dim=0
      )
  
      repeated_static_feat = static_feat.repeat_interleave(
          repeats=self.num_parallel_samples, dim=0
      ).unsqueeze(1)
  
      repeated_enc_out = enc_out.repeat_interleave(
          repeats=self.num_parallel_samples, dim=1
      )
  
      repeated_scale = scale.repeat_interleave(
          repeats=self.num_parallel_samples, dim=0
      )
  
      future_samples = []
  
      # for each future time-units we draw new samples for this time-unit and update the state
      for k in range(self.prediction_length):
          lags = self.get_lagged_subsequences(
              sequence=repeated_past_target,
              sequence_length=self.history_length + k,
              indices=self.shifted_lags,
              subsequences_length=1,
          )
  
          # (batch_size * num_samples, 1, *target_shape, num_lags)
          lags_scaled = lags / repeated_scale.unsqueeze(1)
          # lags_scaled = F.broadcast_div(
          #     lags, repeated_scale.expand_dims(axis=-1)
          # )
  
          # from (batch_size * num_samples, 1, *target_shape, num_lags)
          # to (batch_size * num_samples, 1, prod(target_shape) * num_lags)
          input_lags = lags_scaled.reshape(
              shape=(
                  -1,
                  1,
                  prod(self.target_shape) * len(self.lags_seq),
              )
          )
  
          # (batch_size * num_samples, 1, prod(target_shape) * num_lags + num_time_features + num_static_features)
          dec_input = torch.cat(
              (
                  input_lags,
                  repeated_time_feat[:, k : k + 1, :],
                  repeated_static_feat,
              ),
              dim=-1,
          )
  
          dec_output = self.transformer.decoder(
              self.decoder_input(dec_input).permute(1, 0, 2),
              repeated_enc_out,
          )
  
          distr_args = self.proj_dist_args(dec_output.permute(1, 0, 2))
  
          # compute likelihood of target given the predicted parameters
          distr = self.distr_output.distribution(
              distr_args, scale=repeated_scale
          )
  
          # (batch_size * num_samples, 1, *target_shape)
          new_samples = distr.sample()
  
          # (batch_size * num_samples, seq_len, *target_shape)
          repeated_past_target = torch.cat(
              (repeated_past_target, new_samples), dim=1
          )
          future_samples.append(new_samples)
  
      # reset cache of the decoder
      # self.transformer.decoder.cache_reset()
  
      # (batch_size * num_samples, prediction_length, *target_shape)
      samples = torch.cat(future_samples, dim=1)
  
      # (batch_size, num_samples, *target_shape, prediction_length)
      return samples.reshape(
          (
              (-1, self.num_parallel_samples)
              + self.target_shape
              + (self.prediction_length,)
          )
      )
  
file_path: gluonts/src/gluonts/nursery/robust-mts-attack/pts/model/transformer/transformer_network.py
imports: from typing import List, Optional, Tuple
  import torch
  import torch.nn
  from gluonts.core.component import validated
  from gluonts.torch.modules.distribution_output import DistributionOutput
  from pts.modules import MeanScaler, NOPScaler, FeatureEmbedder
label_desc: Use image node_id 2 for calling the TransformerPredictionNetwork obj's underlying member method code with example usage: obj.sampling_decoder(static_feat, past_target, time_feat, scale, enc_out) and returns: samples