class_docstr: Constructs instances of :class:`CausalAttentionMask`.
class_docstr_tok: ["Constructs","instances","of",":","class",":","`","CausalAttentionMask","`","."]
code: def __call__(
      self,
      seqs: Tensor,
      keys: Tensor,
      *,
      training: bool = True,
      state_bag: Optional[IncrementalStateBag] = None,
  ) -> Optional[CausalAttentionMask]:
      attn_len: Optional[int]
  
      attn_len = seqs.size(1)
  
      if training or state_bag is None:
          seq_len = attn_len
      else:
          seq_len = state_bag.step_nr + attn_len
  
      if seqs is keys:  # Self attention
          key_len = seq_len
      else:
          key_len = keys.size(1)
  
      if seq_len > key_len:
          raise ValueError(
              f"The sequence length of `seqs` must be less than or equal to the sequence length of `keys` ({key_len}), but is {seq_len} instead."
          )
  
      if attn_len <= 1:
          # Return `None` if the sequence has a length of 1 during training;
          # or if we attend to past steps during incremental decoding.
          return None
  
      # PyTorch SDPA does not support `attn_len`; set it to `None` if it is
      # redundant.
      if attn_len == seq_len:
          attn_len = None
  
      return CausalAttentionMask(
          seq_len,
          key_len,
          attn_len=attn_len,
          attn_window_len=self.attn_window_len,
          device=seqs.device,
          dtype=seqs.dtype,
      )
  
imports: from abc import ABC, abstractmethod
  from typing import Optional, Protocol, final
  import torch
  from torch import Tensor
  from fairseq2.nn.incremental_state import IncrementalStateBag
  from fairseq2.typing import DataType, Device, finaloverride
label_desc: Use image node_id 2 for calling the CausalAttentionMaskFactory obj's underlying member method code with example usage: obj.__call__(seqs, keys) and returns: CausalAttentionMask, None