Aluode/PerceptionLabPortable
0
1# ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ2# This file was automatically generated from src/transformers/models/got_ocr2/modular_got_ocr2.py.3# Do NOT edit this file manually as any edits will be overwritten by the generation of4# the file from the modular. If any change should be done, please apply the change to the5# modular_got_ocr2.py file directly. One of our CI enforces this.6# ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ๐จ7# coding=utf-88# Copyright 2024 HuggingFace Inc. team. All rights reserved.9#10# Licensed under the Apache License, Version 2.0 (the "License");11# you may not use this file except in compliance with the License.12# You may obtain a copy of the License at13#14# http://www.apache.org/licenses/LICENSE-2.015#16# Unless required by applicable law or agreed to in writing, software17# distributed under the License is distributed on an "AS IS" BASIS,18# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.19# See the License for the specific language governing permissions and20# limitations under the License.21 22 23from ...configuration_utils import PretrainedConfig24from ..auto import CONFIG_MAPPING, AutoConfig25 26 27class GotOcr2VisionConfig(PretrainedConfig):28 r"""29 This is the configuration class to store the configuration of a [`GotOcr2VisionModel`]. It is used to instantiate a GOT_OCR230 vision encoder according to the specified arguments, defining the model architecture. Instantiating a configuration31 defaults will yield a similar configuration to that of the SAM ViT-h32 [facebook/sam-vit-huge](https://huggingface.co/facebook/sam-vit-huge) architecture.33 34 Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the35 documentation from [`PretrainedConfig`] for more information.36 37 Args:38 hidden_size (`int`, *optional*, defaults to 768):39 Dimensionality of the encoder layers and the pooler layer.40 output_channels (`int`, *optional*, defaults to 256):41 Dimensionality of the output channels in the Patch Encoder.42 num_hidden_layers (`int`, *optional*, defaults to 12):43 Number of hidden layers in the Transformer encoder.44 num_attention_heads (`int`, *optional*, defaults to 12):45 Number of attention heads for each attention layer in the Transformer encoder.46 num_channels (`int`, *optional*, defaults to 3):47 Number of channels in the input image.48 image_size (`int`, *optional*, defaults to 1024):49 Expected resolution. Target size of the resized input image.50 patch_size (`int`, *optional*, defaults to 16):51 Size of the patches to be extracted from the input image.52 hidden_act (`str`, *optional*, defaults to `"gelu"`):53 The non-linear activation function (function or string)54 layer_norm_eps (`float`, *optional*, defaults to 1e-06):55 The epsilon used by the layer normalization layers.56 attention_dropout (`float`, *optional*, defaults to 0.0):57 The dropout ratio for the attention probabilities.58 initializer_range (`float`, *optional*, defaults to 1e-10):59 The standard deviation of the truncated_normal_initializer for initializing all weight matrices.60 qkv_bias (`bool`, *optional*, defaults to `True`):61 Whether to add a bias to query, key, value projections.62 use_abs_pos (`bool`, *optional*, defaults to `True`):63 Whether to use absolute position embedding.64 use_rel_pos (`bool`, *optional*, defaults to `True`):65 Whether to use relative position embedding.66 window_size (`int`, *optional*, defaults to 14):67 Window size for relative position.68 global_attn_indexes (`list[int]`, *optional*, defaults to `[2, 5, 8, 11]`):69 The indexes of the global attention layers.70 mlp_dim (`int`, *optional*, defaults to 3072):71 The dimensionality of the MLP layer in the Transformer encoder.72 """73 74 base_config_key = "vision_config"75 76 def __init__(77 self,78 hidden_size=768,79 output_channels=256,80 num_hidden_layers=12,81 num_attention_heads=12,82 num_channels=3,83 image_size=1024,84 patch_size=16,85 hidden_act="gelu",86 layer_norm_eps=1e-06,87 attention_dropout=0.0,88 initializer_range=1e-10,89 qkv_bias=True,90 use_abs_pos=True,91 use_rel_pos=True,92 window_size=14,93 global_attn_indexes=[2, 5, 8, 11],94 mlp_dim=3072,95 **kwargs,96 ):97 super().__init__(**kwargs)98 99 self.hidden_size = hidden_size100 self.output_channels = output_channels101 self.num_hidden_layers = num_hidden_layers102 self.num_attention_heads = num_attention_heads103 self.num_channels = num_channels104 self.image_size = image_size105 self.patch_size = patch_size106 self.hidden_act = hidden_act107 self.layer_norm_eps = layer_norm_eps108 self.attention_dropout = attention_dropout109 self.initializer_range = initializer_range110 self.qkv_bias = qkv_bias111 self.use_abs_pos = use_abs_pos112 self.use_rel_pos = use_rel_pos113 self.window_size = window_size114 self.global_attn_indexes = global_attn_indexes115 self.mlp_dim = mlp_dim116 117 118class GotOcr2Config(PretrainedConfig):119 r"""120 This is the configuration class to store the configuration of a [`GotOcr2ForConditionalGeneration`]. It is used to instantiate a121 GotOcr2 model according to the specified arguments, defining the model architecture. Instantiating a configuration122 with the defaults will yield a similar configuration to that of GOT-OCR-2.0.123 124 e.g [stepfun-ai/GOT-OCR-2.0-hf](https://huggingface.co/stepfun-ai/GOT-OCR-2.0-hf)125 126 Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the127 documentation from [`PretrainedConfig`] for more information.128 129 130 Args:131 vision_config (`Union[AutoConfig, dict]`, *optional*, defaults to `CLIPVisionConfig`):132 The config object or dictionary of the vision backbone.133 text_config (`Union[AutoConfig, dict]`, *optional*, defaults to `LlamaConfig`):134 The config object or dictionary of the text backbone.135 image_token_index (`int`, *optional*, defaults to 151859):136 The image token index to encode the image prompt.137 image_seq_length (`int`, *optional*, defaults to 576):138 Sequence length of one image embedding.139 pad_token_id (`int`, *optional*, defaults to -1):140 Padding token id.141 142 ```python143 >>> from transformers import GotOcr2ForConditionalGeneration, GotOcr2Config144 145 >>> # Initializing a GotOcr2 style configuration146 >>> configuration = GotOcr2Config()147 148 >>> # Initializing a model from the Qwen2-VL-7B style configuration149 >>> model = GotOcr2ForConditionalGeneration(configuration)150 151 >>> # Accessing the model configuration152 >>> configuration = model.config153 ```"""154 155 model_type = "got_ocr2"156 attribute_map = {157 "image_token_id": "image_token_index",158 }159 sub_configs = {"text_config": AutoConfig, "vision_config": GotOcr2VisionConfig}160 161 def __init__(162 self,163 vision_config=None,164 text_config=None,165 image_token_index=151859,166 image_seq_length=576,167 pad_token_id=-1,168 **kwargs,169 ):170 self.image_token_index = image_token_index171 self.image_seq_length = image_seq_length172 self.pad_token_id = pad_token_id173 174 if vision_config is None:175 self.vision_config = GotOcr2VisionConfig()176 elif isinstance(vision_config, dict):177 self.vision_config = GotOcr2VisionConfig(**vision_config)178 elif isinstance(vision_config, GotOcr2VisionConfig):179 self.vision_config = vision_config180 181 if isinstance(text_config, dict):182 text_config["model_type"] = text_config.get("model_type", "qwen2")183 text_config = CONFIG_MAPPING[text_config["model_type"]](**text_config)184 elif text_config is None:185 text_config = CONFIG_MAPPING["qwen2"](186 vocab_size=151860,187 hidden_size=1024,188 intermediate_size=2816,189 num_hidden_layers=24,190 num_attention_heads=16,191 num_key_value_heads=16,192 hidden_act="silu",193 max_position_embeddings=32768,194 initializer_range=0.02,195 rms_norm_eps=1e-6,196 use_cache=True,197 tie_word_embeddings=True,198 rope_theta=1000000.0,199 rope_scaling=None,200 use_sliding_window=False,201 sliding_window=4096,202 max_window_layers=21,203 attention_dropout=0.0,204 )205 206 self.text_config = text_config207 208 super().__init__(**kwargs)209 210 211__all__ = ["GotOcr2VisionConfig", "GotOcr2Config"]212 