code: def einsum_op_tensor_mem(q, k, v, max_tensor_mb):
      size_mb = (
          q.shape[0]
          * q.shape[1]
          * k.shape[1]
          * q.element_size()
          // (1 << 20)
      )
      if size_mb <= max_tensor_mb:
          return einsum_op_compvis(q, k, v)
      div = 1 << int((size_mb - 1) / max_tensor_mb).bit_length()
      if div <= q.shape[0]:
          return einsum_op_slice_0(q, k, v, q.shape[0] // div)
      return einsum_op_slice_1(q, k, v, max(q.shape[1] // div, 1))
  
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 10 for calling a global function with example usage: einsum_op_tensor_mem(q, k, v, max_tensor_mb) and returns: einsum_op_slice_1, einsum_op_compvis, einsum_op_slice_0