code: def _einsum_v2(equation, *inputs, **kwargs):
      """Implementation of einsum utilizing opt_einsum and EinsumOp."""
      name = kwargs.pop("name", None)
      optimize = kwargs.pop("optimize", "greedy")
      if kwargs:
          raise TypeError(
              f'Invalid keyword arguments for einsum: {", ".join(kwargs)}. '
              f"Valid arguments: name, optimize, greedy."
          )
  
      with ops.name_scope(name, "einsum", [equation, inputs]) as name:
          inputs = list(inputs)
          input_shapes = []
          for operand in inputs:
              if isinstance(operand.shape, tensor_shape.TensorShape):
                  input_shapes.append(
                      operand.shape.as_list() if operand.shape else None
                  )
              else:
                  input_shapes.append(list(operand.shape))
          # Validate and sanitize the equation and resolve static input shapes, as
          # opt_einsum requires that all shapes be a tuple of positive integers.
          # Also remove ellipsis from the equation as opt_einsum will replace them
          # with named labels. Then broadcasting between different shapes or ranks
          # wouldn't work. (E.g. [1, 1, 2] wouldn't broadcast with [3, 1]).
          (
              resolved_equation,
              resolved_input_shapes,
              ellipsis_label,
          ) = _einsum_v2_parse_and_resolve_equation(
              equation, input_shapes
          )
  
          if len(inputs) <= 2:  # No need to call opt_einsum.
              # Replace back ellipses that were removed for opt_einsum.
              if ellipsis_label:
                  resolved_equation = resolved_equation.replace(
                      ellipsis_label, "..."
                  )
              return gen_linalg_ops.einsum(inputs, resolved_equation)
  
          # Send fully specified shapes to opt_einsum, since it cannot handle unknown
          # dimensions. For unknown dimensions, we guess that the dimension equals 1.
          # Instead of creating Tensors or NumPy arrays with the specified shape,
          # create a dummy `shaped` object with a `shape` property.
          shaped = collections.namedtuple("shaped", ["shape"])
          shaped_inputs = tuple(
              [shaped(tuple(shape)) for shape in resolved_input_shapes]
          )
          # opt_einsum breaks down an n-ary einsum operation into n-1 binary einsums.
          # Obtain the sequence of equations and the indices of operands involved in
          # each einsum operation.
          indices_and_equations = _get_opt_einsum_contract_path(
              resolved_equation, shaped_inputs, optimize
          )
          for operand_indices, binary_equation in indices_and_equations:
              if ellipsis_label:
                  # Replace back ellipses that were removed for opt_einsum.
                  binary_equation = binary_equation.replace(
                      ellipsis_label, "..."
                  )
              operands = list(map(inputs.pop, operand_indices))
              inputs.append(
                  gen_linalg_ops.einsum(operands, binary_equation)
              )
          return inputs[0]
  
imports: import collections
  import functools
  import re
  import string
  import numpy
  import opt_einsum
  from tensorflow.compiler.tf2xla.ops import gen_xla_ops
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import gen_linalg_ops
  from tensorflow.python.ops import gen_special_math_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.util import deprecation
  from tensorflow.python.util import dispatch
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 30 for calling a global function with example usage: _einsum_v2(equation) and returns: inputs, gen_linalg_ops