# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # This file was automatically generated from src/transformers/models/paddleocr_vl/modular_paddleocr_vl.py. # Do NOT edit this file manually as any edits will be overwritten by the generation of # the file from the modular. If any change should be done, please apply the change to the # modular_paddleocr_vl.py file directly. One of our CI enforces this. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # Copyright 2025 The PaddlePaddle Team and The HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from its # original forms to accommodate minor architectural differences compared # to GPT-NeoX and OPT used by the Meta AI team that trained the model. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import inspect from huggingface_hub.dataclasses import strict from ...configuration_utils import PreTrainedConfig from ...modeling_rope_utils import RopeParameters from ...utils import auto_docstring @auto_docstring(checkpoint="PaddlePaddle/PaddleOCR-VL") @strict class PaddleOCRVisionConfig(PreTrainedConfig): r""" Example: ```python >>> from transformers import PaddleOCRVisionConfig, PaddleOCRVisionModel >>> # Initializing a PaddleOCRVisionConfig with PaddlePaddle/PaddleOCR-VL style configuration >>> configuration = PaddleOCRVisionConfig() >>> # Initializing a PaddleOCRVisionModel (with random weights) from the PaddlePaddle/PaddleOCR-VL style configuration >>> model = PaddleOCRVisionModel(configuration) >>> # Accessing the model configuration >>> configuration = model.config ``` """ model_type = "paddleocr_vl_vision" base_config_key = "vision_config" hidden_size: int = 1152 intermediate_size: int = 4304 num_hidden_layers: int = 27 num_attention_heads: int = 16 num_channels: int = 3 image_size: int = 384 patch_size: int = 14 hidden_act: str = "gelu_pytorch_tanh" layer_norm_eps: float = 1e-6 attention_dropout: float | int = 0.0 spatial_merge_size: int = 2 @auto_docstring(checkpoint="PaddlePaddle/PaddleOCR-VL") @strict class PaddleOCRTextConfig(PreTrainedConfig): r""" use_bias (`bool`, *optional*, defaults to `False`): Whether to use a bias in any of the projections including mlp and attention for example. Example: ```python >>> from transformers import PaddleOCRTextModel, PaddleOCRTextConfig >>> # Initializing a PaddleOCRText 0.3B style configuration >>> configuration = PaddleOCRTextConfig() >>> # Initializing a model from the 0.3B style configuration >>> model = PaddleOCRTextModel(configuration) >>> # Accessing the model configuration >>> configuration = model.config ```""" model_type = "paddleocr_vl_text" keys_to_ignore_at_inference = ["past_key_values"] default_theta = 500000.0 # Default tensor parallel plan for base model `PaddleOCRTextModel` base_model_tp_plan = { "layers.*.self_attn.q_proj": "colwise", "layers.*.self_attn.k_proj": "colwise", "layers.*.self_attn.v_proj": "colwise", "layers.*.self_attn.o_proj": "rowwise", "layers.*.mlp.gate_proj": "colwise", "layers.*.mlp.up_proj": "colwise", "layers.*.mlp.down_proj": "rowwise", } base_model_pp_plan = { "embed_tokens": (["input_ids"], ["inputs_embeds"]), "layers": (["hidden_states", "attention_mask"], ["hidden_states"]), "norm": (["hidden_states"], ["hidden_states"]), } vocab_size: int = 103424 hidden_size: int = 1024 intermediate_size: int = 3072 num_hidden_layers: int = 18 num_attention_heads: int = 16 num_key_value_heads: int | None = 2 hidden_act: str = "silu" max_position_embeddings: int = 131072 initializer_range: float = 0.02 rms_norm_eps: float = 1e-05 use_cache: bool | None = True pad_token_id: int | None = 0 bos_token_id: int | None = 1 eos_token_id: int | list[int] | None = 2 tie_word_embeddings: bool = True rope_parameters: RopeParameters | dict | None = None use_bias: bool | None = False head_dim: int | None = 128 def __post_init__(self, **kwargs): if self.num_key_value_heads is None: self.num_key_value_heads = self.num_attention_heads self.head_dim = self.head_dim if self.head_dim is not None else self.hidden_size // self.num_attention_heads super().__post_init__(**kwargs) @auto_docstring(checkpoint="PaddlePaddle/PaddleOCR-VL") @strict class PaddleOCRVLConfig(PreTrainedConfig): r""" Example: ```python >>> from transformers import PaddleOCRVLForConditionalGeneration, PaddleOCRVLConfig >>> # Initializing a PaddleOCRVL style configuration >>> configuration = PaddleOCRVLConfig() >>> # Initializing a model from the PaddleOCRVL style configuration >>> model = PaddleOCRVLForConditionalGeneration(configuration) >>> # Accessing the model configuration >>> configuration = model.config ```""" model_type = "paddleocr_vl" sub_configs = {"vision_config": PaddleOCRVisionConfig, "text_config": PaddleOCRTextConfig} keys_to_ignore_at_inference = ["past_key_values"] text_config: dict | PreTrainedConfig | None = None vision_config: dict | PreTrainedConfig | None = None image_token_id: int = 100295 video_token_id: int = 100296 vision_start_token_id: int = 101305 vision_end_token_id: int = 101306 tie_word_embeddings: bool = True def __post_init__(self, **kwargs): if isinstance(self.vision_config, dict): self.vision_config = self.sub_configs["vision_config"](**self.vision_config) elif self.vision_config is None: self.vision_config = self.sub_configs["vision_config"]() # Hub configs are saved as flat dicts so we pop some of kwargs to init `TextConfig` text_params = inspect.signature(self.sub_configs["text_config"].__init__).parameters.keys() text_params = list(text_params) + ["rope_parameters", "rope_scaling", "rope_theta"] text_kwargs = {key: kwargs.pop(key) for key in text_params if key in kwargs} if isinstance(self.text_config, dict): self.text_config = self.sub_configs["text_config"](**self.text_config) elif self.text_config is None: # Hub configs are saved as flat dicts so we pop some of kwargs to init `TextConfig` text_kwargs["dtype"] = kwargs.get("torch_dtype", kwargs.get("dtype")) # don't pop the dtype self.text_config = self.sub_configs["text_config"](**text_kwargs) # BC: pre-v5 saves placed `tie_word_embeddings` inside text_config. Forward it to the outer # config (where v5's tying logic looks) when the root value is the default. Checked after # text_config init so it also covers a text config passed as an already-initialized instance. if not self.tie_word_embeddings and getattr(self.text_config, "tie_word_embeddings", False): self.tie_word_embeddings = True super().__post_init__(**kwargs) __all__ = ["PaddleOCRVLConfig", "PaddleOCRVisionConfig", "PaddleOCRTextConfig"]