code: def forward(
      self,
      q: torch.Tensor,
      k: torch.Tensor,
      v: torch.Tensor,
      *_,
      **__,
  ):
      # Project key and queries onto the feature map space
      k_prime = self.feature_map(k)
      q_prime = self.feature_map(q)
  
      with autocast(enabled=False):
          # The softmax kernel approximation for Favor will easily overflow
          # Force the computations here to stay in fp32 for numerical stability
          # Note that the dimensions are vastly reduced when compared to scaled_dot_product
          k_prime = self._maybe_promote(k_prime)
          q_prime = self._maybe_promote(q_prime)
          v = self._maybe_promote(v)
  
          if not self.causal:
              att_normalization = q_prime @ (
                  k_prime.transpose(-2, -1) @ torch.ones_like(v)
              )
              att_raw = q_prime @ (k_prime.transpose(-2, -1) @ v)
          else:
              # Actually compute attention
              att_raw, att_normalization = self._causal_attention(
                  k_prime, q_prime, v
              )
  
          # Normalize
          att = att_raw / att_normalization
  
      if self.attn_drop is not None:
          att = self.attn_drop(att)
  
      return att
  
file_path: xformers/xformers/components/attention/favor.py
imports: import logging
  import math
  from dataclasses import dataclass
  from typing import Optional, Tuple
  import torch
  import torch.nn
  from torch.cuda.amp import autocast
  from xformers.components.attention import Attention, AttentionConfig, register_attention
  from xformers.components.attention.feature_maps import FeatureMap, FeatureMapType, SMHyperbolic, SMOrf, SMReg
label_desc: Use image node_id 4 for calling the FavorAttention obj's underlying member method code with example usage: obj.forward(q, k, v) and returns: att