code: def replace_rvs_by_values(
      graphs: Sequence[TensorVariable],
      *,
      rvs_to_values: Dict[TensorVariable, TensorVariable],
      rvs_to_transforms: Optional[
          Dict[TensorVariable, "Transform"]
      ] = None,
  ) -> List[TensorVariable]:
      """Clone and replace random variables in graphs with their value variables.
  
      Parameters
      ----------
      graphs
          The graphs in which to perform the replacements.
      rvs_to_values
          Mapping between the original graph RVs and respective value variables
      rvs_to_transforms, optional
          Mapping between the original graph RVs and respective value transforms
      """
  
      if rvs_to_transforms:
          # Conditional transforms like Interval can reference variables in the original RV graph
          # To avoid mutating the original graphs in place, we have to clone them
          inputs = [
              i
              for i in graph_inputs(graphs)
              if not isinstance(i, Constant)
          ]
          equiv = clone_get_equiv(inputs, graphs, False, False)
  
          graphs = [equiv[g] for g in graphs]
          rvs_to_values = {
              equiv.get(rv, rv): value
              for rv, value in rvs_to_values.items()
          }
          rvs_to_transforms = {
              equiv.get(rv, rv): transform
              for rv, transform in rvs_to_transforms.items()
          }
  
      replacements = {}
  
      def populate_replacements(var):
          # Populate replacements dict with {rv: value} pairs indicating which graph
          # RVs should be replaced by what value variables.
          if not var.owner:
              return []
  
          next_vars = []
          value = rvs_to_values.get(var, None)
          if value is not None:
              rv = var
  
              if rvs_to_transforms is not None:
                  transform = rvs_to_transforms.get(rv, None)
                  if transform is not None:
                      # We want to replace uses of the RV by the back-transformation of its value
                      value = transform.backward(
                          value, *rv.owner.inputs
                      )
                      # The value may have a less precise type than the rv. In this case
                      # filter_variable will add a SpecifyShape to ensure they are consistent
                      value = rv.type.filter_variable(
                          value, allow_convert=True
                      )
                      value.name = rv.name
  
              replacements[rv] = value
              # Also walk the graph of the value variable to make any additional
              # replacements if that is not a simple input variable
              next_vars.append(value)
  
          next_vars.extend(reversed(var.owner.inputs))
          return next_vars
  
      # Iterate over the generator to populate the replacements
      for _ in walk(graphs, populate_replacements, bfs=False):
          pass
  
      return replace_vars_in_graphs(graphs, replacements)
  
imports: import typing
  import warnings
  from typing import Container, Dict, List, Optional, Sequence, Set, Tuple, Union
  import numpy
  import pytensor
  from pytensor import Variable
  from pytensor import tensor
  from pytensor.graph import Apply, Op, node_rewriter
  from pytensor.graph.basic import Constant, clone_get_equiv, graph_inputs, walk
  from pytensor.graph.op import HasInnerGraph
  from pytensor.link.c.type import CType
  from pytensor.raise_op import CheckAndRaise
  from pytensor.tensor.random.op import RandomVariable
  from pytensor.tensor.variable import TensorVariable
  from pymc.logprob.abstract import MeasurableVariable, _logprob
  from pymc.pytensorf import replace_vars_in_graphs
  from pymc.util import makeiter
label_desc: Use image node_id 1 for calling a global function with example usage: replace_rvs_by_values(graphs) and returns: replace_vars_in_graphs, next_vars, list