code: def forward(
      self,
      net: Tensor,
      state: Optional[TrainerState] = None,
      *,
      get_quantiles: bool = True,
      get_cdf: bool = True,
      get_mean: Optional[bool] = None,
      tau: Optional[TCond] = None,
      y_anchor: Optional[TCond] = None,
  ) -> tensor_dict_type:
      # prepare
      device = net.device
      num_samples = len(net)
      if len(net.shape) > 2:
          net = net.contiguous().view(num_samples, -1)
      get_quantiles = get_quantiles and self.predict_quantiles
      get_cdf = get_cdf and self.predict_cdf
      if not self.training:
          if (
              get_mean is None
              and get_quantiles
              and self.use_mean_correction
          ):
              get_mean = True
      else:
          if (
              state is not None
              and self.use_mean_correction
              and (
                  self.dual_period is None
                  or state.step % self.dual_period == 0
              )
          ):
              get_mean = True
          else:
              get_mean = False
      if get_mean and not get_quantiles:
          print_warning(
              "`get_mean` is set to `True` but `get_quantiles` is `False`, "
              "so `get_mean` will fallback to `False`"
          )
          get_mean = False
      # median / modulator forward
      mods = []
      q_mods = []
      cdf_mods = []
      q_net = None
      cdf_net = None
      for i, block in enumerate(self.fcnn.net):
          is_last = i == len(self.fcnn.net) - 1
          if not is_last and self.q_mod is not None:
              q_net = net if q_net is None else q_net + net
          if not is_last and self.cdf_mod is not None:
              cdf_net = net if cdf_net is None else cdf_net + net
          net = block(net)
          mods.append(net)
          if not is_last:
              if self.q_mod is not None:
                  q_net = self.q_mod.net[i](q_net)
                  q_mods.append(q_net)
              if self.cdf_mod is not None:
                  cdf_net = self.cdf_mod.net[i](cdf_net)
                  cdf_mods.append(cdf_net)
      q_mods = q_mods or mods
      cdf_mods = cdf_mods or mods
      median = mods.pop()
      results = {PREDICTIONS_KEY: median}
      if not get_quantiles and not get_cdf:
          return results
      y_min, y_max = self.y_min_max.tolist()  # type: ignore
      y_span = y_max - y_min
      # quantile forward
      if get_quantiles:
          if tau is not None:
              tau_tensor = (
                  _expand_element(num_samples, tau, device) * 2.0 - 1.0
              )
          else:
              if self.training:
                  shape = num_samples, self.num_random_samples, 1
                  tau_tensor = (
                      torch.rand(*shape, device=device) * 2.0 - 1.0
                  )
              else:
                  tau_tensor = _make_ddr_grid(
                      self.num_random_samples, device
                  )
                  tau_tensor = tau_tensor.repeat(num_samples, 1, 1)
          tau_tensor.requires_grad_(True)
          q_increment, quantiles = self._get_quantiles(
              tau_tensor, q_mods, median
          )
          results.update(
              {
                  "tau": tau_tensor,
                  "q_increment": q_increment,
                  "quantiles": quantiles,
              }
          )
          ## mean forward
          if get_mean:
              tau_mu = _make_ddr_grid(self.num_mean_samples, device)
              tau_mu = tau_mu.repeat(num_samples, 1, 1)
              _, quantiles_mu = self._get_quantiles(
                  tau_mu, q_mods, median.detach()
              )
              delta = 0.5 / self.num_mean_samples
              sliding_sum = quantiles_mu[:, 1:] + quantiles_mu[:, :-1]
              results["mean"] = delta * sliding_sum.sum(1)
      # cdf forward
      if get_cdf:
          if y_anchor is not None:
              ya_tensor = _expand_element(num_samples, y_anchor, device)
          else:
              shape = num_samples, self.num_random_samples, 1
              if self.training:
                  ya_tensor = (
                      torch.rand(*shape, device=device) * y_span + y_min
                  )
              else:
                  y_raw_ratio = _make_ddr_grid(
                      self.num_random_samples, device
                  )
                  y_raw_ratio = 0.5 * (y_raw_ratio + 1.0)
                  ya_tensor = (y_raw_ratio * y_span + y_min).repeat(
                      num_samples, 1, 1
                  )
          ya_tensor.requires_grad_(True)
          _, logit, cdf = self._get_cdf(
              ya_tensor, median, y_span, cdf_mods
          )
          pdf = get_gradient(cdf, ya_tensor, True, True)  # type: ignore
          results.update(
              {
                  "y_anchor": ya_tensor,
                  "logit": logit,
                  "cdf": cdf,
                  "pdf": pdf,
              }
          )
      # dual forward
      if (
          get_quantiles
          and get_cdf
          and (
              state is None
              or not self.training
              or self.dual_period is None
              or state.step % self.dual_period == 0
          )
      ):
          dual_y = results["quantiles"].detach()
          results["dual_cdf"] = self._get_cdf(
              dual_y, median, y_span, cdf_mods
          )[-1]
          if self.use_dual_quantiles:
              dual_quantiles_args = results["cdf"], q_mods, median
              _, results["dual_quantiles"] = self._get_quantiles(
                  *dual_quantiles_args
              )
      return results
  
imports: import torch
  import numpy
  import torch.nn.functional
  from torch import Tensor
  from typing import Any
  from typing import Dict
  from typing import List
  from typing import Tuple
  from typing import Union
  from typing import Optional
  from cftool.misc import print_warning
  from cftool.types import tensor_dict_type
  from .base import MLModel
  from .fcnn import FCNN
  from ...types import losses_type
  from ...schema import ILoss
  from ...schema import ITrainer
  from ...schema import TrainerState
  from ...schema import MLEncoderSettings
  from ...schema import MLGlobalEncoderSettings
  from ...constants import LOSS_KEY
  from ...constants import INPUT_KEY
  from ...constants import LABEL_KEY
  from ...constants import PREDICTIONS_KEY
  from ..implicit.siren import make_grid
  from ..implicit.siren import Siren
  from ...misc.toolkit import get_gradient
label_desc: Use image node_id 2 for calling the DDR obj's underlying member method code with example usage: obj.forward(net, state) and returns: results, results