code: def forward(
      self,
      q: torch.Tensor,
      k: torch.Tensor,
      v: torch.Tensor,
      att_mask: Optional[Union[torch.Tensor, AttentionMask]] = None,
      *args,
      **kwargs,
  ):
      # Local window attention masking
      if (
          self.attention_mask is None
          or self.attention_mask.shape[1] != q.shape[1]
      ):
          self.attention_mask = self._get_local_mask(q.shape).to(
              q.device
          )
  
      # Take into account the optional user mask
      if att_mask is None:
          mask = self.attention_mask
      else:
          if isinstance(att_mask, AttentionMask):
              # Needed because & op not defined for SparseCS with AttentionMask
              att_mask = att_mask.to_bool()
          mask = self.attention_mask & att_mask
  
      return scaled_dot_product_attention(
          q=q, k=k, v=v, att_mask=mask, dropout=self.attn_drop
      )
  
file_path: xformers/xformers/components/attention/local.py
imports: from dataclasses import dataclass
  from typing import Optional, Union
  import torch
  import torch.nn
  from xformers.components.attention import Attention, AttentionConfig, AttentionMask, maybe_sparsify, register_attention, sparsify
  from xformers.components.attention.attention_patterns import causal_1d_pattern, local_1d_pattern
  from xformers.components.attention.core import scaled_dot_product_attention
label_desc: Use image node_id 3 for calling the LocalAttention obj's underlying member method code with example usage: obj.forward(q, k, v, att_mask) and returns: scaled_dot_product_attention