jordan0811 commited on
Commit
921b0e2
·
verified ·
1 Parent(s): b71f8af

Delete files *.py with huggingface_hub

Browse files
configuration_minicpm.py DELETED
@@ -1,118 +0,0 @@
1
- # coding=utf-8
2
- # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
3
- #
4
- # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
5
- # and OPT implementations in this library. It has been modified from its
6
- # original forms to accommodate minor architectural differences compared
7
- # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
8
- #
9
- # Licensed under the Apache License, Version 2.0 (the "License");
10
- # you may not use this file except in compliance with the License.
11
- # You may obtain a copy of the License at
12
- #
13
- # http://www.apache.org/licenses/LICENSE-2.0
14
- #
15
- # Unless required by applicable law or agreed to in writing, software
16
- # distributed under the License is distributed on an "AS IS" BASIS,
17
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- """ MiniCPM model configuration"""
21
-
22
- import os
23
- from typing import Union
24
-
25
- from transformers.configuration_utils import PretrainedConfig
26
- from transformers.utils import logging
27
- from .modeling_navit_siglip import SiglipVisionConfig
28
-
29
- from transformers import LlamaConfig
30
-
31
- logger = logging.get_logger(__name__)
32
-
33
-
34
- class MiniCPMVSliceConfig(PretrainedConfig):
35
- model_type = "minicpmv"
36
-
37
- def __init__(
38
- self,
39
- patch_size=14,
40
- max_slice_nums=9,
41
- scale_resolution=448,
42
- **kwargs,
43
- ):
44
- super().__init__(**kwargs)
45
- self.patch_size = patch_size
46
- self.max_slice_nums = max_slice_nums
47
- self.scale_resolution = scale_resolution
48
-
49
- @classmethod
50
- def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> "PretrainedConfig":
51
- cls._set_token_in_kwargs(kwargs)
52
-
53
- config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
54
-
55
- if config_dict.get("model_type") == "minicpmv":
56
- config_dict = config_dict["slice_config"]
57
-
58
- if "model_type" in config_dict and hasattr(cls, "model_type") and config_dict["model_type"] != cls.model_type:
59
- logger.warning(
60
- f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
61
- f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."
62
- )
63
-
64
- return cls.from_dict(config_dict, **kwargs)
65
-
66
- class MiniCPMVConfig(LlamaConfig):
67
- model_type = "minicpmv"
68
- keys_to_ignore_at_inference = ["past_key_values"]
69
-
70
- default_vision_config = {
71
- "hidden_size": 1152,
72
- "image_size": 980,
73
- "intermediate_size": 4304,
74
- "model_type": "siglip",
75
- "num_attention_heads": 16,
76
- "num_hidden_layers": 27,
77
- "patch_size": 14,
78
- }
79
-
80
- def __init__(
81
- self,
82
- use_cache=True,
83
- query_num=64,
84
- image_size=448,
85
- drop_vision_last_layer=True,
86
- batch_vision_input=True,
87
- slice_config=None,
88
- vision_config=None,
89
- use_image_id=True,
90
- vision_batch_size=16,
91
- **kwargs,
92
- ):
93
- self.use_cache = use_cache
94
- self.query_num = query_num
95
- self.image_size = image_size
96
- self.drop_vision_last_layer = drop_vision_last_layer
97
- self.batch_vision_input = batch_vision_input
98
- self.use_image_id = use_image_id
99
- self.vision_batch_size = vision_batch_size
100
-
101
- if slice_config is None:
102
- self.slice_config = MiniCPMVSliceConfig(max_slice_nums=1)
103
- else:
104
- self.slice_config = MiniCPMVSliceConfig(**slice_config)
105
- self.slice_mode = True
106
-
107
- # same as HuggingFaceM4/siglip-so400m-14-980-flash-attn2-navit add tgt_sizes
108
- if vision_config is None:
109
- self.vision_config = SiglipVisionConfig(**self.default_vision_config)
110
- logger.info("vision_config is None, using default vision config")
111
- elif isinstance(vision_config, dict):
112
- self.vision_config = SiglipVisionConfig(**vision_config)
113
- elif isinstance(vision_config, SiglipVisionConfig):
114
- self.vision_config = vision_config
115
-
116
- self.patch_size = self.vision_config.patch_size
117
-
118
- super().__init__(**kwargs)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tokenization_minicpmv_fast.py DELETED
@@ -1,66 +0,0 @@
1
- from transformers import LlamaTokenizerFast
2
-
3
-
4
- class MiniCPMVTokenizerFast(LlamaTokenizerFast):
5
- def __init__(self, **kwargs):
6
- super().__init__(**kwargs)
7
- self.im_start = "<image>"
8
- self.im_end = "</image>"
9
- self.ref_start = "<ref>"
10
- self.ref_end = "</ref>"
11
- self.box_start = "<box>"
12
- self.box_end = "</box>"
13
- self.quad_start = "<quad>"
14
- self.quad_end = "</quad>"
15
- self.slice_start = "<slice>"
16
- self.slice_end = "</slice>"
17
- self.im_id_start = "<image_id>"
18
- self.im_id_end = "</image_id>"
19
-
20
- @property
21
- def eos_id(self):
22
- return self.eos_token_id
23
-
24
- @property
25
- def bos_id(self):
26
- return self.bos_token_id
27
-
28
- @property
29
- def unk_id(self):
30
- return self.unk_token_id
31
-
32
- @property
33
- def im_start_id(self):
34
- return self.convert_tokens_to_ids(self.im_start)
35
-
36
- @property
37
- def im_end_id(self):
38
- return self.convert_tokens_to_ids(self.im_end)
39
-
40
- @property
41
- def slice_start_id(self):
42
- return self.convert_tokens_to_ids(self.slice_start)
43
-
44
- @property
45
- def slice_end_id(self):
46
- return self.convert_tokens_to_ids(self.slice_end)
47
-
48
- @property
49
- def im_id_start_id(self):
50
- return self.convert_tokens_to_ids(self.im_id_start)
51
-
52
- @property
53
- def im_id_end_id(self):
54
- return self.convert_tokens_to_ids(self.im_id_end)
55
-
56
- @property
57
- def newline_id(self):
58
- return self.convert_tokens_to_ids('\n')
59
-
60
- @staticmethod
61
- def escape(text: str) -> str:
62
- return text
63
-
64
- @staticmethod
65
- def unescape(text: str) -> str:
66
- return text