code: def _gemm_from_node2(fgraph, node):
      """
  
      TODO: In many expressions, there are many ways to turn it into a
      gemm.  For example dot(a,b) + c + d.  This function should return all
      of them, so that if one version of gemm causes a cycle in the graph, then
      another application of gemm can be tried.
  
      """
      lst = []
      t0 = time.perf_counter()
      _gemm_canonicalize(fgraph, node.outputs[0], 1.0, lst, 0)
      t1 = time.perf_counter()
  
      if len(lst) > 1:
          lst = _factor_canonicalized(lst)
          t2 = time.perf_counter()
          rval = _gemm_from_factored_list(fgraph, lst)
          t3 = time.perf_counter()
  
          # It can happen that _factor_canonicalized and
          # _gemm_from_factored_list return a node with an incorrect
          # type.  This happens in particular when one of the scalar
          # factors forces the upcast of the whole expression.  In that
          # case, we simply skip that candidate for Gemm.  This was
          # discussed in
          # http://groups.google.com/group/theano-dev/browse_thread/thread/a3096c82856e3ad5,
          # but never made it into a trac ticket.
  
          if rval and rval[0][0].type.in_same_class(
              node.outputs[0].type
          ):
              return rval, t1 - t0, t2 - t1, t3 - t2
  
      return None, t1 - t0, 0, 0
  
imports: import copy
  import logging
  import time
  import numpy
  from pytensor.tensor.rewriting.basic import register_specialize
  import pytensor.scalar
  from pytensor.compile.mode import optdb
  from pytensor.configdefaults import config
  from pytensor.graph.features import ReplacementDidNotRemoveError, ReplaceValidate
  from pytensor.graph.rewriting.basic import EquilibriumGraphRewriter, GraphRewriter, copy_stack_trace, in2out, node_rewriter
  from pytensor.graph.rewriting.db import SequenceDB
  from pytensor.graph.utils import InconsistencyError
  from pytensor.tensor import basic
  from pytensor.tensor.blas import Dot22, _dot22, _dot22scalar, batched_dot, gemm_inplace, gemm_no_inplace, gemv_inplace, gemv_no_inplace, ger, ger_destructive
  from pytensor.tensor.elemwise import DimShuffle, Elemwise
  from pytensor.tensor.exceptions import NotScalarConstantError
  from pytensor.tensor.math import Dot, _matrix_matrix_matmul, add, mul, neg, sub
  from pytensor.tensor.rewriting.elemwise import local_dimshuffle_lift
  from pytensor.tensor.type import DenseTensorType, TensorType, integer_dtypes, values_eq_approx_remove_inf_nan
label_desc: Use image node_id 9 for calling a global function with example usage: _gemm_from_node2(fgraph, node) and returns: None,  unknown,  int,  int, rval,  unknown,  unknown,  unknown