code: def forced_replace(out, x, y):
      """
      Check all internal values of the graph that compute the variable ``out``
      for occurrences of values identical with ``x``. If such occurrences are
      encountered then they are replaced with variable ``y``.
  
      Parameters
      ----------
      out : PyTensor Variable
      x : PyTensor Variable
      y : PyTensor Variable
  
      Examples
      --------
      out := sigmoid(wu)*(1-sigmoid(wu))
      x := sigmoid(wu)
      forced_replace(out, x, y) := y*(1-y)
  
      Notes
      -----
      When it find a match, it don't continue on the corresponding inputs.
      """
      if out is None:
          return None
  
      # ``visited`` is a set of nodes that are already known and don't need to be
      # checked again, speeding up the traversal of multiply-connected graphs.
      visited = set()
      from collections import deque
  
      q = deque()
      q.append(out)
      to_replace = []
      while q:
          graph = q.popleft()
          if graph in visited:
              continue
          visited.add(graph)
          if equal_computations([graph], [x]):
              to_replace.append((graph, y))
          elif graph.owner:
              q.extendleft(graph.owner.inputs)
  
      if len(to_replace) == 0:
          return out
      return clone_replace(out, replace=to_replace)
  
imports: import copy
  import dataclasses
  import logging
  from collections import OrderedDict, namedtuple
  from collections.abc import Sequence
  from itertools import chain
  from typing import TYPE_CHECKING, Callable, Optional, Union
  from typing import cast
  import numpy
  from pytensor import scalar
  from pytensor import tensor
  from pytensor.compile.profiling import ProfileStats
  from pytensor.configdefaults import config
  from pytensor.graph.basic import Constant, Variable, equal_computations, graph_inputs
  from pytensor.graph.op import get_test_value
  from pytensor.graph.replace import clone_replace
  from pytensor.graph.type import HasDataType
  from pytensor.graph.utils import TestValueError
  from pytensor.tensor.basic import AllocEmpty, cast
  from pytensor.tensor.subtensor import set_subtensor
  from pytensor.tensor.variable import TensorConstant
label_desc: Use image node_id 9 for calling a global function with example usage: forced_replace(out, x, y) and returns: clone_replace, None, out