Upload model trained with Unsloth
Browse filesUpload model trained with Unsloth 2x faster
- README.md +1 -0
- config.json +78 -0
- configuration_paddleocr_vl.py +191 -0
- generation_config.json +12 -0
- model.safetensors +3 -0
- modeling_paddleocr_vl.py +0 -0
README.md
CHANGED
|
@@ -6,6 +6,7 @@ tags:
|
|
| 6 |
- unsloth
|
| 7 |
- paddleocr_vl
|
| 8 |
- trl
|
|
|
|
| 9 |
license: apache-2.0
|
| 10 |
language:
|
| 11 |
- en
|
|
|
|
| 6 |
- unsloth
|
| 7 |
- paddleocr_vl
|
| 8 |
- trl
|
| 9 |
+
- sft
|
| 10 |
license: apache-2.0
|
| 11 |
language:
|
| 12 |
- en
|
config.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"PaddleOCRVLForConditionalGeneration"
|
| 4 |
+
],
|
| 5 |
+
"attention_probs_dropout_prob": 0.0,
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "configuration_paddleocr_vl.PaddleOCRVLConfig",
|
| 8 |
+
"AutoModel": "modeling_paddleocr_vl.PaddleOCRVLForConditionalGeneration",
|
| 9 |
+
"AutoModelForCausalLM": "modeling_paddleocr_vl.PaddleOCRVLForConditionalGeneration"
|
| 10 |
+
},
|
| 11 |
+
"bos_token_id": 1,
|
| 12 |
+
"compression_ratio": 1.0,
|
| 13 |
+
"dtype": "float32",
|
| 14 |
+
"eos_token_id": 2,
|
| 15 |
+
"head_dim": 128,
|
| 16 |
+
"hidden_act": "silu",
|
| 17 |
+
"hidden_dropout_prob": 0.0,
|
| 18 |
+
"hidden_size": 1024,
|
| 19 |
+
"ignored_index": -100,
|
| 20 |
+
"image_token_id": 100295,
|
| 21 |
+
"intermediate_size": 3072,
|
| 22 |
+
"max_position_embeddings": 131072,
|
| 23 |
+
"max_sequence_length": null,
|
| 24 |
+
"model_type": "paddleocr_vl",
|
| 25 |
+
"num_attention_heads": 16,
|
| 26 |
+
"num_hidden_layers": 18,
|
| 27 |
+
"num_key_value_heads": 2,
|
| 28 |
+
"pad_token_id": 0,
|
| 29 |
+
"rms_norm_eps": 1e-05,
|
| 30 |
+
"rope_is_neox_style": true,
|
| 31 |
+
"rope_scaling": {
|
| 32 |
+
"mrope_section": [
|
| 33 |
+
16,
|
| 34 |
+
24,
|
| 35 |
+
24
|
| 36 |
+
],
|
| 37 |
+
"rope_type": "default",
|
| 38 |
+
"type": "default"
|
| 39 |
+
},
|
| 40 |
+
"rope_theta": 500000,
|
| 41 |
+
"sliding_window": null,
|
| 42 |
+
"tie_word_embeddings": false,
|
| 43 |
+
"transformers_version": "4.56.2",
|
| 44 |
+
"unsloth_version": "2025.12.8",
|
| 45 |
+
"use_3d_rope": true,
|
| 46 |
+
"use_bias": false,
|
| 47 |
+
"use_cache": false,
|
| 48 |
+
"use_flash_attention": false,
|
| 49 |
+
"video_token_id": 101307,
|
| 50 |
+
"vision_config": {
|
| 51 |
+
"architectures": [
|
| 52 |
+
"PaddleOCRVisionModel"
|
| 53 |
+
],
|
| 54 |
+
"attention_dropout": 0.0,
|
| 55 |
+
"auto_map": {
|
| 56 |
+
"AutoConfig": "configuration_paddleocr_vl.PaddleOCRVLConfig",
|
| 57 |
+
"AutoModel": "modeling_paddleocr_vl.PaddleOCRVisionModel"
|
| 58 |
+
},
|
| 59 |
+
"dtype": "float16",
|
| 60 |
+
"hidden_act": "gelu_pytorch_tanh",
|
| 61 |
+
"hidden_size": 1152,
|
| 62 |
+
"image_size": 384,
|
| 63 |
+
"intermediate_size": 4304,
|
| 64 |
+
"layer_norm_eps": 1e-06,
|
| 65 |
+
"model_type": "paddleocr_vl",
|
| 66 |
+
"num_attention_heads": 16,
|
| 67 |
+
"num_channels": 3,
|
| 68 |
+
"num_hidden_layers": 27,
|
| 69 |
+
"pad_token_id": 0,
|
| 70 |
+
"patch_size": 14,
|
| 71 |
+
"spatial_merge_size": 2,
|
| 72 |
+
"temporal_patch_size": 2,
|
| 73 |
+
"tokens_per_second": 2
|
| 74 |
+
},
|
| 75 |
+
"vision_start_token_id": 101305,
|
| 76 |
+
"vocab_size": 103424,
|
| 77 |
+
"weight_share_add_bias": true
|
| 78 |
+
}
|
configuration_paddleocr_vl.py
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 16 |
+
from transformers.modeling_rope_utils import rope_config_validation
|
| 17 |
+
|
| 18 |
+
class PaddleOCRVisionConfig(PretrainedConfig):
|
| 19 |
+
model_type = "paddleocr_vl"
|
| 20 |
+
base_config_key = "vision_config"
|
| 21 |
+
|
| 22 |
+
def __init__(
|
| 23 |
+
self,
|
| 24 |
+
hidden_size=768,
|
| 25 |
+
intermediate_size=3072,
|
| 26 |
+
num_hidden_layers=12,
|
| 27 |
+
num_attention_heads=12,
|
| 28 |
+
num_channels=3,
|
| 29 |
+
image_size=224,
|
| 30 |
+
patch_size=14,
|
| 31 |
+
hidden_act="gelu_pytorch_tanh",
|
| 32 |
+
layer_norm_eps=1e-6,
|
| 33 |
+
attention_dropout=0.0,
|
| 34 |
+
spatial_merge_size=2,
|
| 35 |
+
temporal_patch_size=2,
|
| 36 |
+
tokens_per_second=2,
|
| 37 |
+
**kwargs,
|
| 38 |
+
):
|
| 39 |
+
super().__init__(**kwargs)
|
| 40 |
+
|
| 41 |
+
self.hidden_size = hidden_size
|
| 42 |
+
self.intermediate_size = intermediate_size
|
| 43 |
+
self.num_hidden_layers = num_hidden_layers
|
| 44 |
+
self.num_attention_heads = num_attention_heads
|
| 45 |
+
self.num_channels = num_channels
|
| 46 |
+
self.patch_size = patch_size
|
| 47 |
+
self.image_size = image_size
|
| 48 |
+
self.attention_dropout = attention_dropout
|
| 49 |
+
self.layer_norm_eps = layer_norm_eps
|
| 50 |
+
self.hidden_act = hidden_act
|
| 51 |
+
self.spatial_merge_size = spatial_merge_size
|
| 52 |
+
self.temporal_patch_size = temporal_patch_size
|
| 53 |
+
self.tokens_per_second = tokens_per_second
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class PaddleOCRVLConfig(PretrainedConfig):
|
| 58 |
+
"""
|
| 59 |
+
Configuration class.
|
| 60 |
+
|
| 61 |
+
This class stores the configuration of an Ernie model, defining the model architecture.
|
| 62 |
+
It inherits from PretrainedConfig and can be used to control model outputs.
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
model_type = "paddleocr_vl"
|
| 66 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 67 |
+
sub_configs = {"vision_config": PaddleOCRVisionConfig}
|
| 68 |
+
|
| 69 |
+
# Default tensor parallel plan for base model `Qwen3`
|
| 70 |
+
base_model_tp_plan = {
|
| 71 |
+
"layers.*.self_attn.q_proj": "colwise",
|
| 72 |
+
"layers.*.self_attn.k_proj": "colwise",
|
| 73 |
+
"layers.*.self_attn.v_proj": "colwise",
|
| 74 |
+
"layers.*.self_attn.o_proj": "rowwise",
|
| 75 |
+
"layers.*.mlp.gate_proj": "colwise",
|
| 76 |
+
"layers.*.mlp.up_proj": "colwise",
|
| 77 |
+
"layers.*.mlp.down_proj": "rowwise",
|
| 78 |
+
}
|
| 79 |
+
base_model_pp_plan = {
|
| 80 |
+
"embed_tokens": (["input_ids"], ["inputs_embeds"]),
|
| 81 |
+
"layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
|
| 82 |
+
"norm": (["hidden_states"], ["hidden_states"]),
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
def __init__(
|
| 86 |
+
self,
|
| 87 |
+
vocab_size=32000,
|
| 88 |
+
hidden_size=768,
|
| 89 |
+
intermediate_size=11008,
|
| 90 |
+
max_position_embeddings=32768,
|
| 91 |
+
num_hidden_layers=2,
|
| 92 |
+
num_attention_heads=2,
|
| 93 |
+
image_token_id=101304,
|
| 94 |
+
video_token_id=101305,
|
| 95 |
+
vision_start_token_id=101306,
|
| 96 |
+
rms_norm_eps=1e-6,
|
| 97 |
+
use_cache=False,
|
| 98 |
+
use_flash_attention=False,
|
| 99 |
+
pad_token_id=0,
|
| 100 |
+
bos_token_id=1,
|
| 101 |
+
eos_token_id=2,
|
| 102 |
+
head_dim=128,
|
| 103 |
+
hidden_act="silu",
|
| 104 |
+
use_bias=False,
|
| 105 |
+
rope_theta=10000,
|
| 106 |
+
weight_share_add_bias=True,
|
| 107 |
+
ignored_index=-100,
|
| 108 |
+
attention_probs_dropout_prob=0.0,
|
| 109 |
+
hidden_dropout_prob=0.0,
|
| 110 |
+
compression_ratio: float = 1.0,
|
| 111 |
+
num_key_value_heads=None,
|
| 112 |
+
max_sequence_length=None,
|
| 113 |
+
tie_word_embeddings=False,
|
| 114 |
+
vision_config=None,
|
| 115 |
+
rope_scaling=None,
|
| 116 |
+
**kwargs,
|
| 117 |
+
):
|
| 118 |
+
"""
|
| 119 |
+
Initialize configuration with default or specified parameters.
|
| 120 |
+
|
| 121 |
+
Args:
|
| 122 |
+
vocab_size (int): Size of the vocabulary (number of unique tokens)
|
| 123 |
+
hidden_size (int): Dimensionality of the encoder layers and the pooler layer
|
| 124 |
+
intermediate_size (int): Dimensionality of the "intermediate" (feed-forward) layer
|
| 125 |
+
max_position_embeddings (int): Maximum sequence length the model can handle
|
| 126 |
+
num_hidden_layers (int): Number of hidden layers in the Transformer encoder
|
| 127 |
+
num_attention_heads (int): Number of attention heads for each attention layer
|
| 128 |
+
rms_norm_eps (float): The epsilon used by the RMS normalization layers
|
| 129 |
+
use_cache (bool): Whether to use caching for faster generation (decoding)
|
| 130 |
+
use_flash_attention (bool): Whether to use FlashAttention for optimized attention computation
|
| 131 |
+
pad_token_id (int): Token ID used for padding sequences
|
| 132 |
+
bos_token_id (int): Token ID used for beginning-of-sequence
|
| 133 |
+
eos_token_id (int): Token ID used for end-of-sequence
|
| 134 |
+
use_bias (bool): Whether to use bias terms in linear layers
|
| 135 |
+
rope_theta (float): The base period of the RoPE embeddings
|
| 136 |
+
weight_share_add_bias (bool): Whether to share bias weights in certain layers
|
| 137 |
+
ignored_index (int): Target value that is ignored during loss computation
|
| 138 |
+
attention_probs_dropout_prob (float): Dropout probability for attention weights
|
| 139 |
+
hidden_dropout_prob (float): Dropout probability for hidden layers
|
| 140 |
+
compression_ratio (float): Ratio for KV cache compression (1.0 = no compression)
|
| 141 |
+
num_key_value_heads (int): Number of key/value heads (for Grouped Query Attention)
|
| 142 |
+
max_sequence_length (int): Maximum sequence length for positional embeddings
|
| 143 |
+
**kwargs: Additional keyword arguments passed to parent class
|
| 144 |
+
"""
|
| 145 |
+
|
| 146 |
+
# Set default for tied embeddings if not specified.
|
| 147 |
+
super().__init__(
|
| 148 |
+
pad_token_id=pad_token_id,
|
| 149 |
+
bos_token_id=bos_token_id,
|
| 150 |
+
eos_token_id=eos_token_id,
|
| 151 |
+
**kwargs,
|
| 152 |
+
)
|
| 153 |
+
if isinstance(vision_config, dict):
|
| 154 |
+
self.vision_config = self.sub_configs["vision_config"](**vision_config)
|
| 155 |
+
elif vision_config is None:
|
| 156 |
+
self.vision_config = self.sub_configs["vision_config"]()
|
| 157 |
+
self.vocab_size = vocab_size
|
| 158 |
+
self.hidden_size = hidden_size
|
| 159 |
+
self.intermediate_size = intermediate_size
|
| 160 |
+
self.max_position_embeddings = max_position_embeddings
|
| 161 |
+
self.num_hidden_layers = num_hidden_layers
|
| 162 |
+
self.num_attention_heads = num_attention_heads
|
| 163 |
+
self.rms_norm_eps = rms_norm_eps
|
| 164 |
+
self.use_cache = use_cache
|
| 165 |
+
self.use_flash_attention = use_flash_attention
|
| 166 |
+
self.pad_token_id = pad_token_id
|
| 167 |
+
self.bos_token_id = bos_token_id
|
| 168 |
+
self.eos_token_id = eos_token_id
|
| 169 |
+
self.image_token_id = image_token_id
|
| 170 |
+
self.video_token_id = video_token_id
|
| 171 |
+
self.vision_start_token_id = vision_start_token_id
|
| 172 |
+
self.head_dim = head_dim
|
| 173 |
+
self.hidden_act=hidden_act
|
| 174 |
+
self.sliding_window = None
|
| 175 |
+
self.hidden_size = hidden_size
|
| 176 |
+
self.use_bias = use_bias
|
| 177 |
+
self.weight_share_add_bias = weight_share_add_bias
|
| 178 |
+
self.rope_theta = rope_theta
|
| 179 |
+
self.ignored_index = ignored_index
|
| 180 |
+
self.attention_probs_dropout_prob = attention_probs_dropout_prob
|
| 181 |
+
self.hidden_dropout_prob = hidden_dropout_prob
|
| 182 |
+
self.compression_ratio = compression_ratio
|
| 183 |
+
self.num_key_value_heads = num_key_value_heads
|
| 184 |
+
self.max_sequence_length = max_sequence_length
|
| 185 |
+
self.rope_scaling = rope_scaling
|
| 186 |
+
if self.rope_scaling is not None and "type" in self.rope_scaling:
|
| 187 |
+
if self.rope_scaling["type"] == "mrope":
|
| 188 |
+
self.rope_scaling["type"] = "default"
|
| 189 |
+
self.rope_scaling["rope_type"] = self.rope_scaling["type"]
|
| 190 |
+
rope_config_validation(self, ignore_keys={"mrope_section"})
|
| 191 |
+
super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs)
|
generation_config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"eos_token_id": [
|
| 5 |
+
2,
|
| 6 |
+
2
|
| 7 |
+
],
|
| 8 |
+
"max_length": 131072,
|
| 9 |
+
"pad_token_id": 0,
|
| 10 |
+
"transformers_version": "4.56.2",
|
| 11 |
+
"use_cache": false
|
| 12 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:305b9e13a0fdbd3201db363da4cabda0f0311d1533c45e8b7ea79bb6ae715d02
|
| 3 |
+
size 3826461296
|
modeling_paddleocr_vl.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|