code: def _fit_fallback_approximate(
      mll: _ApproximateMarginalLogLikelihood,
      _: Type[Likelihood],
      __: Type[ApproximateGPyTorchModel],
      *,
      closure: Optional[
          Callable[[], Tuple[Tensor, Sequence[Optional[Tensor]]]]
      ] = None,
      data_loader: Optional[DataLoader] = None,
      optimizer: Optional[Callable] = None,
      full_batch_limit: int = 1024,
      **kwargs: Any,
  ) -> _ApproximateMarginalLogLikelihood:
      r"""Fallback method for fitting approximate Gaussian processes.
  
      Args:
          closure: Forward-backward closure for obtaining objective values and gradients.
              Responsible for setting parameters' `grad` attributes. If no closure is
              provided, one will be obtained by calling `get_loss_closure_with_grads`.
          optimizer: The underlying optimization algorithm to run. Default to
              `fit_gpytorch_mll_scipy` when `closure=None` and the model's internal
              training set has no more than `full_batch_cutoff` observations; otherwise,
              defaults to `fit_gpytorch_mll_torch`.
          data_loader: An optional DataLoader to pass to `get_loss_closure_with_grads`.
              May only be provided when `closure=None`.
          full_batch_limit: Threshold for determining the default choice of `optimizer`
              when `closure=None`.
          **kwargs: Keyword arguments passed to `_fit_fallback`.
      """
      if data_loader is not None:
          if closure is not None:
              raise UnsupportedError(
                  "Only one of `data_loader` or `closure` may be passed."
              )
          closure = get_loss_closure_with_grads(
              mll=mll,
              data_loader=data_loader,
              parameters=get_parameters(mll, requires_grad=True),
          )
  
      if optimizer is None:
          optimizer = (
              fit_gpytorch_mll_scipy
              if closure is None
              and len(mll.model.train_targets) <= full_batch_limit
              else fit_gpytorch_mll_torch
          )
  
      return _fit_fallback(
          mll, _, __, closure=closure, optimizer=optimizer, **kwargs
      )
  
imports: from __future__ import annotations
  import logging
  from contextlib import nullcontext
  from functools import partial
  from itertools import filterfalse
  from typing import Any, Callable, Dict, Iterable, Optional, Sequence, Tuple, Type, Union
  from warnings import catch_warnings, simplefilter, warn, warn_explicit, WarningMessage
  from botorch.exceptions.errors import ModelFittingError, UnsupportedError
  from botorch.exceptions.warnings import OptimizationWarning
  from botorch.models.approximate_gp import ApproximateGPyTorchModel
  from botorch.models.fully_bayesian import SaasFullyBayesianSingleTaskGP
  from botorch.models.fully_bayesian_multitask import SaasFullyBayesianMultiTaskGP
  from botorch.models.model_list_gp_regression import ModelListGP
  from botorch.optim.closures import get_loss_closure_with_grads
  from botorch.optim.core import _LBFGSB_MAXITER_MAXFUN_REGEX
  from botorch.optim.fit import fit_gpytorch_mll_scipy, fit_gpytorch_mll_torch
  from botorch.optim.utils import _warning_handler_template, get_parameters, sample_all_priors
  from botorch.settings import debug
  from botorch.utils.context_managers import module_rollback_ctx, parameter_rollback_ctx, requires_grad_ctx, TensorCheckpoint
  from botorch.utils.dispatcher import Dispatcher, type_bypassing_encoder
  from gpytorch.likelihoods import Likelihood
  from gpytorch.mlls._approximate_mll import _ApproximateMarginalLogLikelihood
  from gpytorch.mlls.marginal_log_likelihood import MarginalLogLikelihood
  from gpytorch.mlls.sum_marginal_log_likelihood import SumMarginalLogLikelihood
  from linear_operator.utils.errors import NotPSDError
  from pyro.infer.mcmc import MCMC, NUTS
  from torch import device, Tensor
  from torch.nn import Parameter
  from torch.utils.data import DataLoader
label_desc: Use image node_id 7 for calling a global function with example usage: _fit_fallback_approximate(mll, _, __) and returns: _fit_fallback