code: def _detect_is_causal_mask(
      mask: Optional[Tensor],
      is_causal: Optional[bool] = None,
      size: Optional[int] = None,
  ) -> bool:
      """Return whether the given attention mask is causal.
  
      Warning:
      If ``is_causal`` is not ``None``, its value will be returned as is.  If a
      user supplies an incorrect ``is_causal`` hint,
  
      ``is_causal=False`` when the mask is in fact a causal attention.mask
         may lead to reduced performance relative to what would be achievable
         with ``is_causal=True``;
      ``is_causal=True`` when the mask is in fact not a causal attention.mask
         may lead to incorrect and unpredictable execution - in some scenarios,
         a causal mask may be applied based on the hint, in other execution
         scenarios the specified mask may be used.  The choice may not appear
         to be deterministic, in that a number of factors like alignment,
         hardware SKU, etc influence the decision whether to use a mask or
         rely on the hint.
      ``size`` if not None, check whether the mask is a causal mask of the provided size
         Otherwise, checks for any causal mask.
      """
      # Prevent type refinement
      make_causal = is_causal is True
  
      if is_causal is None and mask is not None:
          sz = size if size is not None else mask.size(-2)
          causal_comparison = _generate_square_subsequent_mask(
              sz, device=mask.device, dtype=mask.dtype
          )
  
          # Do not use `torch.equal` so we handle batched masks by
          # broadcasting the comparison.
          if mask.size() == causal_comparison.size():
              make_causal = bool((mask == causal_comparison).all())
          else:
              make_causal = False
  
      return make_causal
  
imports: import copy
  from typing import Optional, Any, Union, Callable
  import torch
  import warnings
  from torch import Tensor
  from ..None import functional
  from .module import Module
  from .activation import MultiheadAttention
  from .container import ModuleList
  from ..init import xavier_uniform_
  from .dropout import Dropout
  from .linear import Linear
  from .normalization import LayerNorm
label_desc: Use image node_id 5 for calling a global function with example usage: _detect_is_causal_mask(mask, is_causal, size) and returns: make_causal