CoolFace
Modelpublic

MathLLMs/MathCoder-VL-8B

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
6likes77downloads
configuration_intern_vit.py120 linesDownload Raw Back to root
1# --------------------------------------------------------2# InternVL3# Copyright (c) 2024 OpenGVLab4# Licensed under The MIT License [see LICENSE for details]5# --------------------------------------------------------6import os7from typing import Union8 9from transformers.configuration_utils import PretrainedConfig10from transformers.utils import logging11 12logger = logging.get_logger(__name__)13 14 15class InternVisionConfig(PretrainedConfig):16    r"""17    This is the configuration class to store the configuration of a [`InternVisionModel`]. It is used to18    instantiate a vision encoder according to the specified arguments, defining the model architecture.19 20    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the21    documentation from [`PretrainedConfig`] for more information.22 23    Args:24        num_channels (`int`, *optional*, defaults to 3):25            Number of color channels in the input images (e.g., 3 for RGB).26        patch_size (`int`, *optional*, defaults to 14):27            The size (resolution) of each patch.28        image_size (`int`, *optional*, defaults to 224):29            The size (resolution) of each image.30        qkv_bias (`bool`, *optional*, defaults to `False`):31            Whether to add a bias to the queries and values in the self-attention layers.32        hidden_size (`int`, *optional*, defaults to 3200):33            Dimensionality of the encoder layers and the pooler layer.34        num_attention_heads (`int`, *optional*, defaults to 25):35            Number of attention heads for each attention layer in the Transformer encoder.36        intermediate_size (`int`, *optional*, defaults to 12800):37            Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.38        qk_normalization (`bool`, *optional*, defaults to `True`):39            Whether to normalize the queries and keys in the self-attention layers.40        num_hidden_layers (`int`, *optional*, defaults to 48):41            Number of hidden layers in the Transformer encoder.42        use_flash_attn (`bool`, *optional*, defaults to `True`):43            Whether to use flash attention mechanism.44        hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):45            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,46            `"relu"`, `"selu"` and `"gelu_new"` ``"gelu"` are supported.47        layer_norm_eps (`float`, *optional*, defaults to 1e-6):48            The epsilon used by the layer normalization layers.49        dropout (`float`, *optional*, defaults to 0.0):50            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.51        drop_path_rate (`float`, *optional*, defaults to 0.0):52            Dropout rate for stochastic depth.53        attention_dropout (`float`, *optional*, defaults to 0.0):54            The dropout ratio for the attention probabilities.55        initializer_range (`float`, *optional*, defaults to 0.02):56            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.57        initializer_factor (`float`, *optional*, defaults to 0.1):58            A factor for layer scale.59    """60 61    model_type = 'intern_vit_6b'62 63    def __init__(64            self,65            num_channels=3,66            patch_size=14,67            image_size=224,68            qkv_bias=False,69            hidden_size=3200,70            num_attention_heads=25,71            intermediate_size=12800,72            qk_normalization=True,73            num_hidden_layers=48,74            use_flash_attn=True,75            hidden_act='gelu',76            norm_type='rms_norm',77            layer_norm_eps=1e-6,78            dropout=0.0,79            drop_path_rate=0.0,80            attention_dropout=0.0,81            initializer_range=0.02,82            initializer_factor=0.1,83            **kwargs,84    ):85        super().__init__(**kwargs)86 87        self.hidden_size = hidden_size88        self.intermediate_size = intermediate_size89        self.dropout = dropout90        self.drop_path_rate = drop_path_rate91        self.num_hidden_layers = num_hidden_layers92        self.num_attention_heads = num_attention_heads93        self.num_channels = num_channels94        self.patch_size = patch_size95        self.image_size = image_size96        self.initializer_range = initializer_range97        self.initializer_factor = initializer_factor98        self.attention_dropout = attention_dropout99        self.layer_norm_eps = layer_norm_eps100        self.hidden_act = hidden_act101        self.norm_type = norm_type102        self.qkv_bias = qkv_bias103        self.qk_normalization = qk_normalization104        self.use_flash_attn = use_flash_attn105 106    @classmethod107    def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> 'PretrainedConfig':108        config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)109 110        if 'vision_config' in config_dict:111            config_dict = config_dict['vision_config']112 113        if 'model_type' in config_dict and hasattr(cls, 'model_type') and config_dict['model_type'] != cls.model_type:114            logger.warning(115                f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "116                f'{cls.model_type}. This is not supported for all configurations of models and can yield errors.'117            )118 119        return cls.from_dict(config_dict, **kwargs)120