code: def _compute_stage_value(
      model: Model,
      valfunc_cls: Optional[Type[AcquisitionFunction]],
      X: Tensor,
      objective: MCAcquisitionObjective,
      posterior_transform: Optional[PosteriorTransform],
      inner_sampler: Optional[MCSampler] = None,
      arg_fac: Optional[TAcqfArgConstructor] = None,
  ) -> Optional[Tensor]:
      r"""Compute the stage value of a multi-step look-ahead policy.
  
      Args:
          model: A Model of appropriate batch size. Specifically, it must be possible to
              evaluate the model's posterior at `Xs[0]`.
          valfunc_cls: The acquisition function class to be used as the stage value
              functions. If `None`, a zero stage value is assumed (returns `None`)
          X: A tensor with shape `f_i x .... x f_1 x batch_shape x q_i x d` when called in
              the `i`-th step.
          objective: The MCAcquisitionObjective under which the model output is evaluated.
          posterior_transform: A PosteriorTransform.
          inner_sampler: An `MCSampler` object to be used in the stage value function. Can
              be `None` for analytic acquisition functions or when using the default
              sampler of the acquisition function class.
          arg_fac: A callable mapping a `Model` and the input tensor `X` to a dictionary
              of kwargs for the stage value function constructor. If `None`, only the
              standard `model`, `sampler` and `objective` kwargs will be used.
  
      Returns:
          A `f_i x ... x f_1 x batch_shape`-dim tensor of stage values, or `None`
          (= zero stage value).
      """
      if valfunc_cls is None:
          return None
      common_kwargs: Dict[str, Any] = {
          "model": model,
          "posterior_transform": posterior_transform,
      }
      if issubclass(valfunc_cls, MCAcquisitionFunction):
          common_kwargs["sampler"] = inner_sampler
          common_kwargs["objective"] = objective
      kwargs = arg_fac(model=model, X=X) if arg_fac is not None else {}
      stage_val_func = valfunc_cls(**common_kwargs, **kwargs)
      # shape of stage_val is f_i x ... x f_1 x batch_shape
      stage_val = stage_val_func(X=X)
      return stage_val
  
imports: from __future__ import annotations
  import math
  import warnings
  from typing import Any, Callable, Dict, List, Optional, Tuple, Type
  import numpy
  import torch
  from botorch.acquisition import AcquisitionFunction, OneShotAcquisitionFunction
  from botorch.acquisition.analytic import AnalyticAcquisitionFunction, PosteriorMean
  from botorch.acquisition.monte_carlo import MCAcquisitionFunction
  from botorch.acquisition.objective import MCAcquisitionObjective, PosteriorTransform
  from botorch.exceptions.errors import UnsupportedError
  from botorch.exceptions.warnings import BotorchWarning
  from botorch.models.model import Model
  from botorch.optim.initializers import initialize_q_batch
  from botorch.sampling.base import MCSampler
  from botorch.sampling.normal import SobolQMCNormalSampler
  from botorch.utils.transforms import match_batch_shape, t_batch_mode_transform, unnormalize
  from torch import Size, Tensor
  from torch.distributions import Beta
  from torch.nn import ModuleList
label_desc: Use image node_id 2 for calling a global function with example usage: _compute_stage_value(model, valfunc_cls, X, objective, posterior_transform, inner_sampler, arg_fac) and returns: stage_val, None