code: def replace_with_values(vars_needed, replacements=None, model=None):
      R"""
      Replace random variable nodes in the graph with values given by the replacements dict.
      Uses untransformed versions of the inputs, performs some basic input validation.
  
      Parameters
      ----------
      vars_needed: list of TensorVariables
          A list of variable outputs
      replacements: dict with string keys, numeric values
          The variable name and values to be replaced in the model graph.
      model: Model
          A PyMC model object
      """
      model = modelcontext(model)
  
      inputs, input_names = [], []
      for rv in ancestors(vars_needed):
          if rv in model.named_vars.values() and not isinstance(
              rv, SharedVariable
          ):
              inputs.append(rv)
              input_names.append(rv.name)
  
      # Then it's deterministic, no inputs are required, can eval and return
      if len(inputs) == 0:
          return tuple(v.eval() for v in vars_needed)
  
      fn = compile_pymc(
          inputs,
          vars_needed,
          allow_input_downcast=True,
          accept_inplace=True,
          on_unused_input="ignore",
      )
  
      # Remove unneeded inputs
      replacements = {
          name: val
          for name, val in replacements.items()
          if name in input_names
      }
      missing = set(input_names) - set(replacements.keys())
  
      # Error if more inputs are needed
      if len(missing) > 0:
          missing_str = ", ".join(missing)
          raise ValueError(
              f"Values for {missing_str} must be included in `replacements`."
          )
  
      return fn(**replacements)
  
file_path: pymc/pymc/gp/util.py
imports: import warnings
  import numpy
  import pytensor.tensor
  from pytensor.compile import SharedVariable
  from pytensor.graph import ancestors
  from pytensor.tensor.variable import TensorConstant
  from scipy.cluster.vq import kmeans
  from pymc.distributions.distribution import Distribution
  from pymc.model import modelcontext
  from pymc.pytensorf import compile_pymc
label_desc: Use image node_id 1 for calling a global function with example usage: replace_with_values(vars_needed, replacements, model) and returns: fn, tuple