code: def einsum_op(q, k, v):
      if q.device.type == "cuda":
          return einsum_op_cuda(q, k, v)
  
      if q.device.type == "mps":
          if (
              mem_total_gb >= 32
              and q.shape[0] % 32 != 0
              and q.shape[0] * q.shape[1] < 2**18
          ):
              return einsum_op_mps_v1(q, k, v)
          return einsum_op_mps_v2(q, k, v)
  
      # Smaller slices are faster due to L2/L3/SLC caches.
      # Tested on i7 with 8MB L3 cache.
      return einsum_op_tensor_mem(q, k, v, 32)
  
imports: from __future__ import annotations
  import math
  import psutil
  import platform
  import torch
  from torch import einsum
  from ldm.util import default
  from einops import rearrange
  from modules import shared, errors, devices, sub_quadratic_attention
  from modules.hypernetworks import hypernetwork
  import ldm.modules.attention
  import ldm.modules.diffusionmodules.model
  import sgm.modules.attention
  import sgm.modules.diffusionmodules.model
label_desc: Use image node_id 12 for calling a global function with example usage: einsum_op(q, k, v) and returns: einsum_op_tensor_mem, einsum_op_cuda, einsum_op_mps_v2, einsum_op_mps_v1