bsyx001 commited on
Commit
02a3b66
1 Parent(s): 7c5b18b

Upload model

Browse files
README.md ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags: []
4
+ ---
5
+
6
+ # Model Card for Model ID
7
+
8
+ <!-- Provide a quick summary of what the model is/does. -->
9
+
10
+
11
+
12
+ ## Model Details
13
+
14
+ ### Model Description
15
+
16
+ <!-- Provide a longer summary of what this model is. -->
17
+
18
+ This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
+
20
+ - **Developed by:** [More Information Needed]
21
+ - **Funded by [optional]:** [More Information Needed]
22
+ - **Shared by [optional]:** [More Information Needed]
23
+ - **Model type:** [More Information Needed]
24
+ - **Language(s) (NLP):** [More Information Needed]
25
+ - **License:** [More Information Needed]
26
+ - **Finetuned from model [optional]:** [More Information Needed]
27
+
28
+ ### Model Sources [optional]
29
+
30
+ <!-- Provide the basic links for the model. -->
31
+
32
+ - **Repository:** [More Information Needed]
33
+ - **Paper [optional]:** [More Information Needed]
34
+ - **Demo [optional]:** [More Information Needed]
35
+
36
+ ## Uses
37
+
38
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
+
40
+ ### Direct Use
41
+
42
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
+
44
+ [More Information Needed]
45
+
46
+ ### Downstream Use [optional]
47
+
48
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
+
50
+ [More Information Needed]
51
+
52
+ ### Out-of-Scope Use
53
+
54
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
+
56
+ [More Information Needed]
57
+
58
+ ## Bias, Risks, and Limitations
59
+
60
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
+
62
+ [More Information Needed]
63
+
64
+ ### Recommendations
65
+
66
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
+
68
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
+
70
+ ## How to Get Started with the Model
71
+
72
+ Use the code below to get started with the model.
73
+
74
+ [More Information Needed]
75
+
76
+ ## Training Details
77
+
78
+ ### Training Data
79
+
80
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
+
82
+ [More Information Needed]
83
+
84
+ ### Training Procedure
85
+
86
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
+
88
+ #### Preprocessing [optional]
89
+
90
+ [More Information Needed]
91
+
92
+
93
+ #### Training Hyperparameters
94
+
95
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
+
97
+ #### Speeds, Sizes, Times [optional]
98
+
99
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
+
101
+ [More Information Needed]
102
+
103
+ ## Evaluation
104
+
105
+ <!-- This section describes the evaluation protocols and provides the results. -->
106
+
107
+ ### Testing Data, Factors & Metrics
108
+
109
+ #### Testing Data
110
+
111
+ <!-- This should link to a Dataset Card if possible. -->
112
+
113
+ [More Information Needed]
114
+
115
+ #### Factors
116
+
117
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
+
119
+ [More Information Needed]
120
+
121
+ #### Metrics
122
+
123
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
+
125
+ [More Information Needed]
126
+
127
+ ### Results
128
+
129
+ [More Information Needed]
130
+
131
+ #### Summary
132
+
133
+
134
+
135
+ ## Model Examination [optional]
136
+
137
+ <!-- Relevant interpretability work for the model goes here -->
138
+
139
+ [More Information Needed]
140
+
141
+ ## Environmental Impact
142
+
143
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
+
145
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
+
147
+ - **Hardware Type:** [More Information Needed]
148
+ - **Hours used:** [More Information Needed]
149
+ - **Cloud Provider:** [More Information Needed]
150
+ - **Compute Region:** [More Information Needed]
151
+ - **Carbon Emitted:** [More Information Needed]
152
+
153
+ ## Technical Specifications [optional]
154
+
155
+ ### Model Architecture and Objective
156
+
157
+ [More Information Needed]
158
+
159
+ ### Compute Infrastructure
160
+
161
+ [More Information Needed]
162
+
163
+ #### Hardware
164
+
165
+ [More Information Needed]
166
+
167
+ #### Software
168
+
169
+ [More Information Needed]
170
+
171
+ ## Citation [optional]
172
+
173
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
+
175
+ **BibTeX:**
176
+
177
+ [More Information Needed]
178
+
179
+ **APA:**
180
+
181
+ [More Information Needed]
182
+
183
+ ## Glossary [optional]
184
+
185
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
+
187
+ [More Information Needed]
188
+
189
+ ## More Information [optional]
190
+
191
+ [More Information Needed]
192
+
193
+ ## Model Card Authors [optional]
194
+
195
+ [More Information Needed]
196
+
197
+ ## Model Card Contact
198
+
199
+ [More Information Needed]
config.json ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "CustomCLIPModel"
4
+ ],
5
+ "auto_map": {
6
+ "AutoConfig": "configuration_custom_clip.CustomCLIPConfig",
7
+ "AutoModel": "modeling_custom_clip.CustomCLIPModel"
8
+ },
9
+ "initializer_factor": 1.0,
10
+ "logit_scale_init_value": 2.659260036932778,
11
+ "model_type": "custom-clip-model",
12
+ "projection_dim": 1024,
13
+ "text_config": {
14
+ "_name_or_path": "",
15
+ "add_cross_attention": false,
16
+ "architectures": null,
17
+ "attention_probs_dropout_prob": 0.1,
18
+ "bad_words_ids": null,
19
+ "begin_suppress_tokens": null,
20
+ "bos_token_id": 1,
21
+ "chunk_size_feed_forward": 0,
22
+ "classifier_dropout": null,
23
+ "cross_attention_hidden_size": null,
24
+ "decoder_start_token_id": null,
25
+ "diversity_penalty": 0.0,
26
+ "do_sample": false,
27
+ "early_stopping": false,
28
+ "encoder_no_repeat_ngram_size": 0,
29
+ "eos_token_id": 2,
30
+ "exponential_decay_length_penalty": null,
31
+ "finetuning_task": null,
32
+ "forced_bos_token_id": null,
33
+ "forced_eos_token_id": null,
34
+ "hidden_act": "gelu",
35
+ "hidden_dropout_prob": 0.1,
36
+ "hidden_size": 768,
37
+ "id2label": {
38
+ "0": "LABEL_0",
39
+ "1": "LABEL_1"
40
+ },
41
+ "initializer_range": 0.02,
42
+ "intermediate_size": 3072,
43
+ "is_decoder": false,
44
+ "is_encoder_decoder": false,
45
+ "label2id": {
46
+ "LABEL_0": 0,
47
+ "LABEL_1": 1
48
+ },
49
+ "layer_norm_eps": 1e-12,
50
+ "length_penalty": 1.0,
51
+ "max_length": 20,
52
+ "max_position_embeddings": 512,
53
+ "min_length": 0,
54
+ "model_type": "bert",
55
+ "no_repeat_ngram_size": 0,
56
+ "num_attention_heads": 12,
57
+ "num_beam_groups": 1,
58
+ "num_beams": 1,
59
+ "num_hidden_layers": 24,
60
+ "num_return_sequences": 1,
61
+ "output_attentions": false,
62
+ "output_hidden_states": false,
63
+ "output_scores": false,
64
+ "pad_token_id": 3,
65
+ "position_embedding_type": "absolute",
66
+ "prefix": null,
67
+ "problem_type": null,
68
+ "pruned_heads": {},
69
+ "remove_invalid_values": false,
70
+ "repetition_penalty": 1.0,
71
+ "return_dict": true,
72
+ "return_dict_in_generate": false,
73
+ "sep_token_id": null,
74
+ "suppress_tokens": null,
75
+ "task_specific_params": null,
76
+ "temperature": 1.0,
77
+ "tf_legacy_loss": false,
78
+ "tie_encoder_decoder": false,
79
+ "tie_word_embeddings": true,
80
+ "tokenizer_class": null,
81
+ "top_k": 50,
82
+ "top_p": 1.0,
83
+ "torch_dtype": null,
84
+ "torchscript": false,
85
+ "type_vocab_size": 2,
86
+ "typical_p": 1.0,
87
+ "use_bfloat16": false,
88
+ "use_cache": true,
89
+ "vocab_size": 32000
90
+ },
91
+ "text_model_pooler": "CustomCLIPPooler",
92
+ "text_model_pooler_kwargs": {},
93
+ "torch_dtype": "float32",
94
+ "transformers_version": "4.38.2",
95
+ "vision_config": {
96
+ "_name_or_path": "",
97
+ "add_cross_attention": false,
98
+ "architectures": null,
99
+ "attention_dropout": 0.0,
100
+ "bad_words_ids": null,
101
+ "begin_suppress_tokens": null,
102
+ "bos_token_id": null,
103
+ "chunk_size_feed_forward": 0,
104
+ "cross_attention_hidden_size": null,
105
+ "decoder_start_token_id": null,
106
+ "diversity_penalty": 0.0,
107
+ "do_sample": false,
108
+ "dropout": 0.0,
109
+ "early_stopping": false,
110
+ "encoder_no_repeat_ngram_size": 0,
111
+ "eos_token_id": null,
112
+ "exponential_decay_length_penalty": null,
113
+ "finetuning_task": null,
114
+ "forced_bos_token_id": null,
115
+ "forced_eos_token_id": null,
116
+ "hidden_act": "gelu",
117
+ "hidden_size": 1280,
118
+ "id2label": {
119
+ "0": "LABEL_0",
120
+ "1": "LABEL_1"
121
+ },
122
+ "image_size": 224,
123
+ "initializer_factor": 1.0,
124
+ "initializer_range": 0.02,
125
+ "intermediate_size": 5120,
126
+ "is_decoder": false,
127
+ "is_encoder_decoder": false,
128
+ "label2id": {
129
+ "LABEL_0": 0,
130
+ "LABEL_1": 1
131
+ },
132
+ "layer_norm_eps": 1e-05,
133
+ "length_penalty": 1.0,
134
+ "max_length": 20,
135
+ "min_length": 0,
136
+ "model_type": "clip_vision_model",
137
+ "no_repeat_ngram_size": 0,
138
+ "num_attention_heads": 16,
139
+ "num_beam_groups": 1,
140
+ "num_beams": 1,
141
+ "num_channels": 3,
142
+ "num_hidden_layers": 32,
143
+ "num_return_sequences": 1,
144
+ "output_attentions": false,
145
+ "output_hidden_states": false,
146
+ "output_scores": false,
147
+ "pad_token_id": null,
148
+ "patch_size": 14,
149
+ "prefix": null,
150
+ "problem_type": null,
151
+ "projection_dim": 1024,
152
+ "pruned_heads": {},
153
+ "remove_invalid_values": false,
154
+ "repetition_penalty": 1.0,
155
+ "return_dict": true,
156
+ "return_dict_in_generate": false,
157
+ "sep_token_id": null,
158
+ "suppress_tokens": null,
159
+ "task_specific_params": null,
160
+ "temperature": 1.0,
161
+ "tf_legacy_loss": false,
162
+ "tie_encoder_decoder": false,
163
+ "tie_word_embeddings": true,
164
+ "tokenizer_class": null,
165
+ "top_k": 50,
166
+ "top_p": 1.0,
167
+ "torch_dtype": null,
168
+ "torchscript": false,
169
+ "typical_p": 1.0,
170
+ "use_bfloat16": false
171
+ },
172
+ "vision_config_dict": {
173
+ "hidden_act": "gelu",
174
+ "hidden_size": 1280,
175
+ "intermediate_size": 5120,
176
+ "num_attention_heads": 16,
177
+ "num_hidden_layers": 32,
178
+ "patch_size": 14,
179
+ "projection_dim": 1024
180
+ }
181
+ }
configuration_custom_clip.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from copy import deepcopy
2
+ from typing import Optional
3
+
4
+ import torch
5
+ from transformers import AutoConfig, VisionTextDualEncoderConfig
6
+ from transformers.utils import logging
7
+
8
+ logger = logging.get_logger(__name__)
9
+
10
+
11
+ class CustomCLIPPooler(torch.nn.Module):
12
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
13
+ first_token_tensor = hidden_states[:, 0, :]
14
+ return first_token_tensor
15
+
16
+
17
+ def get_text_model_pooler(text_model_pooler: str) -> torch.nn.Module:
18
+ if text_model_pooler == "CustomCLIPPooler":
19
+ return CustomCLIPPooler
20
+ else:
21
+ raise ValueError(f"Unrecognized text model pooler type {text_model_pooler!r}.")
22
+
23
+
24
+ def is_valid_text_model_pooler(
25
+ text_model_pooler: str, suppress_error: bool = False
26
+ ) -> bool:
27
+ try:
28
+ get_text_model_pooler(text_model_pooler)
29
+ except ValueError:
30
+ if not suppress_error:
31
+ raise
32
+ return False
33
+ else:
34
+ return True
35
+
36
+
37
+ class CustomCLIPConfig(VisionTextDualEncoderConfig):
38
+ model_type = "custom-clip-model"
39
+
40
+ DEFAULT_TEXT_MODEL_POOLER_STR: str = "CustomCLIPPooler"
41
+ DEFAULT_TEXT_MODEL_POOLER_KWARGS: dict = {}
42
+
43
+ def __init__(
44
+ self,
45
+ *args,
46
+ text_model_pooler: Optional[str] = None,
47
+ text_model_pooler_kwargs: Optional[dict] = None,
48
+ **kwargs,
49
+ ):
50
+ super().__init__(*args, **kwargs)
51
+
52
+ self.text_model_pooler = (
53
+ self.DEFAULT_TEXT_MODEL_POOLER_STR
54
+ if text_model_pooler is None
55
+ else text_model_pooler
56
+ )
57
+ is_valid_text_model_pooler(self.text_model_pooler, suppress_error=False)
58
+
59
+ self.text_model_pooler_kwargs = (
60
+ self.DEFAULT_TEXT_MODEL_POOLER_KWARGS
61
+ if text_model_pooler_kwargs is None
62
+ else text_model_pooler_kwargs
63
+ )
64
+
65
+ @classmethod
66
+ def from_base(cls, obj: VisionTextDualEncoderConfig):
67
+ if not isinstance(obj, cls):
68
+ base = VisionTextDualEncoderConfig
69
+ if not isinstance(obj, base):
70
+ raise TypeError(f"obj must be of type {cls!r} or {base!r}.")
71
+ obj = deepcopy(obj)
72
+ logger.warning(f"Changing config class from {obj.__class__!r} to {cls!r}.")
73
+ obj.__class__ = cls
74
+
75
+ def setattr_with_warning(object, name, value):
76
+ logger.warning(f"Setting {name!r} to {value!r}.")
77
+ setattr(object, name, value)
78
+
79
+ setattr_with_warning(
80
+ obj, "text_model_pooler", cls.DEFAULT_TEXT_MODEL_POOLER_STR
81
+ )
82
+ setattr_with_warning(
83
+ obj, "text_model_pooler_kwargs", cls.DEFAULT_TEXT_MODEL_POOLER_KWARGS
84
+ )
85
+ return obj
86
+
87
+
88
+ AutoConfig.register(CustomCLIPConfig.model_type, CustomCLIPConfig)
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:423a03a2873e4eda3ff4ee2b99f0e34dccbdd9f5a4a8996219d7bc0aadb9283b
3
+ size 3311897444
modeling_custom_clip.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Subclasses VisionTextDualEncoderModel to customize text pooler.
3
+ """
4
+
5
+ from typing import Optional
6
+
7
+ import torch
8
+ from transformers import AutoModel, VisionTextDualEncoderModel
9
+
10
+ from .configuration_custom_clip import CustomCLIPConfig, get_text_model_pooler
11
+
12
+
13
+ # @add_start_docstrings(CUSTOM_CLIP_START_DOCSTRING)
14
+ class CustomCLIPModel(VisionTextDualEncoderModel):
15
+ config_class = CustomCLIPConfig
16
+
17
+ DEFAULT_TEXT_MODEL_POOLER_TYPE: torch.nn.Module = get_text_model_pooler(
18
+ CustomCLIPConfig.DEFAULT_TEXT_MODEL_POOLER_STR
19
+ )
20
+ DEFAULT_TEXT_MODEL_POOLER_KWARGS: dict = (
21
+ CustomCLIPConfig.DEFAULT_TEXT_MODEL_POOLER_KWARGS
22
+ )
23
+
24
+ def __init__(
25
+ self, config: Optional[CustomCLIPConfig.__base__] = None, *args, **kwargs
26
+ ):
27
+ config = config if config is None else CustomCLIPConfig.from_base(config)
28
+ super().__init__(
29
+ config, # surprisingly, `super` is unnecessary, possibly due to implementation of CustomCLIPConfig.__init__?
30
+ *args,
31
+ **kwargs,
32
+ )
33
+
34
+ self.text_model.pooler = (
35
+ (self.DEFAULT_TEXT_MODEL_POOLER_TYPE)(
36
+ **self.DEFAULT_TEXT_MODEL_POOLER_KWARGS
37
+ )
38
+ if config is None
39
+ else get_text_model_pooler(config.text_model_pooler)(
40
+ **config.text_model_pooler_kwargs
41
+ )
42
+ )
43
+
44
+
45
+ AutoModel.register(CustomCLIPConfig, CustomCLIPModel)