.\models\auto\feature_extraction_auto.py

# 设置脚本的编码格式为 UTF-8
# 版权声明,使用 Apache License Version 2.0 授权许可
# 只有遵循许可证的条款,才能使用该文件
# 可以从 http://www.apache.org/licenses/LICENSE-2.0 获取许可证的副本
# 除非适用法律要求或书面同意,否则不得使用此文件
# 此软件根据 "原样" 分发,不提供任何形式的明示或暗示担保或条件
# 有关详细信息,请参阅许可证
""" AutoFeatureExtractor class."""

# 导入必要的模块
import importlib  # 动态导入模块的功能
import json  # 处理 JSON 数据的模块
import os  # 提供与操作系统相关的功能
import warnings  # 控制警告信息的输出
from collections import OrderedDict  # 提供有序字典的数据结构
from typing import Dict, Optional, Union  # 导入类型提示所需的类型

# 导入 transformers 库中的其他模块和函数
from ...configuration_utils import PretrainedConfig  # 预训练配置类
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code  # 动态模块相关工具函数
from ...feature_extraction_utils import FeatureExtractionMixin  # 特征提取混合类
from ...utils import CONFIG_NAME, FEATURE_EXTRACTOR_NAME, get_file_from_repo, logging  # 提供各种实用功能的工具函数
from .auto_factory import _LazyAutoMapping  # 自动工厂类的延迟映射
from .configuration_auto import (
    CONFIG_MAPPING_NAMES,  # 配置映射名称列表
    AutoConfig,  # 自动配置类
    model_type_to_module_name,  # 模型类型到模块名称的映射函数
    replace_list_option_in_docstrings,  # 在文档字符串中替换列表选项的函数
)

# 获取日志记录器对象
logger = logging.get_logger(__name__)

# 特征提取器映射名称的有序字典定义
FEATURE_EXTRACTOR_MAPPING_NAMES = OrderedDict(
    [
        # 此处应该有一些特征提取器的映射条目,但代码片段中省略了具体内容
    ]
)

# 基于配置映射名称和特征提取器映射名称创建特征提取器映射对象
FEATURE_EXTRACTOR_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, FEATURE_EXTRACTOR_MAPPING_NAMES)


def feature_extractor_class_from_name(class_name: str):
    """
    根据特征提取器类名获取对应的特征提取器类对象。

    Args:
        class_name (str): 特征提取器类的名称。

    Returns:
        type or None: 如果找到匹配的特征提取器类,则返回该类对象;否则返回 None。
    """
    # 遍历特征提取器映射名称字典中的模块名称和特征提取器类列表
    for module_name, extractors in FEATURE_EXTRACTOR_MAPPING_NAMES.items():
        # 如果 class_name 在当前模块的特征提取器类列表中
        if class_name in extractors:
            # 将模型类型转换为相应的模块名称
            module_name = model_type_to_module_name(module_name)
            # 在 transformers.models 下动态导入对应的模块
            module = importlib.import_module(f".{module_name}", "transformers.models")
            try:
                # 返回特征提取器类对象
                return getattr(module, class_name)
            except AttributeError:
                continue

    # 在额外内容中查找特征提取器对象
    for _, extractor in FEATURE_EXTRACTOR_MAPPING._extra_content.items():
        # 如果特征提取器对象的 __name__ 属性等于 class_name
        if getattr(extractor, "__name__", None) == class_name:
            return extractor

    # 如果在当前模块中找不到特征提取器类,可能是由于依赖项丢失,此时返回适当的 dummy 类以获得适当的错误消息
    main_module = importlib.import_module("transformers")
    if hasattr(main_module, class_name):
        return getattr(main_module, class_name)

    # 如果找不到匹配的特征提取器类,则返回 None
    return None


def get_feature_extractor_config(
    pretrained_model_name_or_path: Union[str, os.PathLike],  # 预训练模型名称或路径
    cache_dir: Optional[Union[str, os.PathLike]] = None,  # 缓存目录,可选
    force_download: bool = False,  # 是否强制下载
    resume_download: bool = False,  # 是否恢复下载
    proxies: Optional[Dict[str, str]] = None,  # 代理设置
    token: Optional[Union[bool, str]] = None,  # 访问令牌,可选
    revision: Optional[str] = None,  # 仓库的版本号,可选
    local_files_only: bool = False,  # 仅使用本地文件
    **kwargs,  # 其他关键字参数
):
    """
    从预训练模型加载特征提取器的配置信息。

    Args:
        pretrained_model_name_or_path (Union[str, os.PathLike]): 预训练模型的名称或路径。
        cache_dir (Optional[Union[str, os.PathLike]], optional): 缓存目录路径,可选参数。默认为 None。
        force_download (bool, optional): 是否强制下载,默认为 False。
        resume_download (bool, optional): 是否恢复下载,默认为 False。
        proxies (Optional[Dict[str, str]], optional): 代理设置,可选参数。默认为 None。
        token (Optional[Union[bool, str]], optional): 访问令牌,可选参数。默认为 None。
        revision (Optional[str], optional): 仓库的版本号,可选参数。默认为 None。
        local_files_only (bool, optional): 是否仅使用本地文件,默认为 False。
        **kwargs: 其他关键字参数。

    Returns:
        None
    """
    pass  # 函数体未实现,仅有文档字符串提示函数用途
    # 从参数中获取 `use_auth_token`,如果存在则弹出并赋值给 `use_auth_token` 变量,否则设置为 `None`
    use_auth_token = kwargs.pop("use_auth_token", None)
    # 如果 use_auth_token 参数不为 None,则发出警告,说明该参数在将来版本中会被移除
    if use_auth_token is not None:
        warnings.warn(
            "The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.",
            FutureWarning,
        )
        # 如果同时指定了 token 参数,则抛出数值错误,提示只能设置 `token` 参数
        if token is not None:
            raise ValueError("`token` and `use_auth_token` are both specified. Please set only the argument `token`.")
        # 将 token 参数设置为 use_auth_token 的值
        token = use_auth_token

    # 获取预训练模型名称或路径对应的特征提取器配置文件路径
    resolved_config_file = get_file_from_repo(
        pretrained_model_name_or_path,
        FEATURE_EXTRACTOR_NAME,
        cache_dir=cache_dir,
        force_download=force_download,
        resume_download=resume_download,
        proxies=proxies,
        token=token,
        revision=revision,
        local_files_only=local_files_only,
    )
    # 如果未找到特征提取器配置文件,则记录日志并返回空字典
    if resolved_config_file is None:
        logger.info(
            "Could not locate the feature extractor configuration file, will try to use the model config instead."
        )
        return {}

    # 使用 UTF-8 编码打开特征提取器配置文件,并加载为 JSON 格式返回
    with open(resolved_config_file, encoding="utf-8") as reader:
        return json.load(reader)
class AutoFeatureExtractor:
    r"""
    This is a generic feature extractor class that will be instantiated as one of the feature extractor classes of the
    library when created with the [`AutoFeatureExtractor.from_pretrained`] class method.

    This class cannot be instantiated directly using `__init__()` (throws an error).
    """

    def __init__(self):
        # 抛出环境错误,阻止直接通过 __init__() 实例化该类
        raise EnvironmentError(
            "AutoFeatureExtractor is designed to be instantiated "
            "using the `AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path)` method."
        )

    @classmethod
    @replace_list_option_in_docstrings(FEATURE_EXTRACTOR_MAPPING_NAMES)
    @staticmethod
    def register(config_class, feature_extractor_class, exist_ok=False):
        """
        Register a new feature extractor for this class.

        Args:
            config_class ([`PretrainedConfig`]):
                The configuration corresponding to the model to register.
            feature_extractor_class ([`FeatureExtractorMixin`]): The feature extractor to register.
        """
        # 使用 FEATURE_EXTRACTOR_MAPPING 的 register 方法注册新的特征提取器类
        FEATURE_EXTRACTOR_MAPPING.register(config_class, feature_extractor_class, exist_ok=exist_ok)

.\models\auto\image_processing_auto.py

# 设置编码格式为 UTF-8
# 版权声明,指明代码版权归 HuggingFace Inc. 团队所有
# 使用 Apache License, Version 2.0 许可协议,详见链接
# 除非法律另有规定或书面同意,否则不得使用本文件
# 详细信息请查看许可协议:http://www.apache.org/licenses/LICENSE-2.0
# 引入 warnings 库,用于发出警告信息
import warnings
# collections 模块中的 OrderedDict 类,用于创建有序字典
from collections import OrderedDict
# typing 模块,用于类型提示
from typing import Dict, Optional, Union

# 从相应模块中导入函数和类
# configuration_utils 模块中的 PretrainedConfig 类
from ...configuration_utils import PretrainedConfig
# dynamic_module_utils 中的函数,用于从动态模块中获取类
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
# image_processing_utils 中的 ImageProcessingMixin 类
from ...image_processing_utils import ImageProcessingMixin
# utils 中的各种实用函数和常量
from ...utils import CONFIG_NAME, IMAGE_PROCESSOR_NAME, get_file_from_repo, logging
# 从当前包中导入 auto_factory 模块的 _LazyAutoMapping 类
from .auto_factory import _LazyAutoMapping
# 从当前包中导入 configuration_auto 模块中的若干变量和函数
from .configuration_auto import (
    CONFIG_MAPPING_NAMES,
    AutoConfig,
    model_type_to_module_name,
    replace_list_option_in_docstrings,
)

# 获取 logger 对象
logger = logging.get_logger(__name__)

# 定义 IMAGE_PROCESSOR_MAPPING_NAMES 为有序字典
IMAGE_PROCESSOR_MAPPING_NAMES = OrderedDict(
    # 这里原本应该有具体的映射关系,由开发者补充完整
    # 类似 {'module_name': ['extractor1', 'extractor2']}
    # 用于存储映射关系
)

# 使用 _LazyAutoMapping 类创建 IMAGE_PROCESSOR_MAPPING 对象
IMAGE_PROCESSOR_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, IMAGE_PROCESSOR_MAPPING_NAMES)

# 根据类名从 IMAGE_PROCESSOR_MAPPING_NAMES 中获取对应的处理器类
def image_processor_class_from_name(class_name: str):
    for module_name, extractors in IMAGE_PROCESSOR_MAPPING_NAMES.items():
        # 遍历映射字典,查找匹配的类名
        if class_name in extractors:
            # 将模块名转换为模块的实际名称
            module_name = model_type_to_module_name(module_name)
            # 动态导入相应模块
            module = importlib.import_module(f".{module_name}", "transformers.models")
            try:
                # 返回模块中对应的类对象
                return getattr(module, class_name)
            except AttributeError:
                continue

    # 如果在 IMAGE_PROCESSOR_MAPPING_NAMES 中未找到对应类名,则遍历额外内容
    for _, extractor in IMAGE_PROCESSOR_MAPPING._extra_content.items():
        # 检查额外内容中是否包含与类名匹配的对象
        if getattr(extractor, "__name__", None) == class_name:
            return extractor

    # 若以上方法均未找到匹配的类名,则从主模块中导入,返回对应的类对象或 None
    main_module = importlib.import_module("transformers")
    if hasattr(main_module, class_name):
        return getattr(main_module, class_name)

    return None

# 加载预训练模型的图像处理器配置信息
def get_image_processor_config(
    pretrained_model_name_or_path: Union[str, os.PathLike],
    cache_dir: Optional[Union[str, os.PathLike]] = None,
    force_download: bool = False,
    resume_download: bool = False,
    proxies: Optional[Dict[str, str]] = None,
    token: Optional[Union[bool, str]] = None,
    revision: Optional[str] = None,
    local_files_only: bool = False,
    **kwargs,
):
    """
    从预训练模型的图像处理器配置中加载图像处理器配置信息。
    """
    # 函数体内容尚未给出,需由开发者补充完整
    Args:
        pretrained_model_name_or_path (`str` or `os.PathLike`):
            This can be either:

            - a string, the *model id* of a pretrained model configuration hosted inside a model repo on
              huggingface.co.
            - a path to a *directory* containing a configuration file saved using the
              [`~PreTrainedTokenizer.save_pretrained`] method, e.g., `./my_model_directory/`.

        cache_dir (`str` or `os.PathLike`, *optional*):
            Path to a directory in which a downloaded pretrained model configuration should be cached if the standard
            cache should not be used.
        force_download (`bool`, *optional*, defaults to `False`):
            Whether or not to force to (re-)download the configuration files and override the cached versions if they
            exist.
        resume_download (`bool`, *optional*, defaults to `False`):
            Whether or not to delete incompletely received file. Attempts to resume the download if such a file exists.
        proxies (`Dict[str, str]`, *optional*):
            A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
            'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
        token (`str` or *bool*, *optional*):
            The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
            when running `huggingface-cli login` (stored in `~/.huggingface`).
        revision (`str`, *optional*, defaults to `"main"`):
            The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
            git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
            identifier allowed by git.
        local_files_only (`bool`, *optional*, defaults to `False`):
            If `True`, will only try to load the image processor configuration from local files.

    <Tip>

    Passing `token=True` is required when you want to use a private model.

    </Tip>

    Returns:
        `Dict`: The configuration of the image processor.

    Examples:

    ```
    # Download configuration from huggingface.co and cache.
    image_processor_config = get_image_processor_config("google-bert/bert-base-uncased")
    # This model does not have a image processor config so the result will be an empty dict.
    image_processor_config = get_image_processor_config("FacebookAI/xlm-roberta-base")

    # Save a pretrained image processor locally and you can reload its config
    from transformers import AutoTokenizer

    image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k")
    image_processor.save_pretrained("image-processor-test")
    image_processor_config = get_image_processor_config("image-processor-test")
    ```
"""
    use_auth_token = kwargs.pop("use_auth_token", None)
    # 如果 use_auth_token 参数不为 None,则发出警告,提醒该参数将在 Transformers v5 版本中被移除
    if use_auth_token is not None:
        warnings.warn(
            "The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.",
            FutureWarning,
        )
        # 如果同时指定了 token 参数和 use_auth_token 参数,则抛出数值错误
        if token is not None:
            raise ValueError("`token` and `use_auth_token` are both specified. Please set only the argument `token`.")
        # 将 token 参数设置为 use_auth_token 参数的值
        token = use_auth_token

    # 从指定的预训练模型名或路径中获取配置文件路径
    resolved_config_file = get_file_from_repo(
        pretrained_model_name_or_path,
        IMAGE_PROCESSOR_NAME,
        cache_dir=cache_dir,
        force_download=force_download,
        resume_download=resume_download,
        proxies=proxies,
        token=token,
        revision=revision,
        local_files_only=local_files_only,
    )
    # 如果未能定位到图像处理器配置文件,则记录信息并返回空字典
    if resolved_config_file is None:
        logger.info(
            "Could not locate the image processor configuration file, will try to use the model config instead."
        )
        return {}

    # 打开配置文件并以 UTF-8 编码读取其中的内容,解析为 JSON 格式返回
    with open(resolved_config_file, encoding="utf-8") as reader:
        return json.load(reader)
class AutoImageProcessor:
    r"""
    This is a generic image processor class that will be instantiated as one of the image processor classes of the
    library when created with the [`AutoImageProcessor.from_pretrained`] class method.

    This class cannot be instantiated directly using `__init__()` (throws an error).
    """

    def __init__(self):
        # 抛出环境错误,阻止直接实例化该类
        raise EnvironmentError(
            "AutoImageProcessor is designed to be instantiated "
            "using the `AutoImageProcessor.from_pretrained(pretrained_model_name_or_path)` method."
        )

    @classmethod
    @replace_list_option_in_docstrings(IMAGE_PROCESSOR_MAPPING_NAMES)
    @staticmethod
    def register(config_class, image_processor_class, exist_ok=False):
        """
        Register a new image processor for this class.

        Args:
            config_class ([`PretrainedConfig`]):
                The configuration corresponding to the model to register.
            image_processor_class ([`ImageProcessingMixin`]): The image processor to register.
        """
        # 调用全局注册函数,将给定的配置类和图像处理器类注册到映射表中
        IMAGE_PROCESSOR_MAPPING.register(config_class, image_processor_class, exist_ok=exist_ok)

.\models\auto\modeling_auto.py

# 设置文件编码为 UTF-8
# 版权声明和许可信息
#
# 根据 Apache 许可证版本 2.0 授权使用此文件
# 除非符合许可证的条件,否则不得使用此文件
# 可以在以下网址获取许可证的副本:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# 除非适用法律要求或书面同意,否则本软件基于"原样"分发,无任何担保或条件
# 请查阅许可证了解具体的法律条文和允许条件
""" Auto Model class."""

# 导入警告模块
import warnings
# 导入有序字典模块
from collections import OrderedDict

# 导入日志记录工具
from ...utils import logging
# 从 auto_factory 模块导入相关类和函数
from .auto_factory import (
    _BaseAutoBackboneClass,
    _BaseAutoModelClass,
    _LazyAutoMapping,
    auto_class_update,
)
# 导入自动生成的配置映射
from .configuration_auto import CONFIG_MAPPING_NAMES

# 获取当前模块的日志记录器
logger = logging.get_logger(__name__)

# 定义模型映射名称的有序字典
MODEL_MAPPING_NAMES = OrderedDict(
    # 这里是一个空的有序字典,用于存储模型映射名称
)

# 定义用于预训练的模型映射名称的有序字典
MODEL_FOR_PRETRAINING_MAPPING_NAMES = OrderedDict(
    # 这里是一个空的有序字典,用于存储预训练模型映射名称
)

# 定义带语言模型头部的模型映射名称的有序字典
MODEL_WITH_LM_HEAD_MAPPING_NAMES = OrderedDict(
    # 这里是一个空的有序字典,用于存储带语言模型头部的模型映射名称
)

# 定义用于因果语言模型的模型映射名称的有序字典
MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = OrderedDict(
    # 这里是一个空的有序字典,用于存储因果语言模型的模型映射名称
)

# 定义用于图像任务的模型映射名称的有序字典
MODEL_FOR_IMAGE_MAPPING_NAMES = OrderedDict(
    # 这里是一个空的有序字典,用于存储图像任务的模型映射名称
)
    # 创建一个元组列表,每个元组包含模型的名称和相应的模型类名
    [
        # 模型名 "beit" 对应的模型类名 "BeitModel"
        ("beit", "BeitModel"),
        # 模型名 "bit" 对应的模型类名 "BitModel"
        ("bit", "BitModel"),
        # 模型名 "conditional_detr" 对应的模型类名 "ConditionalDetrModel"
        ("conditional_detr", "ConditionalDetrModel"),
        # 模型名 "convnext" 对应的模型类名 "ConvNextModel"
        ("convnext", "ConvNextModel"),
        # 模型名 "convnextv2" 对应的模型类名 "ConvNextV2Model"
        ("convnextv2", "ConvNextV2Model"),
        # 模型名 "data2vec-vision" 对应的模型类名 "Data2VecVisionModel"
        ("data2vec-vision", "Data2VecVisionModel"),
        # 模型名 "deformable_detr" 对应的模型类名 "DeformableDetrModel"
        ("deformable_detr", "DeformableDetrModel"),
        # 模型名 "deit" 对应的模型类名 "DeiTModel"
        ("deit", "DeiTModel"),
        # 模型名 "deta" 对应的模型类名 "DetaModel"
        ("deta", "DetaModel"),
        # 模型名 "detr" 对应的模型类名 "DetrModel"
        ("detr", "DetrModel"),
        # 模型名 "dinat" 对应的模型类名 "DinatModel"
        ("dinat", "DinatModel"),
        # 模型名 "dinov2" 对应的模型类名 "Dinov2Model"
        ("dinov2", "Dinov2Model"),
        # 模型名 "dpt" 对应的模型类名 "DPTModel"
        ("dpt", "DPTModel"),
        # 模型名 "efficientformer" 对应的模型类名 "EfficientFormerModel"
        ("efficientformer", "EfficientFormerModel"),
        # 模型名 "efficientnet" 对应的模型类名 "EfficientNetModel"
        ("efficientnet", "EfficientNetModel"),
        # 模型名 "focalnet" 对应的模型类名 "FocalNetModel"
        ("focalnet", "FocalNetModel"),
        # 模型名 "glpn" 对应的模型类名 "GLPNModel"
        ("glpn", "GLPNModel"),
        # 模型名 "imagegpt" 对应的模型类名 "ImageGPTModel"
        ("imagegpt", "ImageGPTModel"),
        # 模型名 "levit" 对应的模型类名 "LevitModel"
        ("levit", "LevitModel"),
        # 模型名 "mobilenet_v1" 对应的模型类名 "MobileNetV1Model"
        ("mobilenet_v1", "MobileNetV1Model"),
        # 模型名 "mobilenet_v2" 对应的模型类名 "MobileNetV2Model"
        ("mobilenet_v2", "MobileNetV2Model"),
        # 模型名 "mobilevit" 对应的模型类名 "MobileViTModel"
        ("mobilevit", "MobileViTModel"),
        # 模型名 "mobilevitv2" 对应的模型类名 "MobileViTV2Model"
        ("mobilevitv2", "MobileViTV2Model"),
        # 模型名 "nat" 对应的模型类名 "NatModel"
        ("nat", "NatModel"),
        # 模型名 "poolformer" 对应的模型类名 "PoolFormerModel"
        ("poolformer", "PoolFormerModel"),
        # 模型名 "pvt" 对应的模型类名 "PvtModel"
        ("pvt", "PvtModel"),
        # 模型名 "regnet" 对应的模型类名 "RegNetModel"
        ("regnet", "RegNetModel"),
        # 模型名 "resnet" 对应的模型类名 "ResNetModel"
        ("resnet", "ResNetModel"),
        # 模型名 "segformer" 对应的模型类名 "SegformerModel"
        ("segformer", "SegformerModel"),
        # 模型名 "siglip_vision_model" 对应的模型类名 "SiglipVisionModel"
        ("siglip_vision_model", "SiglipVisionModel"),
        # 模型名 "swiftformer" 对应的模型类名 "SwiftFormerModel"
        ("swiftformer", "SwiftFormerModel"),
        # 模型名 "swin" 对应的模型类名 "SwinModel"
        ("swin", "SwinModel"),
        # 模型名 "swin2sr" 对应的模型类名 "Swin2SRModel"
        ("swin2sr", "Swin2SRModel"),
        # 模型名 "swinv2" 对应的模型类名 "Swinv2Model"
        ("swinv2", "Swinv2Model"),
        # 模型名 "table-transformer" 对应的模型类名 "TableTransformerModel"
        ("table-transformer", "TableTransformerModel"),
        # 模型名 "timesformer" 对应的模型类名 "TimesformerModel"
        ("timesformer", "TimesformerModel"),
        # 模型名 "timm_backbone" 对应的模型类名 "TimmBackbone"
        ("timm_backbone", "TimmBackbone"),
        # 模型名 "van" 对应的模型类名 "VanModel"
        ("van", "VanModel"),
        # 模型名 "videomae" 对应的模型类名 "VideoMAEModel"
        ("videomae", "VideoMAEModel"),
        # 模型名 "vit" 对应的模型类名 "ViTModel"
        ("vit", "ViTModel"),
        # 模型名 "vit_hybrid" 对应的模型类名 "ViTHybridModel"
        ("vit_hybrid", "ViTHybridModel"),
        # 模型名 "vit_mae" 对应的模型类名 "ViTMAEModel"
        ("vit_mae", "ViTMAEModel"),
        # 模型名 "vit_msn" 对应的模型类名 "ViTMSNModel"
        ("vit_msn", "ViTMSNModel"),
        # 模型名 "vitdet" 对应的模型类名 "VitDetModel"
        ("vitdet", "VitDetModel"),
        # 模型名 "vivit" 对应的模型类名 "VivitModel"
        ("vivit", "VivitModel"),
        # 模型名 "yolos" 对应的模型类名 "YolosModel"
        ("yolos", "YolosModel"),
    ]
# 定义一个有序字典,映射不同模型到相应的类名称,用于掩模图像建模模型
MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING_NAMES = OrderedDict(
    [
        ("deit", "DeiTForMaskedImageModeling"),   # 将 "deit" 映射到 "DeiTForMaskedImageModeling"
        ("focalnet", "FocalNetForMaskedImageModeling"),  # 将 "focalnet" 映射到 "FocalNetForMaskedImageModeling"
        ("swin", "SwinForMaskedImageModeling"),   # 将 "swin" 映射到 "SwinForMaskedImageModeling"
        ("swinv2", "Swinv2ForMaskedImageModeling"),  # 将 "swinv2" 映射到 "Swinv2ForMaskedImageModeling"
        ("vit", "ViTForMaskedImageModeling"),   # 将 "vit" 映射到 "ViTForMaskedImageModeling"
    ]
)

# 定义一个有序字典,映射不同模型到因果图像建模模型的类名称
MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING_NAMES = OrderedDict(
    [
        ("imagegpt", "ImageGPTForCausalImageModeling"),  # 将 "imagegpt" 映射到 "ImageGPTForCausalImageModeling"
    ]
)

# 定义一个有序字典,映射不同模型到图像分类模型的类名称
MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        # 定义了多个模型名称与对应的类名的映射关系
        ("beit", "BeitForImageClassification"),  # BEiT 模型的图像分类器
        ("bit", "BitForImageClassification"),  # BiT 模型的图像分类器
        ("clip", "CLIPForImageClassification"),  # CLIP 模型的图像分类器
        ("convnext", "ConvNextForImageClassification"),  # ConvNext 模型的图像分类器
        ("convnextv2", "ConvNextV2ForImageClassification"),  # ConvNextV2 模型的图像分类器
        ("cvt", "CvtForImageClassification"),  # CvT 模型的图像分类器
        ("data2vec-vision", "Data2VecVisionForImageClassification"),  # Data2VecVision 模型的图像分类器
        (
            "deit",
            ("DeiTForImageClassification", "DeiTForImageClassificationWithTeacher"),  # DeiT 模型的图像分类器及其带教师的版本
        ),
        ("dinat", "DinatForImageClassification"),  # DINO 模型的图像分类器
        ("dinov2", "Dinov2ForImageClassification"),  # DINOv2 模型的图像分类器
        (
            "efficientformer",
            (
                "EfficientFormerForImageClassification",  # EfficientFormer 模型的图像分类器
                "EfficientFormerForImageClassificationWithTeacher",  # EfficientFormer 模型的图像分类器带教师版本
            ),
        ),
        ("efficientnet", "EfficientNetForImageClassification"),  # EfficientNet 模型的图像分类器
        ("focalnet", "FocalNetForImageClassification"),  # FocalNet 模型的图像分类器
        ("imagegpt", "ImageGPTForImageClassification"),  # ImageGPT 模型的图像分类器
        (
            "levit",
            ("LevitForImageClassification", "LevitForImageClassificationWithTeacher"),  # LeViT 模型的图像分类器及其带教师的版本
        ),
        ("mobilenet_v1", "MobileNetV1ForImageClassification"),  # MobileNetV1 模型的图像分类器
        ("mobilenet_v2", "MobileNetV2ForImageClassification"),  # MobileNetV2 模型的图像分类器
        ("mobilevit", "MobileViTForImageClassification"),  # MobileViT 模型的图像分类器
        ("mobilevitv2", "MobileViTV2ForImageClassification"),  # MobileViTV2 模型的图像分类器
        ("nat", "NatForImageClassification"),  # NAT 模型的图像分类器
        (
            "perceiver",
            (
                "PerceiverForImageClassificationLearned",  # Perceiver 模型的图像分类器(学习)
                "PerceiverForImageClassificationFourier",  # Perceiver 模型的图像分类器(Fourier变换)
                "PerceiverForImageClassificationConvProcessing",  # Perceiver 模型的图像分类器(卷积处理)
            ),
        ),
        ("poolformer", "PoolFormerForImageClassification"),  # PoolFormer 模型的图像分类器
        ("pvt", "PvtForImageClassification"),  # PVT 模型的图像分类器
        ("pvt_v2", "PvtV2ForImageClassification"),  # PvtV2 模型的图像分类器
        ("regnet", "RegNetForImageClassification"),  # RegNet 模型的图像分类器
        ("resnet", "ResNetForImageClassification"),  # ResNet 模型的图像分类器
        ("segformer", "SegformerForImageClassification"),  # Segformer 模型的图像分类器
        ("siglip", "SiglipForImageClassification"),  # Siglip 模型的图像分类器
        ("swiftformer", "SwiftFormerForImageClassification"),  # SwiftFormer 模型的图像分类器
        ("swin", "SwinForImageClassification"),  # Swin 模型的图像分类器
        ("swinv2", "Swinv2ForImageClassification"),  # SwinV2 模型的图像分类器
        ("van", "VanForImageClassification"),  # ViT 模型的图像分类器
        ("vit", "ViTForImageClassification"),  # ViT 模型的图像分类器
        ("vit_hybrid", "ViTHybridForImageClassification"),  # ViT 混合模型的图像分类器
        ("vit_msn", "ViTMSNForImageClassification"),  # ViT-MSN 模型的图像分类器
    ]
# 定义一个有序字典,映射不同的模型名称到对应的类名,用于图像分割模型
MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES = OrderedDict(
    [
        # 不要在这里添加新的模型,此类将来会被弃用。
        # 图像分割模型的映射
        ("detr", "DetrForSegmentation"),
    ]
)

# 定义一个有序字典,映射不同的模型名称到对应的类名,用于语义分割模型
MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES = OrderedDict(
    [
        # 语义分割模型的映射
        ("beit", "BeitForSemanticSegmentation"),
        ("data2vec-vision", "Data2VecVisionForSemanticSegmentation"),
        ("dpt", "DPTForSemanticSegmentation"),
        ("mobilenet_v2", "MobileNetV2ForSemanticSegmentation"),
        ("mobilevit", "MobileViTForSemanticSegmentation"),
        ("mobilevitv2", "MobileViTV2ForSemanticSegmentation"),
        ("segformer", "SegformerForSemanticSegmentation"),
        ("upernet", "UperNetForSemanticSegmentation"),
    ]
)

# 定义一个有序字典,映射不同的模型名称到对应的类名,用于实例分割模型
MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING_NAMES = OrderedDict(
    [
        # 实例分割模型的映射
        # MaskFormerForInstanceSegmentation 在 v5 中可以从这个映射中移除
        ("maskformer", "MaskFormerForInstanceSegmentation"),
    ]
)

# 定义一个有序字典,映射不同的模型名称到对应的类名,用于通用分割模型
MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES = OrderedDict(
    [
        # 通用分割模型的映射
        ("detr", "DetrForSegmentation"),
        ("mask2former", "Mask2FormerForUniversalSegmentation"),
        ("maskformer", "MaskFormerForInstanceSegmentation"),
        ("oneformer", "OneFormerForUniversalSegmentation"),
    ]
)

# 定义一个有序字典,映射不同的模型名称到对应的类名,用于视频分类模型
MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        ("timesformer", "TimesformerForVideoClassification"),
        ("videomae", "VideoMAEForVideoClassification"),
        ("vivit", "VivitForVideoClassification"),
    ]
)

# 定义一个有序字典,映射不同的模型名称到对应的类名,用于视觉到序列模型
MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES = OrderedDict(
    [
        ("blip", "BlipForConditionalGeneration"),
        ("blip-2", "Blip2ForConditionalGeneration"),
        ("git", "GitForCausalLM"),
        ("instructblip", "InstructBlipForConditionalGeneration"),
        ("kosmos-2", "Kosmos2ForConditionalGeneration"),
        ("llava", "LlavaForConditionalGeneration"),
        ("llava_next", "LlavaNextForConditionalGeneration"),
        ("pix2struct", "Pix2StructForConditionalGeneration"),
        ("vipllava", "VipLlavaForConditionalGeneration"),
        ("vision-encoder-decoder", "VisionEncoderDecoderModel"),
    ]
)

# 定义一个有序字典,映射不同的模型名称到对应的类名,用于掩码语言建模模型
MODEL_FOR_MASKED_LM_MAPPING_NAMES = OrderedDict(
    [
        # 模型名称与对应的 PyTorch 模型类名的映射关系列表
        ("albert", "AlbertForMaskedLM"),                # Albert 模型用于 Masked LM
        ("bart", "BartForConditionalGeneration"),       # Bart 模型用于条件生成
        ("bert", "BertForMaskedLM"),                    # Bert 模型用于 Masked LM
        ("big_bird", "BigBirdForMaskedLM"),             # BigBird 模型用于 Masked LM
        ("camembert", "CamembertForMaskedLM"),          # Camembert 模型用于 Masked LM
        ("convbert", "ConvBertForMaskedLM"),            # ConvBert 模型用于 Masked LM
        ("data2vec-text", "Data2VecTextForMaskedLM"),   # Data2Vec-Text 模型用于 Masked LM
        ("deberta", "DebertaForMaskedLM"),              # Deberta 模型用于 Masked LM
        ("deberta-v2", "DebertaV2ForMaskedLM"),         # Deberta-v2 模型用于 Masked LM
        ("distilbert", "DistilBertForMaskedLM"),        # DistilBert 模型用于 Masked LM
        ("electra", "ElectraForMaskedLM"),              # Electra 模型用于 Masked LM
        ("ernie", "ErnieForMaskedLM"),                  # Ernie 模型用于 Masked LM
        ("esm", "EsmForMaskedLM"),                      # ESM 模型用于 Masked LM
        ("flaubert", "FlaubertWithLMHeadModel"),        # Flaubert 模型用于 Masked LM
        ("fnet", "FNetForMaskedLM"),                    # FNet 模型用于 Masked LM
        ("funnel", "FunnelForMaskedLM"),                # Funnel 模型用于 Masked LM
        ("ibert", "IBertForMaskedLM"),                  # IBert 模型用于 Masked LM
        ("layoutlm", "LayoutLMForMaskedLM"),            # LayoutLM 模型用于 Masked LM
        ("longformer", "LongformerForMaskedLM"),        # Longformer 模型用于 Masked LM
        ("luke", "LukeForMaskedLM"),                    # Luke 模型用于 Masked LM
        ("mbart", "MBartForConditionalGeneration"),     # MBart 模型用于条件生成
        ("mega", "MegaForMaskedLM"),                    # Mega 模型用于 Masked LM
        ("megatron-bert", "MegatronBertForMaskedLM"),   # Megatron-Bert 模型用于 Masked LM
        ("mobilebert", "MobileBertForMaskedLM"),        # MobileBert 模型用于 Masked LM
        ("mpnet", "MPNetForMaskedLM"),                  # MPNet 模型用于 Masked LM
        ("mra", "MraForMaskedLM"),                      # Mra 模型用于 Masked LM
        ("mvp", "MvpForConditionalGeneration"),         # Mvp 模型用于条件生成
        ("nezha", "NezhaForMaskedLM"),                  # Nezha 模型用于 Masked LM
        ("nystromformer", "NystromformerForMaskedLM"),  # Nystromformer 模型用于 Masked LM
        ("perceiver", "PerceiverForMaskedLM"),          # Perceiver 模型用于 Masked LM
        ("qdqbert", "QDQBertForMaskedLM"),              # QDQBert 模型用于 Masked LM
        ("reformer", "ReformerForMaskedLM"),            # Reformer 模型用于 Masked LM
        ("rembert", "RemBertForMaskedLM"),              # RemBert 模型用于 Masked LM
        ("roberta", "RobertaForMaskedLM"),              # Roberta 模型用于 Masked LM
        ("roberta-prelayernorm", "RobertaPreLayerNormForMaskedLM"),  # Roberta with PreLayerNorm 模型用于 Masked LM
        ("roc_bert", "RoCBertForMaskedLM"),             # RoCBert 模型用于 Masked LM
        ("roformer", "RoFormerForMaskedLM"),            # RoFormer 模型用于 Masked LM
        ("squeezebert", "SqueezeBertForMaskedLM"),      # SqueezeBert 模型用于 Masked LM
        ("tapas", "TapasForMaskedLM"),                  # Tapas 模型用于 Masked LM
        ("wav2vec2", "Wav2Vec2ForMaskedLM"),            # Wav2Vec2 模型用于 Masked LM
        ("xlm", "XLMWithLMHeadModel"),                  # XLM 模型用于 Masked LM
        ("xlm-roberta", "XLMRobertaForMaskedLM"),       # XLM-RoBERTa 模型用于 Masked LM
        ("xlm-roberta-xl", "XLMRobertaXLForMaskedLM"),  # XLM-RoBERTa-XL 模型用于 Masked LM
        ("xmod", "XmodForMaskedLM"),                    # Xmod 模型用于 Masked LM
        ("yoso", "YosoForMaskedLM"),                    # Yoso 模型用于 Masked LM
    ]
# 定义用于对象检测模型的名称映射字典,使用有序字典确保顺序性
MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES = OrderedDict(
    [
        # 对象检测模型映射
        ("conditional_detr", "ConditionalDetrForObjectDetection"),
        ("deformable_detr", "DeformableDetrForObjectDetection"),
        ("deta", "DetaForObjectDetection"),
        ("detr", "DetrForObjectDetection"),
        ("table-transformer", "TableTransformerForObjectDetection"),
        ("yolos", "YolosForObjectDetection"),
    ]
)

# 定义用于零样本对象检测模型的名称映射字典,使用有序字典确保顺序性
MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES = OrderedDict(
    [
        # 零样本对象检测模型映射
        ("owlv2", "Owlv2ForObjectDetection"),
        ("owlvit", "OwlViTForObjectDetection"),
    ]
)

# 定义深度估计模型的名称映射字典,使用有序字典确保顺序性
MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES = OrderedDict(
    [
        # 深度估计模型映射
        ("depth_anything", "DepthAnythingForDepthEstimation"),
        ("dpt", "DPTForDepthEstimation"),
        ("glpn", "GLPNForDepthEstimation"),
    ]
)

# 定义序列到序列因果语言模型的名称映射字典,使用有序字典确保顺序性
MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES = OrderedDict(
    [
        # 序列到序列因果语言模型映射
        ("bart", "BartForConditionalGeneration"),
        ("bigbird_pegasus", "BigBirdPegasusForConditionalGeneration"),
        ("blenderbot", "BlenderbotForConditionalGeneration"),
        ("blenderbot-small", "BlenderbotSmallForConditionalGeneration"),
        ("encoder-decoder", "EncoderDecoderModel"),
        ("fsmt", "FSMTForConditionalGeneration"),
        ("gptsan-japanese", "GPTSanJapaneseForConditionalGeneration"),
        ("led", "LEDForConditionalGeneration"),
        ("longt5", "LongT5ForConditionalGeneration"),
        ("m2m_100", "M2M100ForConditionalGeneration"),
        ("marian", "MarianMTModel"),
        ("mbart", "MBartForConditionalGeneration"),
        ("mt5", "MT5ForConditionalGeneration"),
        ("mvp", "MvpForConditionalGeneration"),
        ("nllb-moe", "NllbMoeForConditionalGeneration"),
        ("pegasus", "PegasusForConditionalGeneration"),
        ("pegasus_x", "PegasusXForConditionalGeneration"),
        ("plbart", "PLBartForConditionalGeneration"),
        ("prophetnet", "ProphetNetForConditionalGeneration"),
        ("seamless_m4t", "SeamlessM4TForTextToText"),
        ("seamless_m4t_v2", "SeamlessM4Tv2ForTextToText"),
        ("switch_transformers", "SwitchTransformersForConditionalGeneration"),
        ("t5", "T5ForConditionalGeneration"),
        ("umt5", "UMT5ForConditionalGeneration"),
        ("xlm-prophetnet", "XLMProphetNetForConditionalGeneration"),
    ]
)

# 定义语音序列到序列模型的名称映射字典,使用有序字典确保顺序性
MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES = OrderedDict(
    [
        # 语音序列到序列模型映射
        ("pop2piano", "Pop2PianoForConditionalGeneration"),
        ("seamless_m4t", "SeamlessM4TForSpeechToText"),
        ("seamless_m4t_v2", "SeamlessM4Tv2ForSpeechToText"),
        ("speech-encoder-decoder", "SpeechEncoderDecoderModel"),
        ("speech_to_text", "Speech2TextForConditionalGeneration"),
        ("speecht5", "SpeechT5ForSpeechToText"),
        ("whisper", "WhisperForConditionalGeneration"),
    ]
)
# 定义用于序列分类模型的名称映射字典
MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    ]
)

# 定义用于问答模型的名称映射字典
MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(
    ]
)

# 定义用于表格问答模型的名称映射字典
MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(
    [
        # 表格问答模型映射
        ("tapas", "TapasForQuestionAnswering"),
    ]
)

# 定义用于视觉问答模型的名称映射字典
MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(
    [
        ("blip", "BlipForQuestionAnswering"),
        ("blip-2", "Blip2ForConditionalGeneration"),
        ("vilt", "ViltForQuestionAnswering"),
    ]
)

# 定义用于文档问答模型的名称映射字典
MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(
    [
        ("layoutlm", "LayoutLMForQuestionAnswering"),
        ("layoutlmv2", "LayoutLMv2ForQuestionAnswering"),
        ("layoutlmv3", "LayoutLMv3ForQuestionAnswering"),
    ]
)

# 定义用于标记分类模型的名称映射字典
MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    ]
)

# 定义用于多项选择模型的名称映射字典
MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES = OrderedDict(
    [
        # 多项选择模型映射
        ("albert", "AlbertForMultipleChoice"),
        ("bert", "BertForMultipleChoice"),
        ("big_bird", "BigBirdForMultipleChoice"),
        ("camembert", "CamembertForMultipleChoice"),
        ("canine", "CanineForMultipleChoice"),
        ("convbert", "ConvBertForMultipleChoice"),
        ("data2vec-text", "Data2VecTextForMultipleChoice"),
        ("deberta-v2", "DebertaV2ForMultipleChoice"),
        ("distilbert", "DistilBertForMultipleChoice"),
        ("electra", "ElectraForMultipleChoice"),
        ("ernie", "ErnieForMultipleChoice"),
        ("ernie_m", "ErnieMForMultipleChoice"),
        ("flaubert", "FlaubertForMultipleChoice"),
        ("fnet", "FNetForMultipleChoice"),
        ("funnel", "FunnelForMultipleChoice"),
        ("ibert", "IBertForMultipleChoice"),
        ("longformer", "LongformerForMultipleChoice"),
        ("luke", "LukeForMultipleChoice"),
        ("mega", "MegaForMultipleChoice"),
        ("megatron-bert", "MegatronBertForMultipleChoice"),
        ("mobilebert", "MobileBertForMultipleChoice"),
        ("mpnet", "MPNetForMultipleChoice"),
        ("mra", "MraForMultipleChoice"),
        ("nezha", "NezhaForMultipleChoice"),
        ("nystromformer", "NystromformerForMultipleChoice"),
        ("qdqbert", "QDQBertForMultipleChoice"),
        ("rembert", "RemBertForMultipleChoice"),
        ("roberta", "RobertaForMultipleChoice"),
        ("roberta-prelayernorm", "RobertaPreLayerNormForMultipleChoice"),
        ("roc_bert", "RoCBertForMultipleChoice"),
        ("roformer", "RoFormerForMultipleChoice"),
        ("squeezebert", "SqueezeBertForMultipleChoice"),
        ("xlm", "XLMForMultipleChoice"),
        ("xlm-roberta", "XLMRobertaForMultipleChoice"),
        ("xlm-roberta-xl", "XLMRobertaXLForMultipleChoice"),
        ("xlnet", "XLNetForMultipleChoice"),
        ("xmod", "XmodForMultipleChoice"),
        ("yoso", "YosoForMultipleChoice"),
    ]
)

# 定义用于下一句预测模型的名称映射字典
MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES = OrderedDict(
    # 留空,等待后续添加
)
    # 定义一个包含模型名称和类名的元组列表,每个元组包含模型的简称和完整类名
    [
        ("bert", "BertForNextSentencePrediction"),  # Bert 模型的简称及其完整类名
        ("ernie", "ErnieForNextSentencePrediction"),  # Ernie 模型的简称及其完整类名
        ("fnet", "FNetForNextSentencePrediction"),  # FNet 模型的简称及其完整类名
        ("megatron-bert", "MegatronBertForNextSentencePrediction"),  # Megatron-Bert 模型的简称及其完整类名
        ("mobilebert", "MobileBertForNextSentencePrediction"),  # MobileBERT 模型的简称及其完整类名
        ("nezha", "NezhaForNextSentencePrediction"),  # Nezha 模型的简称及其完整类名
        ("qdqbert", "QDQBertForNextSentencePrediction"),  # QDQBert 模型的简称及其完整类名
    ]
# 定义一个有序字典,用于映射音频分类模型名称到对应的类名
MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        # 音频分类模型映射
        ("audio-spectrogram-transformer", "ASTForAudioClassification"),
        ("data2vec-audio", "Data2VecAudioForSequenceClassification"),
        ("hubert", "HubertForSequenceClassification"),
        ("sew", "SEWForSequenceClassification"),
        ("sew-d", "SEWDForSequenceClassification"),
        ("unispeech", "UniSpeechForSequenceClassification"),
        ("unispeech-sat", "UniSpeechSatForSequenceClassification"),
        ("wav2vec2", "Wav2Vec2ForSequenceClassification"),
        ("wav2vec2-bert", "Wav2Vec2BertForSequenceClassification"),
        ("wav2vec2-conformer", "Wav2Vec2ConformerForSequenceClassification"),
        ("wavlm", "WavLMForSequenceClassification"),
        ("whisper", "WhisperForAudioClassification"),
    ]
)

# 定义一个有序字典,用于映射连接主义时间分类(CTC)模型名称到对应的类名
MODEL_FOR_CTC_MAPPING_NAMES = OrderedDict(
    [
        # 连接主义时间分类(CTC)模型映射
        ("data2vec-audio", "Data2VecAudioForCTC"),
        ("hubert", "HubertForCTC"),
        ("mctct", "MCTCTForCTC"),
        ("sew", "SEWForCTC"),
        ("sew-d", "SEWDForCTC"),
        ("unispeech", "UniSpeechForCTC"),
        ("unispeech-sat", "UniSpeechSatForCTC"),
        ("wav2vec2", "Wav2Vec2ForCTC"),
        ("wav2vec2-bert", "Wav2Vec2BertForCTC"),
        ("wav2vec2-conformer", "Wav2Vec2ConformerForCTC"),
        ("wavlm", "WavLMForCTC"),
    ]
)

# 定义一个有序字典,用于映射音频帧分类模型名称到对应的类名
MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        # 音频帧分类模型映射
        ("data2vec-audio", "Data2VecAudioForAudioFrameClassification"),
        ("unispeech-sat", "UniSpeechSatForAudioFrameClassification"),
        ("wav2vec2", "Wav2Vec2ForAudioFrameClassification"),
        ("wav2vec2-bert", "Wav2Vec2BertForAudioFrameClassification"),
        ("wav2vec2-conformer", "Wav2Vec2ConformerForAudioFrameClassification"),
        ("wavlm", "WavLMForAudioFrameClassification"),
    ]
)

# 定义一个有序字典,用于映射音频 X-向量模型名称到对应的类名
MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES = OrderedDict(
    [
        # 音频 X-向量模型映射
        ("data2vec-audio", "Data2VecAudioForXVector"),
        ("unispeech-sat", "UniSpeechSatForXVector"),
        ("wav2vec2", "Wav2Vec2ForXVector"),
        ("wav2vec2-bert", "Wav2Vec2BertForXVector"),
        ("wav2vec2-conformer", "Wav2Vec2ConformerForXVector"),
        ("wavlm", "WavLMForXVector"),
    ]
)

# 定义一个有序字典,用于映射文本到频谱图模型名称到对应的类名
MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES = OrderedDict(
    [
        # 文本到频谱图模型映射
        ("fastspeech2_conformer", "FastSpeech2ConformerModel"),
        ("speecht5", "SpeechT5ForTextToSpeech"),
    ]
)

# 定义一个有序字典,用于映射文本到波形图模型名称到对应的类名
MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES = OrderedDict(
    [
        # 定义了多个元组,每个元组表示一个模型名称和对应的类名
        ("bark", "BarkModel"),                            # 模型名 "bark" 对应的类名 "BarkModel"
        ("fastspeech2_conformer", "FastSpeech2ConformerWithHifiGan"),   # 模型名 "fastspeech2_conformer" 对应的类名 "FastSpeech2ConformerWithHifiGan"
        ("musicgen", "MusicgenForConditionalGeneration"),   # 模型名 "musicgen" 对应的类名 "MusicgenForConditionalGeneration"
        ("musicgen_melody", "MusicgenMelodyForConditionalGeneration"),   # 模型名 "musicgen_melody" 对应的类名 "MusicgenMelodyForConditionalGeneration"
        ("seamless_m4t", "SeamlessM4TForTextToSpeech"),     # 模型名 "seamless_m4t" 对应的类名 "SeamlessM4TForTextToSpeech"
        ("seamless_m4t_v2", "SeamlessM4Tv2ForTextToSpeech"),    # 模型名 "seamless_m4t_v2" 对应的类名 "SeamlessM4Tv2ForTextToSpeech"
        ("vits", "VitsModel"),                             # 模型名 "vits" 对应的类名 "VitsModel"
    ]
# 用于零样本图像分类模型映射的有序字典
MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        # 零样本图像分类模型映射
        ("align", "AlignModel"),
        ("altclip", "AltCLIPModel"),
        ("blip", "BlipModel"),
        ("chinese_clip", "ChineseCLIPModel"),
        ("clip", "CLIPModel"),
        ("clipseg", "CLIPSegModel"),
        ("siglip", "SiglipModel"),
    ]
)

# 用于骨干网络映射的有序字典
MODEL_FOR_BACKBONE_MAPPING_NAMES = OrderedDict(
    [
        # 骨干网络映射
        ("beit", "BeitBackbone"),
        ("bit", "BitBackbone"),
        ("convnext", "ConvNextBackbone"),
        ("convnextv2", "ConvNextV2Backbone"),
        ("dinat", "DinatBackbone"),
        ("dinov2", "Dinov2Backbone"),
        ("focalnet", "FocalNetBackbone"),
        ("maskformer-swin", "MaskFormerSwinBackbone"),
        ("nat", "NatBackbone"),
        ("pvt_v2", "PvtV2Backbone"),
        ("resnet", "ResNetBackbone"),
        ("swin", "SwinBackbone"),
        ("swinv2", "Swinv2Backbone"),
        ("timm_backbone", "TimmBackbone"),
        ("vitdet", "VitDetBackbone"),
    ]
)

# 用于遮罩生成模型映射的有序字典
MODEL_FOR_MASK_GENERATION_MAPPING_NAMES = OrderedDict(
    [
        ("sam", "SamModel"),
    ]
)

# 用于关键点检测模型映射的有序字典
MODEL_FOR_KEYPOINT_DETECTION_MAPPING_NAMES = OrderedDict(
    [
        ("superpoint", "SuperPointForKeypointDetection"),
    ]
)

# 用于文本编码模型映射的有序字典
MODEL_FOR_TEXT_ENCODING_MAPPING_NAMES = OrderedDict(
    [
        ("albert", "AlbertModel"),
        ("bert", "BertModel"),
        ("big_bird", "BigBirdModel"),
        ("data2vec-text", "Data2VecTextModel"),
        ("deberta", "DebertaModel"),
        ("deberta-v2", "DebertaV2Model"),
        ("distilbert", "DistilBertModel"),
        ("electra", "ElectraModel"),
        ("flaubert", "FlaubertModel"),
        ("ibert", "IBertModel"),
        ("longformer", "LongformerModel"),
        ("mobilebert", "MobileBertModel"),
        ("mt5", "MT5EncoderModel"),
        ("nystromformer", "NystromformerModel"),
        ("reformer", "ReformerModel"),
        ("rembert", "RemBertModel"),
        ("roberta", "RobertaModel"),
        ("roberta-prelayernorm", "RobertaPreLayerNormModel"),
        ("roc_bert", "RoCBertModel"),
        ("roformer", "RoFormerModel"),
        ("squeezebert", "SqueezeBertModel"),
        ("t5", "T5EncoderModel"),
        ("umt5", "UMT5EncoderModel"),
        ("xlm", "XLMModel"),
        ("xlm-roberta", "XLMRobertaModel"),
        ("xlm-roberta-xl", "XLMRobertaXLModel"),
    ]
)

# 用于时间序列分类模型映射的有序字典
MODEL_FOR_TIME_SERIES_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        ("patchtsmixer", "PatchTSMixerForTimeSeriesClassification"),
        ("patchtst", "PatchTSTForClassification"),
    ]
)

# 用于时间序列回归模型映射的有序字典
MODEL_FOR_TIME_SERIES_REGRESSION_MAPPING_NAMES = OrderedDict(
    [
        ("patchtsmixer", "PatchTSMixerForRegression"),
        ("patchtst", "PatchTSTForRegression"),
    ]
)

# 用于图像到图像映射的有序字典
MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES = OrderedDict(
    [
        ("swin2sr", "Swin2SRForImageSuperResolution"),
    ]
)

# 使用懒加载自动映射生成的模型映射
MODEL_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_MAPPING_NAMES)
# 创建用于预训练模型映射的惰性自动映射对象
MODEL_FOR_PRETRAINING_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_PRETRAINING_MAPPING_NAMES)

# 创建带有语言模型头的模型映射的惰性自动映射对象
MODEL_WITH_LM_HEAD_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_WITH_LM_HEAD_MAPPING_NAMES)

# 创建用于因果语言模型的模型映射的惰性自动映射对象
MODEL_FOR_CAUSAL_LM_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_CAUSAL_LM_MAPPING_NAMES)

# 创建用于因果图像建模的模型映射的惰性自动映射对象
MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING_NAMES)

# 创建用于图像分类的模型映射的惰性自动映射对象
MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES)

# 创建用于零样本图像分类的模型映射的惰性自动映射对象
MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING_NAMES)

# 创建用于图像分割的模型映射的惰性自动映射对象
MODEL_FOR_IMAGE_SEGMENTATION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES)

# 创建用于语义分割的模型映射的惰性自动映射对象
MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES)

# 创建用于实例分割的模型映射的惰性自动映射对象
MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING_NAMES)

# 创建用于通用分割的模型映射的惰性自动映射对象
MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES)

# 创建用于视频分类的模型映射的惰性自动映射对象
MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING_NAMES)

# 创建用于视觉到序列的模型映射的惰性自动映射对象
MODEL_FOR_VISION_2_SEQ_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES)

# 创建用于视觉问答的模型映射的惰性自动映射对象
MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING_NAMES)

# 创建用于文档问答的模型映射的惰性自动映射对象
MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES)

# 创建用于掩蔽语言模型的模型映射的惰性自动映射对象
MODEL_FOR_MASKED_LM_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_MASKED_LM_MAPPING_NAMES)

# 创建用于图像处理的模型映射的惰性自动映射对象
MODEL_FOR_IMAGE_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_IMAGE_MAPPING_NAMES)

# 创建用于掩蔽图像建模的模型映射的惰性自动映射对象
MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING_NAMES)

# 创建用于目标检测的模型映射的惰性自动映射对象
MODEL_FOR_OBJECT_DETECTION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES)

# 创建用于零样本目标检测的模型映射的惰性自动映射对象
MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES)

# 创建用于深度估计的模型映射的惰性自动映射对象
MODEL_FOR_DEPTH_ESTIMATION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES)

# 创建用于序列到序列因果语言模型的模型映射的惰性自动映射对象
MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES)

# 创建用于序列分类的模型映射的惰性自动映射对象
MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES)

# 创建用于问答的模型映射的惰性自动映射对象
MODEL_FOR_QUESTION_ANSWERING_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES)

# 创建用于表格问答的模型映射的惰性自动映射对象
MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING_NAMES
)
    # 导入变量 CONFIG_MAPPING_NAMES 和 MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING_NAMES
    CONFIG_MAPPING_NAMES, MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING_NAMES
# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES
MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES
MODEL_FOR_MULTIPLE_CHOICE_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES
MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES
MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_CTC_MAPPING_NAMES
MODEL_FOR_CTC_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_CTC_MAPPING_NAMES)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES
MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES
MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES
MODEL_FOR_AUDIO_XVECTOR_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES
MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES
MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_BACKBONE_MAPPING_NAMES
MODEL_FOR_BACKBONE_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_BACKBONE_MAPPING_NAMES)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_MASK_GENERATION_MAPPING_NAMES
MODEL_FOR_MASK_GENERATION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_MASK_GENERATION_MAPPING_NAMES)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_KEYPOINT_DETECTION_MAPPING_NAMES
MODEL_FOR_KEYPOINT_DETECTION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_KEYPOINT_DETECTION_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_TEXT_ENCODING_MAPPING_NAMES
MODEL_FOR_TEXT_ENCODING_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_TEXT_ENCODING_MAPPING_NAMES)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_TIME_SERIES_CLASSIFICATION_MAPPING_NAMES
MODEL_FOR_TIME_SERIES_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_TIME_SERIES_CLASSIFICATION_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_TIME_SERIES_REGRESSION_MAPPING_NAMES
MODEL_FOR_TIME_SERIES_REGRESSION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_TIME_SERIES_REGRESSION_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建模型到配置映射,基于 CONFIG_MAPPING_NAMES 和 MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES
MODEL_FOR_IMAGE_TO_IMAGE_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES)
    # 将 MODEL_WITH_LM_HEAD_MAPPING 赋值给 _model_mapping 变量
    _model_mapping = MODEL_WITH_LM_HEAD_MAPPING
# 更新 _AutoModelWithLMHead 类,自动设置头部文档为 "language modeling"
_AutoModelWithLMHead = auto_class_update(_AutoModelWithLMHead, head_doc="language modeling")

# 定义 AutoModelForCausalLM 类,使用 MODEL_FOR_CAUSAL_LM_MAPPING 映射
class AutoModelForCausalLM(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_CAUSAL_LM_MAPPING

# 更新 AutoModelForCausalLM 类,自动设置头部文档为 "causal language modeling"
AutoModelForCausalLM = auto_class_update(AutoModelForCausalLM, head_doc="causal language modeling")

# 定义 AutoModelForMaskedLM 类,使用 MODEL_FOR_MASKED_LM_MAPPING 映射
class AutoModelForMaskedLM(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_MASKED_LM_MAPPING

# 更新 AutoModelForMaskedLM 类,自动设置头部文档为 "masked language modeling"
AutoModelForMaskedLM = auto_class_update(AutoModelForMaskedLM, head_doc="masked language modeling")

# 定义 AutoModelForSeq2SeqLM 类,使用 MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING 映射
class AutoModelForSeq2SeqLM(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

# 更新 AutoModelForSeq2SeqLM 类,自动设置头部文档为 "sequence-to-sequence language modeling"
# 同时设置示例的检查点为 "google-t5/t5-base"
AutoModelForSeq2SeqLM = auto_class_update(
    AutoModelForSeq2SeqLM,
    head_doc="sequence-to-sequence language modeling",
    checkpoint_for_example="google-t5/t5-base",
)

# 定义 AutoModelForSequenceClassification 类,使用 MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING 映射
class AutoModelForSequenceClassification(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

# 更新 AutoModelForSequenceClassification 类,自动设置头部文档为 "sequence classification"
AutoModelForSequenceClassification = auto_class_update(AutoModelForSequenceClassification, head_doc="sequence classification")

# 定义 AutoModelForQuestionAnswering 类,使用 MODEL_FOR_QUESTION_ANSWERING_MAPPING 映射
class AutoModelForQuestionAnswering(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_QUESTION_ANSWERING_MAPPING

# 更新 AutoModelForQuestionAnswering 类,自动设置头部文档为 "question answering"
AutoModelForQuestionAnswering = auto_class_update(AutoModelForQuestionAnswering, head_doc="question answering")

# 定义 AutoModelForTableQuestionAnswering 类,使用 MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING 映射
class AutoModelForTableQuestionAnswering(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING

# 更新 AutoModelForTableQuestionAnswering 类,自动设置头部文档为 "table question answering"
# 同时设置示例的检查点为 "google/tapas-base-finetuned-wtq"
AutoModelForTableQuestionAnswering = auto_class_update(
    AutoModelForTableQuestionAnswering,
    head_doc="table question answering",
    checkpoint_for_example="google/tapas-base-finetuned-wtq",
)

# 定义 AutoModelForVisualQuestionAnswering 类,使用 MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING 映射
class AutoModelForVisualQuestionAnswering(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING

# 更新 AutoModelForVisualQuestionAnswering 类,自动设置头部文档为 "visual question answering"
# 同时设置示例的检查点为 "dandelin/vilt-b32-finetuned-vqa"
AutoModelForVisualQuestionAnswering = auto_class_update(
    AutoModelForVisualQuestionAnswering,
    head_doc="visual question answering",
    checkpoint_for_example="dandelin/vilt-b32-finetuned-vqa",
)

# 定义 AutoModelForDocumentQuestionAnswering 类,使用 MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING 映射
class AutoModelForDocumentQuestionAnswering(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING

# 更新 AutoModelForDocumentQuestionAnswering 类,自动设置头部文档为 "document question answering"
# 同时设置示例的检查点为 'impira/layoutlm-document-qa", revision="52e01b3'
AutoModelForDocumentQuestionAnswering = auto_class_update(
    AutoModelForDocumentQuestionAnswering,
    head_doc="document question answering",
    checkpoint_for_example='impira/layoutlm-document-qa", revision="52e01b3',
)

# 定义 AutoModelForTokenClassification 类,使用 MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING 映射
class AutoModelForTokenClassification(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING

# 更新 AutoModelForTokenClassification 类,自动设置头部文档为 "token classification"
AutoModelForTokenClassification = auto_class_update(AutoModelForTokenClassification, head_doc="token classification")

# 定义 AutoModelForMultipleChoice 类,使用 MODEL_FOR_MULTIPLE_CHOICE_MAPPING 映射
class AutoModelForMultipleChoice(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_MULTIPLE_CHOICE_MAPPING

# 更新 AutoModelForMultipleChoice 类,自动设置头部文档为 "multiple choice"
AutoModelForMultipleChoice = auto_class_update(AutoModelForMultipleChoice, head_doc="multiple choice")

# 定义 AutoModelForNextSentencePrediction 类,使用 MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING 映射
class AutoModelForNextSentencePrediction(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING

# 更新 AutoModelForNextSentencePrediction 类,未完成的部分,可能有其它设置或定义。
    # 导入 AutoModelForNextSentencePrediction 类,并为其指定 head_doc 参数为 "next sentence prediction"
    AutoModelForNextSentencePrediction, head_doc="next sentence prediction"
class AutoModelForImageClassification(_BaseAutoModelClass):
    # 自动化生成的图像分类模型类,使用预定义的模型映射
    _model_mapping = MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING


AutoModelForImageClassification = auto_class_update(AutoModelForImageClassification, head_doc="image classification")


class AutoModelForZeroShotImageClassification(_BaseAutoModelClass):
    # 自动化生成的零样本图像分类模型类,使用预定义的模型映射
    _model_mapping = MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING


AutoModelForZeroShotImageClassification = auto_class_update(
    AutoModelForZeroShotImageClassification, head_doc="zero-shot image classification"
)


class AutoModelForImageSegmentation(_BaseAutoModelClass):
    # 自动化生成的图像分割模型类,使用预定义的模型映射
    _model_mapping = MODEL_FOR_IMAGE_SEGMENTATION_MAPPING


AutoModelForImageSegmentation = auto_class_update(AutoModelForImageSegmentation, head_doc="image segmentation")


class AutoModelForSemanticSegmentation(_BaseAutoModelClass):
    # 自动化生成的语义分割模型类,使用预定义的模型映射
    _model_mapping = MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING


AutoModelForSemanticSegmentation = auto_class_update(
    AutoModelForSemanticSegmentation, head_doc="semantic segmentation"
)


class AutoModelForUniversalSegmentation(_BaseAutoModelClass):
    # 自动化生成的通用图像分割模型类,使用预定义的模型映射
    _model_mapping = MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING


AutoModelForUniversalSegmentation = auto_class_update(
    AutoModelForUniversalSegmentation, head_doc="universal image segmentation"
)


class AutoModelForInstanceSegmentation(_BaseAutoModelClass):
    # 自动化生成的实例分割模型类,使用预定义的模型映射
    _model_mapping = MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING


AutoModelForInstanceSegmentation = auto_class_update(
    AutoModelForInstanceSegmentation, head_doc="instance segmentation"
)


class AutoModelForObjectDetection(_BaseAutoModelClass):
    # 自动化生成的物体检测模型类,使用预定义的模型映射
    _model_mapping = MODEL_FOR_OBJECT_DETECTION_MAPPING


AutoModelForObjectDetection = auto_class_update(AutoModelForObjectDetection, head_doc="object detection")


class AutoModelForZeroShotObjectDetection(_BaseAutoModelClass):
    # 自动化生成的零样本物体检测模型类,使用预定义的模型映射
    _model_mapping = MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING


AutoModelForZeroShotObjectDetection = auto_class_update(
    AutoModelForZeroShotObjectDetection, head_doc="zero-shot object detection"
)


class AutoModelForDepthEstimation(_BaseAutoModelClass):
    # 自动化生成的深度估计模型类,使用预定义的模型映射
    _model_mapping = MODEL_FOR_DEPTH_ESTIMATION_MAPPING


AutoModelForDepthEstimation = auto_class_update(AutoModelForDepthEstimation, head_doc="depth estimation")


class AutoModelForVideoClassification(_BaseAutoModelClass):
    # 自动化生成的视频分类模型类,使用预定义的模型映射
    _model_mapping = MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING


AutoModelForVideoClassification = auto_class_update(AutoModelForVideoClassification, head_doc="video classification")


class AutoModelForVision2Seq(_BaseAutoModelClass):
    # 自动化生成的视觉到文本模型类,使用预定义的模型映射
    _model_mapping = MODEL_FOR_VISION_2_SEQ_MAPPING


AutoModelForVision2Seq = auto_class_update(AutoModelForVision2Seq, head_doc="vision-to-text modeling")


class AutoModelForAudioClassification(_BaseAutoModelClass):
    # 自动化生成的音频分类模型类,使用预定义的模型映射
    _model_mapping = MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING


AutoModelForAudioClassification = auto_class_update(AutoModelForAudioClassification, head_doc="audio classification")
    # 将 MODEL_FOR_CTC_MAPPING 赋值给 _model_mapping
    _model_mapping = MODEL_FOR_CTC_MAPPING
# 使用 auto_class_update 函数更新 AutoModelForCTC 类,添加头部文档说明
AutoModelForCTC = auto_class_update(AutoModelForCTC, head_doc="connectionist temporal classification")

# 定义 AutoModelForSpeechSeq2Seq 类,映射到 MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING
class AutoModelForSpeechSeq2Seq(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING

# 使用 auto_class_update 函数更新 AutoModelForSpeechSeq2Seq 类,添加头部文档说明
AutoModelForSpeechSeq2Seq = auto_class_update(
    AutoModelForSpeechSeq2Seq, head_doc="sequence-to-sequence speech-to-text modeling"
)

# 定义 AutoModelForAudioFrameClassification 类,映射到 MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING
class AutoModelForAudioFrameClassification(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING

# 使用 auto_class_update 函数更新 AutoModelForAudioFrameClassification 类,添加头部文档说明
AutoModelForAudioFrameClassification = auto_class_update(
    AutoModelForAudioFrameClassification, head_doc="audio frame (token) classification"
)

# 定义 AutoModelForAudioXVector 类,映射到 MODEL_FOR_AUDIO_XVECTOR_MAPPING
class AutoModelForAudioXVector(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_AUDIO_XVECTOR_MAPPING

# 定义 AutoModelForTextToSpectrogram 类,映射到 MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING
class AutoModelForTextToSpectrogram(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING

# 定义 AutoModelForTextToWaveform 类,映射到 MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING
class AutoModelForTextToWaveform(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING

# 定义 AutoBackbone 类,映射到 MODEL_FOR_BACKBONE_MAPPING
class AutoBackbone(_BaseAutoBackboneClass):
    _model_mapping = MODEL_FOR_BACKBONE_MAPPING

# 使用 auto_class_update 函数更新 AutoModelForAudioXVector 类,添加头部文档说明
AutoModelForAudioXVector = auto_class_update(AutoModelForAudioXVector, head_doc="audio retrieval via x-vector")

# 定义 AutoModelForMaskedImageModeling 类,映射到 MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING
class AutoModelForMaskedImageModeling(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING

# 使用 auto_class_update 函数更新 AutoModelForMaskedImageModeling 类,添加头部文档说明
AutoModelForMaskedImageModeling = auto_class_update(AutoModelForMaskedImageModeling, head_doc="masked image modeling")

# 定义 AutoModelWithLMHead 类,继承自 _AutoModelWithLMHead
class AutoModelWithLMHead(_AutoModelWithLMHead):
    # 从给定配置创建对象的类方法,发出未来版本移除警告
    @classmethod
    def from_config(cls, config):
        warnings.warn(
            "The class `AutoModelWithLMHead` is deprecated and will be removed in a future version. Please use "
            "`AutoModelForCausalLM` for causal language models, `AutoModelForMaskedLM` for masked language models and "
            "`AutoModelForSeq2SeqLM` for encoder-decoder models.",
            FutureWarning,
        )
        return super().from_config(config)

    # 从预训练模型创建对象的类方法,发出未来版本移除警告
    @classmethod
    def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
        warnings.warn(
            "The class `AutoModelWithLMHead` is deprecated and will be removed in a future version. Please use "
            "`AutoModelForCausalLM` for causal language models, `AutoModelForMaskedLM` for masked language models and "
            "`AutoModelForSeq2SeqLM` for encoder-decoder models.",
            FutureWarning,
        )
        return super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)

.\models\auto\modeling_flax_auto.py

# 导入必要的模块和函数
from collections import OrderedDict
# 导入日志记录器
from ...utils import logging
# 导入自动模型工厂相关类和函数
from .auto_factory import _BaseAutoModelClass, _LazyAutoMapping, auto_class_update
# 导入自动配置映射名称
from .configuration_auto import CONFIG_MAPPING_NAMES

# 获取当前模块的日志记录器
logger = logging.get_logger(__name__)

# 定义模型名称到类的映射字典,用OrderedDict确保顺序
FLAX_MODEL_MAPPING_NAMES = OrderedDict(
    [
        # 基础模型映射
        ("albert", "FlaxAlbertModel"),
        ("bart", "FlaxBartModel"),
        ("beit", "FlaxBeitModel"),
        ("bert", "FlaxBertModel"),
        ("big_bird", "FlaxBigBirdModel"),
        ("blenderbot", "FlaxBlenderbotModel"),
        ("blenderbot-small", "FlaxBlenderbotSmallModel"),
        ("bloom", "FlaxBloomModel"),
        ("clip", "FlaxCLIPModel"),
        ("distilbert", "FlaxDistilBertModel"),
        ("electra", "FlaxElectraModel"),
        ("gemma", "FlaxGemmaModel"),
        ("gpt-sw3", "FlaxGPT2Model"),
        ("gpt2", "FlaxGPT2Model"),
        ("gpt_neo", "FlaxGPTNeoModel"),
        ("gptj", "FlaxGPTJModel"),
        ("llama", "FlaxLlamaModel"),
        ("longt5", "FlaxLongT5Model"),
        ("marian", "FlaxMarianModel"),
        ("mbart", "FlaxMBartModel"),
        ("mistral", "FlaxMistralModel"),
        ("mt5", "FlaxMT5Model"),
        ("opt", "FlaxOPTModel"),
        ("pegasus", "FlaxPegasusModel"),
        ("regnet", "FlaxRegNetModel"),
        ("resnet", "FlaxResNetModel"),
        ("roberta", "FlaxRobertaModel"),
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormModel"),
        ("roformer", "FlaxRoFormerModel"),
        ("t5", "FlaxT5Model"),
        ("vision-text-dual-encoder", "FlaxVisionTextDualEncoderModel"),
        ("vit", "FlaxViTModel"),
        ("wav2vec2", "FlaxWav2Vec2Model"),
        ("whisper", "FlaxWhisperModel"),
        ("xglm", "FlaxXGLMModel"),
        ("xlm-roberta", "FlaxXLMRobertaModel"),
    ]
)

# 定义用于预训练任务的模型名称到类的映射字典,初始化为空OrderedDict
FLAX_MODEL_FOR_PRETRAINING_MAPPING_NAMES = OrderedDict(
    [
        # 预训练模型到 Flax 模型类的映射关系列表
    
        # ("albert", "FlaxAlbertForPreTraining") 表示将 "albert" 映射到 Flax 中的 FlaxAlbertForPreTraining 类
        ("albert", "FlaxAlbertForPreTraining"),
    
        # ("bart", "FlaxBartForConditionalGeneration") 表示将 "bart" 映射到 Flax 中的 FlaxBartForConditionalGeneration 类
        ("bart", "FlaxBartForConditionalGeneration"),
    
        # ("bert", "FlaxBertForPreTraining") 表示将 "bert" 映射到 Flax 中的 FlaxBertForPreTraining 类
        ("bert", "FlaxBertForPreTraining"),
    
        # ("big_bird", "FlaxBigBirdForPreTraining") 表示将 "big_bird" 映射到 Flax 中的 FlaxBigBirdForPreTraining 类
        ("big_bird", "FlaxBigBirdForPreTraining"),
    
        # ("electra", "FlaxElectraForPreTraining") 表示将 "electra" 映射到 Flax 中的 FlaxElectraForPreTraining 类
        ("electra", "FlaxElectraForPreTraining"),
    
        # ("longt5", "FlaxLongT5ForConditionalGeneration") 表示将 "longt5" 映射到 Flax 中的 FlaxLongT5ForConditionalGeneration 类
        ("longt5", "FlaxLongT5ForConditionalGeneration"),
    
        # ("mbart", "FlaxMBartForConditionalGeneration") 表示将 "mbart" 映射到 Flax 中的 FlaxMBartForConditionalGeneration 类
        ("mbart", "FlaxMBartForConditionalGeneration"),
    
        # ("mt5", "FlaxMT5ForConditionalGeneration") 表示将 "mt5" 映射到 Flax 中的 FlaxMT5ForConditionalGeneration 类
        ("mt5", "FlaxMT5ForConditionalGeneration"),
    
        # ("roberta", "FlaxRobertaForMaskedLM") 表示将 "roberta" 映射到 Flax 中的 FlaxRobertaForMaskedLM 类
        ("roberta", "FlaxRobertaForMaskedLM"),
    
        # ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForMaskedLM") 表示将 "roberta-prelayernorm" 映射到 Flax 中的 FlaxRobertaPreLayerNormForMaskedLM 类
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForMaskedLM"),
    
        # ("roformer", "FlaxRoFormerForMaskedLM") 表示将 "roformer" 映射到 Flax 中的 FlaxRoFormerForMaskedLM 类
        ("roformer", "FlaxRoFormerForMaskedLM"),
    
        # ("t5", "FlaxT5ForConditionalGeneration") 表示将 "t5" 映射到 Flax 中的 FlaxT5ForConditionalGeneration 类
        ("t5", "FlaxT5ForConditionalGeneration"),
    
        # ("wav2vec2", "FlaxWav2Vec2ForPreTraining") 表示将 "wav2vec2" 映射到 Flax 中的 FlaxWav2Vec2ForPreTraining 类
        ("wav2vec2", "FlaxWav2Vec2ForPreTraining"),
    
        # ("whisper", "FlaxWhisperForConditionalGeneration") 表示将 "whisper" 映射到 Flax 中的 FlaxWhisperForConditionalGeneration 类
        ("whisper", "FlaxWhisperForConditionalGeneration"),
    
        # ("xlm-roberta", "FlaxXLMRobertaForMaskedLM") 表示将 "xlm-roberta" 映射到 Flax 中的 FlaxXLMRobertaForMaskedLM 类
        ("xlm-roberta", "FlaxXLMRobertaForMaskedLM"),
    ]
# 带有模型名称到对应 Flax 模型类的映射字典,用于 Masked LM 模型
FLAX_MODEL_FOR_MASKED_LM_MAPPING_NAMES = OrderedDict(
    [
        # 模型为 Masked LM 时的映射
        ("albert", "FlaxAlbertForMaskedLM"),
        ("bart", "FlaxBartForConditionalGeneration"),
        ("bert", "FlaxBertForMaskedLM"),
        ("big_bird", "FlaxBigBirdForMaskedLM"),
        ("distilbert", "FlaxDistilBertForMaskedLM"),
        ("electra", "FlaxElectraForMaskedLM"),
        ("mbart", "FlaxMBartForConditionalGeneration"),
        ("roberta", "FlaxRobertaForMaskedLM"),
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForMaskedLM"),
        ("roformer", "FlaxRoFormerForMaskedLM"),
        ("xlm-roberta", "FlaxXLMRobertaForMaskedLM"),
    ]
)

# 带有模型名称到对应 Flax 模型类的映射字典,用于 Seq2Seq Causal LM 模型
FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES = OrderedDict(
    [
        # 模型为 Seq2Seq Causal LM 时的映射
        ("bart", "FlaxBartForConditionalGeneration"),
        ("blenderbot", "FlaxBlenderbotForConditionalGeneration"),
        ("blenderbot-small", "FlaxBlenderbotSmallForConditionalGeneration"),
        ("encoder-decoder", "FlaxEncoderDecoderModel"),
        ("longt5", "FlaxLongT5ForConditionalGeneration"),
        ("marian", "FlaxMarianMTModel"),
        ("mbart", "FlaxMBartForConditionalGeneration"),
        ("mt5", "FlaxMT5ForConditionalGeneration"),
        ("pegasus", "FlaxPegasusForConditionalGeneration"),
        ("t5", "FlaxT5ForConditionalGeneration"),
    ]
)

# 带有模型名称到对应 Flax 模型类的映射字典,用于图像分类模型
FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        # 图像分类模型的映射
        ("beit", "FlaxBeitForImageClassification"),
        ("regnet", "FlaxRegNetForImageClassification"),
        ("resnet", "FlaxResNetForImageClassification"),
        ("vit", "FlaxViTForImageClassification"),
    ]
)

# 带有模型名称到对应 Flax 模型类的映射字典,用于 Vision 2 Seq 模型
FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES = OrderedDict(
    [
        ("vision-encoder-decoder", "FlaxVisionEncoderDecoderModel"),
    ]
)

# 带有模型名称到对应 Flax 模型类的映射字典,用于 Causal LM 模型
FLAX_MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = OrderedDict(
    [
        # 模型为 Causal LM 时的映射
        ("bart", "FlaxBartForCausalLM"),
        ("bert", "FlaxBertForCausalLM"),
        ("big_bird", "FlaxBigBirdForCausalLM"),
        ("bloom", "FlaxBloomForCausalLM"),
        ("electra", "FlaxElectraForCausalLM"),
        ("gemma", "FlaxGemmaForCausalLM"),
        ("gpt-sw3", "FlaxGPT2LMHeadModel"),
        ("gpt2", "FlaxGPT2LMHeadModel"),
        ("gpt_neo", "FlaxGPTNeoForCausalLM"),
        ("gptj", "FlaxGPTJForCausalLM"),
        ("llama", "FlaxLlamaForCausalLM"),
        ("mistral", "FlaxMistralForCausalLM"),
        ("opt", "FlaxOPTForCausalLM"),
        ("roberta", "FlaxRobertaForCausalLM"),
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForCausalLM"),
        ("xglm", "FlaxXGLMForCausalLM"),
        ("xlm-roberta", "FlaxXLMRobertaForCausalLM"),
    ]
)

# 带有模型名称到对应 Flax 模型类的映射字典,用于序列分类模型
FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        # 定义了一系列元组,每个元组包含两个字符串:
        # 第一个字符串是模型的名称,第二个字符串是用于该模型的序列分类任务的类名
        ("albert", "FlaxAlbertForSequenceClassification"),
        ("bart", "FlaxBartForSequenceClassification"),
        ("bert", "FlaxBertForSequenceClassification"),
        ("big_bird", "FlaxBigBirdForSequenceClassification"),
        ("distilbert", "FlaxDistilBertForSequenceClassification"),
        ("electra", "FlaxElectraForSequenceClassification"),
        ("mbart", "FlaxMBartForSequenceClassification"),
        ("roberta", "FlaxRobertaForSequenceClassification"),
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForSequenceClassification"),
        ("roformer", "FlaxRoFormerForSequenceClassification"),
        ("xlm-roberta", "FlaxXLMRobertaForSequenceClassification"),
    ]
# 定义用于问题回答的模型名称映射字典
FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(
    [
        # 将 "albert" 映射到 FlaxAlbertForQuestionAnswering
        ("albert", "FlaxAlbertForQuestionAnswering"),
        # 将 "bart" 映射到 FlaxBartForQuestionAnswering
        ("bart", "FlaxBartForQuestionAnswering"),
        # 将 "bert" 映射到 FlaxBertForQuestionAnswering
        ("bert", "FlaxBertForQuestionAnswering"),
        # 将 "big_bird" 映射到 FlaxBigBirdForQuestionAnswering
        ("big_bird", "FlaxBigBirdForQuestionAnswering"),
        # 将 "distilbert" 映射到 FlaxDistilBertForQuestionAnswering
        ("distilbert", "FlaxDistilBertForQuestionAnswering"),
        # 将 "electra" 映射到 FlaxElectraForQuestionAnswering
        ("electra", "FlaxElectraForQuestionAnswering"),
        # 将 "mbart" 映射到 FlaxMBartForQuestionAnswering
        ("mbart", "FlaxMBartForQuestionAnswering"),
        # 将 "roberta" 映射到 FlaxRobertaForQuestionAnswering
        ("roberta", "FlaxRobertaForQuestionAnswering"),
        # 将 "roberta-prelayernorm" 映射到 FlaxRobertaPreLayerNormForQuestionAnswering
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForQuestionAnswering"),
        # 将 "roformer" 映射到 FlaxRoFormerForQuestionAnswering
        ("roformer", "FlaxRoFormerForQuestionAnswering"),
        # 将 "xlm-roberta" 映射到 FlaxXLMRobertaForQuestionAnswering
        ("xlm-roberta", "FlaxXLMRobertaForQuestionAnswering"),
    ]
)

# 定义用于标记分类的模型名称映射字典
FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        # 将 "albert" 映射到 FlaxAlbertForTokenClassification
        ("albert", "FlaxAlbertForTokenClassification"),
        # 将 "bert" 映射到 FlaxBertForTokenClassification
        ("bert", "FlaxBertForTokenClassification"),
        # 将 "big_bird" 映射到 FlaxBigBirdForTokenClassification
        ("big_bird", "FlaxBigBirdForTokenClassification"),
        # 将 "distilbert" 映射到 FlaxDistilBertForTokenClassification
        ("distilbert", "FlaxDistilBertForTokenClassification"),
        # 将 "electra" 映射到 FlaxElectraForTokenClassification
        ("electra", "FlaxElectraForTokenClassification"),
        # 将 "roberta" 映射到 FlaxRobertaForTokenClassification
        ("roberta", "FlaxRobertaForTokenClassification"),
        # 将 "roberta-prelayernorm" 映射到 FlaxRobertaPreLayerNormForTokenClassification
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForTokenClassification"),
        # 将 "roformer" 映射到 FlaxRoFormerForTokenClassification
        ("roformer", "FlaxRoFormerForTokenClassification"),
        # 将 "xlm-roberta" 映射到 FlaxXLMRobertaForTokenClassification
        ("xlm-roberta", "FlaxXLMRobertaForTokenClassification"),
    ]
)

# 定义用于多项选择的模型名称映射字典
FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES = OrderedDict(
    [
        # 将 "albert" 映射到 FlaxAlbertForMultipleChoice
        ("albert", "FlaxAlbertForMultipleChoice"),
        # 将 "bert" 映射到 FlaxBertForMultipleChoice
        ("bert", "FlaxBertForMultipleChoice"),
        # 将 "big_bird" 映射到 FlaxBigBirdForMultipleChoice
        ("big_bird", "FlaxBigBirdForMultipleChoice"),
        # 将 "distilbert" 映射到 FlaxDistilBertForMultipleChoice
        ("distilbert", "FlaxDistilBertForMultipleChoice"),
        # 将 "electra" 映射到 FlaxElectraForMultipleChoice
        ("electra", "FlaxElectraForMultipleChoice"),
        # 将 "roberta" 映射到 FlaxRobertaForMultipleChoice
        ("roberta", "FlaxRobertaForMultipleChoice"),
        # 将 "roberta-prelayernorm" 映射到 FlaxRobertaPreLayerNormForMultipleChoice
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForMultipleChoice"),
        # 将 "roformer" 映射到 FlaxRoFormerForMultipleChoice
        ("roformer", "FlaxRoFormerForMultipleChoice"),
        # 将 "xlm-roberta" 映射到 FlaxXLMRobertaForMultipleChoice
        ("xlm-roberta", "FlaxXLMRobertaForMultipleChoice"),
    ]
)

# 定义用于下一个句子预测的模型名称映射字典
FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES = OrderedDict(
    [
        # 将 "bert" 映射到 FlaxBertForNextSentencePrediction
        ("bert", "FlaxBertForNextSentencePrediction"),
    ]
)

# 定义用于语音序列到序列的模型名称映射字典
FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES = OrderedDict(
    [
        # 将 "speech-encoder-decoder" 映射到 FlaxSpeechEncoderDecoderModel
        ("speech-encoder-decoder", "FlaxSpeechEncoderDecoderModel"),
        # 将 "whisper" 映射到 FlaxWhisperForConditionalGeneration
        ("whisper", "FlaxWhisperForConditionalGeneration"),
    ]
)

# 定义用于音频分类的模型名称映射字典
FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        # 将 "whisper" 映射到 FlaxWhisperForAudioClassification
        ("whisper", "FlaxWhisperForAudioClassification"),
    ]
)

# 定义 Flax 模型映射对象,通过 LazyAutoMapping 进行自动映射
FLAX_MODEL_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_MAPPING_NAMES)
# 定义用于预训练的 Flax 模型映射对象
FLAX_MODEL_FOR_PRETRAINING_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_PRETRAINING_MAPPING_NAMES)
# 定义用于遮盖语言模型的 Flax 模型映射对象
FLAX_MODEL_FOR_MASKED_LM_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_MASKED_LM_MAPPING_NAMES)
# 定义用于序列到序列因果语言模型的 Flax 模型映射对象
FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES)
    # 导入两个变量:CONFIG_MAPPING_NAMES 和 FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES
# 使用 _LazyAutoMapping 类创建 FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING 映射
FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建 FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING 映射
FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES)

# 使用 _LazyAutoMapping 类创建 FLAX_MODEL_FOR_CAUSAL_LM_MAPPING 映射
FLAX_MODEL_FOR_CAUSAL_LM_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_CAUSAL_LM_MAPPING_NAMES)

# 使用 _LazyAutoMapping 类创建 FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING 映射
FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建 FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING 映射
FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建 FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING 映射
FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建 FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING 映射
FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建 FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING 映射
FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建 FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING 映射
FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES
)

# 使用 _LazyAutoMapping 类创建 FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING 映射
FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES
)

# 定义 FlaxAutoModel 类,并将 _model_mapping 设置为 FLAX_MODEL_MAPPING
class FlaxAutoModel(_BaseAutoModelClass):
    _model_mapping = FLAX_MODEL_MAPPING

# 使用 auto_class_update 函数更新 FlaxAutoModel
FlaxAutoModel = auto_class_update(FlaxAutoModel)

# 定义 FlaxAutoModelForPreTraining 类,并将 _model_mapping 设置为 FLAX_MODEL_FOR_PRETRAINING_MAPPING
class FlaxAutoModelForPreTraining(_BaseAutoModelClass):
    _model_mapping = FLAX_MODEL_FOR_PRETRAINING_MAPPING

# 使用 auto_class_update 函数更新 FlaxAutoModelForPreTraining,并设置头部文档为 "pretraining"
FlaxAutoModelForPreTraining = auto_class_update(FlaxAutoModelForPreTraining, head_doc="pretraining")

# 定义 FlaxAutoModelForCausalLM 类,并将 _model_mapping 设置为 FLAX_MODEL_FOR_CAUSAL_LM_MAPPING
class FlaxAutoModelForCausalLM(_BaseAutoModelClass):
    _model_mapping = FLAX_MODEL_FOR_CAUSAL_LM_MAPPING

# 使用 auto_class_update 函数更新 FlaxAutoModelForCausalLM,并设置头部文档为 "causal language modeling"
FlaxAutoModelForCausalLM = auto_class_update(FlaxAutoModelForCausalLM, head_doc="causal language modeling")

# 定义 FlaxAutoModelForMaskedLM 类,并将 _model_mapping 设置为 FLAX_MODEL_FOR_MASKED_LM_MAPPING
class FlaxAutoModelForMaskedLM(_BaseAutoModelClass):
    _model_mapping = FLAX_MODEL_FOR_MASKED_LM_MAPPING

# 使用 auto_class_update 函数更新 FlaxAutoModelForMaskedLM,并设置头部文档为 "masked language modeling"
FlaxAutoModelForMaskedLM = auto_class_update(FlaxAutoModelForMaskedLM, head_doc="masked language modeling")

# 定义 FlaxAutoModelForSeq2SeqLM 类,并将 _model_mapping 设置为 FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
class FlaxAutoModelForSeq2SeqLM(_BaseAutoModelClass):
    _model_mapping = FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

# 使用 auto_class_update 函数更新 FlaxAutoModelForSeq2SeqLM,并设置头部文档为 "sequence-to-sequence language modeling",以及示例检查点为 "google-t5/t5-base"
FlaxAutoModelForSeq2SeqLM = auto_class_update(
    FlaxAutoModelForSeq2SeqLM,
    head_doc="sequence-to-sequence language modeling",
    checkpoint_for_example="google-t5/t5-base",
)

# 定义 FlaxAutoModelForSequenceClassification 类,并将 _model_mapping 设置为 FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
class FlaxAutoModelForSequenceClassification(_BaseAutoModelClass):
    _model_mapping = FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

# 使用 auto_class_update 函数更新 FlaxAutoModelForSequenceClassification,并设置头部文档为 "sequence classification"
FlaxAutoModelForSequenceClassification = auto_class_update(
    FlaxAutoModelForSequenceClassification, head_doc="sequence classification"
)

# 定义 FlaxAutoModelForQuestionAnswering 类,并将 _model_mapping 设置为 FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING
class FlaxAutoModelForQuestionAnswering(_BaseAutoModelClass):
    _model_mapping = FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING

# 使用 auto_class_update 函数更新 FlaxAutoModelForQuestionAnswering,并设置头部文档为 "question answering"
FlaxAutoModelForQuestionAnswering = auto_class_update(FlaxAutoModelForQuestionAnswering, head_doc="question answering")
# 定义用于标记分类任务的自动化模型类
class FlaxAutoModelForTokenClassification(_BaseAutoModelClass):
    # 指定模型映射到标记分类任务的类别
    _model_mapping = FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING


# 更新标记分类任务模型类,添加头部文档说明为"token classification"
FlaxAutoModelForTokenClassification = auto_class_update(
    FlaxAutoModelForTokenClassification, head_doc="token classification"
)


# 定义用于多项选择任务的自动化模型类
class FlaxAutoModelForMultipleChoice(_BaseAutoModelClass):
    # 指定模型映射到多项选择任务的类别
    _model_mapping = FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING


# 更新多项选择任务模型类,添加头部文档说明为"multiple choice"
FlaxAutoModelForMultipleChoice = auto_class_update(FlaxAutoModelForMultipleChoice, head_doc="multiple choice")


# 定义用于下一句预测任务的自动化模型类
class FlaxAutoModelForNextSentencePrediction(_BaseAutoModelClass):
    # 指定模型映射到下一句预测任务的类别
    _model_mapping = FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING


# 更新下一句预测任务模型类,添加头部文档说明为"next sentence prediction"
FlaxAutoModelForNextSentencePrediction = auto_class_update(
    FlaxAutoModelForNextSentencePrediction, head_doc="next sentence prediction"
)


# 定义用于图像分类任务的自动化模型类
class FlaxAutoModelForImageClassification(_BaseAutoModelClass):
    # 指定模型映射到图像分类任务的类别
    _model_mapping = FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING


# 更新图像分类任务模型类,添加头部文档说明为"image classification"
FlaxAutoModelForImageClassification = auto_class_update(
    FlaxAutoModelForImageClassification, head_doc="image classification"
)


# 定义用于视觉到文本建模任务的自动化模型类
class FlaxAutoModelForVision2Seq(_BaseAutoModelClass):
    # 指定模型映射到视觉到文本建模任务的类别
    _model_mapping = FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING


# 更新视觉到文本建模任务模型类,添加头部文档说明为"vision-to-text modeling"
FlaxAutoModelForVision2Seq = auto_class_update(FlaxAutoModelForVision2Seq, head_doc="vision-to-text modeling")


# 定义用于语音序列到序列建模任务的自动化模型类
class FlaxAutoModelForSpeechSeq2Seq(_BaseAutoModelClass):
    # 指定模型映射到语音序列到序列建模任务的类别
    _model_mapping = FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING


# 更新语音序列到序列建模任务模型类,添加头部文档说明为"sequence-to-sequence speech-to-text modeling"
FlaxAutoModelForSpeechSeq2Seq = auto_class_update(
    FlaxAutoModelForSpeechSeq2Seq, head_doc="sequence-to-sequence speech-to-text modeling"
)
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐