class_docstr: ### Cross Attention Layer
  
  This falls-back to self-attention when conditional embeddings are not specified.
class_docstr_tok: ["#","#","#","Cross","Attention","Layer","This","falls-back","to","self-attention","when","conditional","embeddings","are","not","specified","."]
docstr: :param x: are the input embeddings of shape `[batch_size, height * width, d_model]`
  :param cond: is the conditional embeddings of shape `[batch_size, n_cond, d_cond]`
docstr_tok: [":","param","x",":","are","the","input","embeddings","of","shape","`","[","batch_size",",","height","*","width",",","d_model","]","`",":","param","cond",":","is","the","conditional","embeddings","of","shape","`","[","batch_size",",","n_cond",",","d_cond","]","`"]
code: def forward(
      self, x: torch.Tensor, cond: Optional[torch.Tensor] = None
  ):
      """
      :param x: are the input embeddings of shape `[batch_size, height * width, d_model]`
      :param cond: is the conditional embeddings of shape `[batch_size, n_cond, d_cond]`
      """
  
      # If `cond` is `None` we perform self attention
      has_cond = cond is not None
      if not has_cond:
          cond = x
  
      # Get query, key and value vectors
      q = self.to_q(x)
      k = self.to_k(cond)
      v = self.to_v(cond)
  
      # Use flash attention if it's available and the head size is less than or equal to `128`
      if (
          CrossAttention.use_flash_attention
          and self.flash is not None
          and not has_cond
          and self.d_head <= 128
      ):
          return self.flash_attention(q, k, v)
      # Otherwise, fallback to normal attention
      else:
          return self.normal_attention(q, k, v)
  
imports: from typing import Optional
  import torch
  import torch.nn.functional
  from torch import nn
label_desc: Use image node_id 2 for calling the CrossAttention obj's underlying member method code with example usage: obj.forward(x, cond) and returns: self, self