docstr: Get samples to compute the final loss. These are samples directly drawn
  from the given `distr` if coherence is not enforced yet; otherwise the
  drawn samples are reconciled.
  
  Parameters
  ----------
  distr
      Distribution instances
  
  Returns
  -------
  samples
      Tensor with shape (num_samples, batch_size, seq_len, target_dim)
docstr_tok: ["Get","samples","to","compute","the","final","loss",".","These","are","samples","directly","drawn","from","the","given","`","distr","`","if","coherence","is","not","enforced","yet",";","otherwise","the","drawn","samples","are","reconciled",".","Parameters","--","--","--","--","--","distr","Distribution","instances","Returns","--","--","--","-","samples","Tensor","with","shape","(","num_samples",",","batch_size",",","seq_len",",","target_dim",")"]
code: def get_samples_for_loss(self, distr: Distribution) -> Tensor:
      """
      Get samples to compute the final loss. These are samples directly drawn
      from the given `distr` if coherence is not enforced yet; otherwise the
      drawn samples are reconciled.
  
      Parameters
      ----------
      distr
          Distribution instances
  
      Returns
      -------
      samples
          Tensor with shape (num_samples, batch_size, seq_len, target_dim)
      """
      samples = distr.sample_rep(
          num_samples=self.num_samples_for_loss, dtype="float32"
      )
  
      # Determine which epoch we are currently in.
      self.batch_no += 1
      epoch_no = self.batch_no // self.num_batches_per_epoch + 1
      epoch_frac = epoch_no / self.epochs
  
      if (
          self.coherent_train_samples
          and epoch_frac > self.warmstart_epoch_frac
      ):
          coherent_samples = reconcile_samples(
              reconciliation_mat=self.M,
              samples=samples,
              seq_axis=self.seq_axis,
          )
          assert_shape(coherent_samples, samples.shape)
          return coherent_samples
      else:
          return samples
  
imports: import logging
  from typing import List, Optional
  from itertools import product
  import mxnet
  import numpy
  from gluonts.core.component import validated
  from gluonts.mx import Tensor
  from gluonts.mx.distribution import Distribution, DistributionOutput
  from gluonts.mx.distribution import EmpiricalDistribution
  from gluonts.mx.util import assert_shape
  from gluonts.mx.distribution import LowrankMultivariateGaussian
  from gluonts.mx.model.deepvar._network import DeepVARNetwork, DeepVARTrainingNetwork, DeepVARPredictionNetwork
label_desc: Use image node_id 2 for calling the DeepVARHierarchicalNetwork obj's underlying member method code with example usage: obj.get_samples_for_loss(distr) and returns: coherent_samples, samples