code: def prefix_attention_mask(
      attention_mask, dim: int = 3, prefix_value: int = 0
  ):
      """
      Adds a prefix to an attention mask. The length of the prefix is determined by the `prefix_attention_mask_length`
      attribute in the ForwardContext.
  
      Args:
          attention_mask:
              The attention mask to add the prefix to.
          dim (int):
              The dimension along which to concatenate the prefix_attention_mask. Defaults to 3.
          prefix_value (int):
              The value to use for the prefix_attention_mask. Defaults to 0, however some models, e.g. DistilBert, use
              different values. BERT like models invert their extended_attention_mask, hence they use 0 as value for not
              masked tokens. This inversion is usually done in the forward method of the model in 2 different ways:
                  1) by calling self.invert_attention_mask, as BERT does 2) by doing the inversion manually, e.g. ALBERT
                  does: `extended_attention_mask = (1.0 - extended_attention_mask) * torch.finfo(self.dtype).min`
      """
  
      forward_context = ForwardContext.get_context()
  
      if (
          attention_mask is not None
          and forward_context is not None
          and getattr(forward_context, "prompt_tokens_length", None)
          is not None
      ):
          # Create a tensor of ones with the desired shape
          ones_shape = list(attention_mask.shape)
          ones_shape[dim] = forward_context.prompt_tokens_length
  
          prefix_attention_mask = torch.full(
              ones_shape,
              prefix_value,
              dtype=attention_mask.dtype,
          ).to(attention_mask.device)
  
          # Concatenate the prefix_attention_mask along the specified dimension
          attention_mask = torch.cat(
              (prefix_attention_mask, attention_mask), dim=dim
          )
  
      return attention_mask
  
imports: import ast
  import fnmatch
  import hashlib
  import inspect
  import io
  import json
  import logging
  import os
  import re
  import shutil
  import tarfile
  import tempfile
  from collections.abc import Mapping
  from contextlib import contextmanager
  from dataclasses import dataclass
  from enum import Enum
  from functools import partial
  from os.path import basename, isdir, isfile, join
  from pathlib import Path
  from typing import Callable, Dict, List, Optional, Tuple, Union
  from urllib.parse import urlparse
  from zipfile import ZipFile, is_zipfile
  import torch
  import requests
  from filelock import FileLock
  from huggingface_hub import HfApi, HfFolder, snapshot_download
  from huggingface_hub.file_download import http_get, url_to_filename
  from huggingface_hub.utils import EntryNotFoundError, RepositoryNotFoundError, RevisionNotFoundError, hf_raise_for_status
  from requests.exceptions import HTTPError
  from transformers.utils import http_user_agent, is_remote_url
  from transformers.utils.hub import torch_cache_home
  from .None import __version__
  from .context import ForwardContext
label_desc: Use image node_id 21 for calling a global function with example usage: prefix_attention_mask(attention_mask, dim, prefix_value) and returns: attention_mask