code: def sub_quad_attention_forward(
      self, x, context=None, mask=None, **kwargs
  ):
      assert (
          mask is None
      ), "attention-mask not currently implemented for SubQuadraticCrossAttnProcessor."
  
      h = self.heads
  
      q = self.to_q(x)
      context = default(context, x)
  
      context_k, context_v = hypernetwork.apply_hypernetworks(
          shared.loaded_hypernetworks, context
      )
      k = self.to_k(context_k)
      v = self.to_v(context_v)
      del context, context_k, context_v, x
  
      q = q.unflatten(-1, (h, -1)).transpose(1, 2).flatten(end_dim=1)
      k = k.unflatten(-1, (h, -1)).transpose(1, 2).flatten(end_dim=1)
      v = v.unflatten(-1, (h, -1)).transpose(1, 2).flatten(end_dim=1)
  
      if q.device.type == "mps":
          q, k, v = q.contiguous(), k.contiguous(), v.contiguous()
  
      dtype = q.dtype
      if shared.opts.upcast_attn:
          q, k = q.float(), k.float()
  
      x = sub_quad_attention(
          q,
          k,
          v,
          q_chunk_size=shared.cmd_opts.sub_quad_q_chunk_size,
          kv_chunk_size=shared.cmd_opts.sub_quad_kv_chunk_size,
          chunk_threshold=shared.cmd_opts.sub_quad_chunk_threshold,
          use_checkpoint=self.training,
      )
  
      x = x.to(dtype)
  
      x = x.unflatten(0, (-1, h)).transpose(1, 2).flatten(start_dim=2)
  
      out_proj, dropout = self.to_out
      x = out_proj(x)
      x = dropout(x)
  
      return x
  
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 14 for calling a global function with example usage: sub_quad_attention_forward(x, context, mask) and returns: x