code: def _expand_and_update_baselines(
      inputs: Tuple[Tensor, ...],
      n_samples: int,
      kwargs: dict,
      draw_baseline_from_distrib: bool = False,
  ):
      def get_random_baseline_indices(bsz, baseline):
          num_ref_samples = baseline.shape[0]
          return np.random.choice(
              num_ref_samples, n_samples * bsz
          ).tolist()
  
      # expand baselines to match the sizes of input
      if "baselines" not in kwargs:
          return
  
      baselines = kwargs["baselines"]
      baselines = _format_baseline(baselines, inputs)
      _validate_input(
          inputs,
          baselines,
          draw_baseline_from_distrib=draw_baseline_from_distrib,
      )
  
      if draw_baseline_from_distrib:
          bsz = inputs[0].shape[0]
          baselines = tuple(
              baseline[get_random_baseline_indices(bsz, baseline)]
              if isinstance(baseline, torch.Tensor)
              else baseline
              for baseline in baselines
          )
      else:
          baselines = tuple(
              baseline.repeat_interleave(n_samples, dim=0)
              if isinstance(baseline, torch.Tensor)
              and baseline.shape[0] == input.shape[0]
              and baseline.shape[0] > 1
              else baseline
              for input, baseline in zip(inputs, baselines)
          )
      # update kwargs with expanded baseline
      kwargs["baselines"] = baselines
  
imports: import typing
  from enum import Enum
  from functools import reduce
  from inspect import signature
  from typing import Any, Callable, cast, Dict, List, overload, Tuple, Union
  import numpy
  import torch
  from captum._utils.typing import BaselineType, Literal, TargetType, TensorOrTupleOfTensorsGeneric, TupleOrTensorOrBoolGeneric
  from torch import device, Tensor
  from torch.nn import Module
label_desc: Use image node_id 24 for calling a global function with example usage: _expand_and_update_baselines(inputs, n_samples, kwargs, draw_baseline_from_distrib) and returns: np