AutoGUI commited on
Commit
e526584
1 Parent(s): d54969a

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: peft
3
+ base_model: Qwen/Qwen-VL-Chat
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
+
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]
200
+ ### Framework versions
201
+
202
+ - PEFT 0.11.1
config.json ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "AutoGUILMHeadModel"
4
+ ],
5
+ "attn_dropout_prob": 0.0,
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_autogui.AutoGUIConfig",
8
+ "AutoModelForCausalLM": "modeling_autogui.AutoGUILMHeadModel"
9
+ },
10
+ "bf16": true,
11
+ "emb_dropout_prob": 0.0,
12
+ "fp16": false,
13
+ "fp32": false,
14
+ "hidden_size": 4096,
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 22016,
17
+ "kv_channels": 128,
18
+ "layer_norm_epsilon": 1e-06,
19
+ "max_position_embeddings": 8192,
20
+ "model_type": "autogui",
21
+ "no_bias": true,
22
+ "num_attention_heads": 32,
23
+ "num_hidden_layers": 32,
24
+ "onnx_safe": null,
25
+ "rotary_emb_base": 10000,
26
+ "rotary_pct": 1.0,
27
+ "scale_attn_weights": true,
28
+ "seq_length": 2048,
29
+ "tie_word_embeddings": false,
30
+ "tokenizer_type": "QWenTokenizer",
31
+ "torch_dtype": "bfloat16",
32
+ "transformers_version": "4.37.2",
33
+ "use_cache": true,
34
+ "use_dynamic_ntk": true,
35
+ "use_flash_attn": false,
36
+ "use_logn_attn": true,
37
+ "visual": {
38
+ "heads": 16,
39
+ "image_size": 448,
40
+ "image_start_id": 151857,
41
+ "layers": 48,
42
+ "mlp_ratio": 4.9231,
43
+ "output_dim": 4096,
44
+ "patch_size": 14,
45
+ "width": 1664,
46
+ "post_resampler": false
47
+ },
48
+ "vocab_size": 151936
49
+ }
configuration_autogui.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba Cloud.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ from transformers import PretrainedConfig
7
+
8
+
9
+ class AutoGUIConfig(PretrainedConfig):
10
+ model_type = "autogui"
11
+ keys_to_ignore_at_inference = ["past_key_values"]
12
+
13
+ def __init__(
14
+ self,
15
+ vocab_size=151860,
16
+ hidden_size=4096,
17
+ num_hidden_layers=32,
18
+ num_attention_heads=32,
19
+ emb_dropout_prob=0.0,
20
+ attn_dropout_prob=0.0,
21
+ layer_norm_epsilon=1e-6,
22
+ initializer_range=0.02,
23
+ max_position_embeddings=8192,
24
+ scale_attn_weights=True,
25
+ use_cache=True,
26
+ bf16=False,
27
+ fp16=False,
28
+ fp32=False,
29
+ kv_channels=128,
30
+ rotary_pct=1.0,
31
+ rotary_emb_base=10000,
32
+ use_dynamic_ntk=True,
33
+ use_logn_attn=True,
34
+ use_flash_attn="auto",
35
+ intermediate_size=22016,
36
+ no_bias=True,
37
+ tie_word_embeddings=False,
38
+ **kwargs,
39
+ ):
40
+ self.vocab_size = vocab_size
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.emb_dropout_prob = emb_dropout_prob
46
+ self.attn_dropout_prob = attn_dropout_prob
47
+ self.layer_norm_epsilon = layer_norm_epsilon
48
+ self.initializer_range = initializer_range
49
+ self.scale_attn_weights = scale_attn_weights
50
+ self.use_cache = use_cache
51
+ self.max_position_embeddings = max_position_embeddings
52
+ self.bf16 = bf16
53
+ self.fp16 = fp16
54
+ self.fp32 = fp32
55
+ self.kv_channels = kv_channels
56
+ self.rotary_pct = rotary_pct
57
+ self.rotary_emb_base = rotary_emb_base
58
+ self.use_dynamic_ntk = use_dynamic_ntk
59
+ self.use_logn_attn = use_logn_attn
60
+ self.use_flash_attn = use_flash_attn
61
+ self.no_bias = no_bias
62
+ super().__init__(
63
+ tie_word_embeddings=tie_word_embeddings,
64
+ **kwargs
65
+ )
configuration_qwen.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba Cloud.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ from transformers import PretrainedConfig
7
+
8
+
9
+ class QWenConfig(PretrainedConfig):
10
+ model_type = "qwen"
11
+ keys_to_ignore_at_inference = ["past_key_values"]
12
+
13
+ def __init__(
14
+ self,
15
+ vocab_size=151936,
16
+ hidden_size=4096,
17
+ num_hidden_layers=32,
18
+ num_attention_heads=32,
19
+ emb_dropout_prob=0.0,
20
+ attn_dropout_prob=0.0,
21
+ layer_norm_epsilon=1e-6,
22
+ initializer_range=0.02,
23
+ max_position_embeddings=8192,
24
+ scale_attn_weights=True,
25
+ use_cache=True,
26
+ bf16=False,
27
+ fp16=False,
28
+ fp32=False,
29
+ kv_channels=128,
30
+ rotary_pct=1.0,
31
+ rotary_emb_base=10000,
32
+ use_dynamic_ntk=True,
33
+ use_logn_attn=True,
34
+ use_flash_attn="auto",
35
+ intermediate_size=22016,
36
+ no_bias=True,
37
+ tie_word_embeddings=False,
38
+ **kwargs,
39
+ ):
40
+ self.vocab_size = vocab_size
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.emb_dropout_prob = emb_dropout_prob
46
+ self.attn_dropout_prob = attn_dropout_prob
47
+ self.layer_norm_epsilon = layer_norm_epsilon
48
+ self.initializer_range = initializer_range
49
+ self.scale_attn_weights = scale_attn_weights
50
+ self.use_cache = use_cache
51
+ self.max_position_embeddings = max_position_embeddings
52
+ self.bf16 = bf16
53
+ self.fp16 = fp16
54
+ self.fp32 = fp32
55
+ self.kv_channels = kv_channels
56
+ self.rotary_pct = rotary_pct
57
+ self.rotary_emb_base = rotary_emb_base
58
+ self.use_dynamic_ntk = use_dynamic_ntk
59
+ self.use_logn_attn = use_logn_attn
60
+ self.use_flash_attn = use_flash_attn
61
+ self.no_bias = no_bias
62
+ super().__init__(
63
+ tie_word_embeddings=tie_word_embeddings,
64
+ **kwargs
65
+ )
generation_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "chat_format": "chatml",
3
+ "do_sample": true,
4
+ "eos_token_id": 151643,
5
+ "max_new_tokens": 512,
6
+ "max_window_size": 6144,
7
+ "pad_token_id": 151643,
8
+ "top_k": 0,
9
+ "top_p": 0.3,
10
+ "transformers_version": "4.37.2"
11
+ }
model-00001-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:723cde0577e10e8e49310c952d54f7201a8905e1462f0b5d299abc80986776be
3
+ size 1964066488
model-00002-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e8b1635cdb6ff48f08880e3acb4cb0f1ecd6e34caaf42a8cb326cc345b48944
3
+ size 2023960808
model-00003-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f2d150c176f4c46d2a4d8e7dfa2f67472099badff3f8824f7c3fd241e6f478f
3
+ size 2023960816
model-00004-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c2d91d1b9df7d6650198fe4dfc85a678eee7427d2725dde1969b884fb835cc25
3
+ size 2023960848
model-00005-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d6e1e9c8deb4cd01d1adea0b6939c04fa0a1529840715c81d3ac49d8e195e16b
3
+ size 2023960848
model-00006-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e709d4c907159ed591589f3afe18795d02d6bdb607b64a2ee00263b62066509b
3
+ size 2023960848
model-00007-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:545d369589b29969249a4a51dbfb24df017e76733fe2c04d0b651c71a19acb71
3
+ size 2023960848
model-00008-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e730554b5959f3715f6cb2bc203c27cee7e72d2c3b74a264e06e32b0fd3111c
3
+ size 2044696480
model-00009-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bdd9227626987f12db68cd3ed4a8ea70a652599b6bd88f853625cdeec590531c
3
+ size 1916789392
model-00010-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3d6b1314f3680e32ce7c69a02f17aed4c1c7bd174269f97b790ef871db10974e
3
+ size 1244659840
model.safetensors.index.json ADDED
@@ -0,0 +1,860 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 19313870336
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "model-00010-of-00010.safetensors",
7
+ "transformer.h.0.attn.c_attn.bias": "model-00001-of-00010.safetensors",
8
+ "transformer.h.0.attn.c_attn.weight": "model-00001-of-00010.safetensors",
9
+ "transformer.h.0.attn.c_proj.weight": "model-00001-of-00010.safetensors",
10
+ "transformer.h.0.ln_1.weight": "model-00001-of-00010.safetensors",
11
+ "transformer.h.0.ln_2.weight": "model-00001-of-00010.safetensors",
12
+ "transformer.h.0.mlp.c_proj.weight": "model-00001-of-00010.safetensors",
13
+ "transformer.h.0.mlp.w1.weight": "model-00001-of-00010.safetensors",
14
+ "transformer.h.0.mlp.w2.weight": "model-00001-of-00010.safetensors",
15
+ "transformer.h.1.attn.c_attn.bias": "model-00001-of-00010.safetensors",
16
+ "transformer.h.1.attn.c_attn.weight": "model-00001-of-00010.safetensors",
17
+ "transformer.h.1.attn.c_proj.weight": "model-00001-of-00010.safetensors",
18
+ "transformer.h.1.ln_1.weight": "model-00001-of-00010.safetensors",
19
+ "transformer.h.1.ln_2.weight": "model-00001-of-00010.safetensors",
20
+ "transformer.h.1.mlp.c_proj.weight": "model-00002-of-00010.safetensors",
21
+ "transformer.h.1.mlp.w1.weight": "model-00001-of-00010.safetensors",
22
+ "transformer.h.1.mlp.w2.weight": "model-00001-of-00010.safetensors",
23
+ "transformer.h.10.attn.c_attn.bias": "model-00003-of-00010.safetensors",
24
+ "transformer.h.10.attn.c_attn.weight": "model-00003-of-00010.safetensors",
25
+ "transformer.h.10.attn.c_proj.weight": "model-00003-of-00010.safetensors",
26
+ "transformer.h.10.ln_1.weight": "model-00003-of-00010.safetensors",
27
+ "transformer.h.10.ln_2.weight": "model-00003-of-00010.safetensors",
28
+ "transformer.h.10.mlp.c_proj.weight": "model-00003-of-00010.safetensors",
29
+ "transformer.h.10.mlp.w1.weight": "model-00003-of-00010.safetensors",
30
+ "transformer.h.10.mlp.w2.weight": "model-00003-of-00010.safetensors",
31
+ "transformer.h.11.attn.c_attn.bias": "model-00003-of-00010.safetensors",
32
+ "transformer.h.11.attn.c_attn.weight": "model-00003-of-00010.safetensors",
33
+ "transformer.h.11.attn.c_proj.weight": "model-00003-of-00010.safetensors",
34
+ "transformer.h.11.ln_1.weight": "model-00003-of-00010.safetensors",
35
+ "transformer.h.11.ln_2.weight": "model-00003-of-00010.safetensors",
36
+ "transformer.h.11.mlp.c_proj.weight": "model-00004-of-00010.safetensors",
37
+ "transformer.h.11.mlp.w1.weight": "model-00003-of-00010.safetensors",
38
+ "transformer.h.11.mlp.w2.weight": "model-00003-of-00010.safetensors",
39
+ "transformer.h.12.attn.c_attn.bias": "model-00004-of-00010.safetensors",
40
+ "transformer.h.12.attn.c_attn.weight": "model-00004-of-00010.safetensors",
41
+ "transformer.h.12.attn.c_proj.weight": "model-00004-of-00010.safetensors",
42
+ "transformer.h.12.ln_1.weight": "model-00004-of-00010.safetensors",
43
+ "transformer.h.12.ln_2.weight": "model-00004-of-00010.safetensors",
44
+ "transformer.h.12.mlp.c_proj.weight": "model-00004-of-00010.safetensors",
45
+ "transformer.h.12.mlp.w1.weight": "model-00004-of-00010.safetensors",
46
+ "transformer.h.12.mlp.w2.weight": "model-00004-of-00010.safetensors",
47
+ "transformer.h.13.attn.c_attn.bias": "model-00004-of-00010.safetensors",
48
+ "transformer.h.13.attn.c_attn.weight": "model-00004-of-00010.safetensors",
49
+ "transformer.h.13.attn.c_proj.weight": "model-00004-of-00010.safetensors",
50
+ "transformer.h.13.ln_1.weight": "model-00004-of-00010.safetensors",
51
+ "transformer.h.13.ln_2.weight": "model-00004-of-00010.safetensors",
52
+ "transformer.h.13.mlp.c_proj.weight": "model-00004-of-00010.safetensors",
53
+ "transformer.h.13.mlp.w1.weight": "model-00004-of-00010.safetensors",
54
+ "transformer.h.13.mlp.w2.weight": "model-00004-of-00010.safetensors",
55
+ "transformer.h.14.attn.c_attn.bias": "model-00004-of-00010.safetensors",
56
+ "transformer.h.14.attn.c_attn.weight": "model-00004-of-00010.safetensors",
57
+ "transformer.h.14.attn.c_proj.weight": "model-00004-of-00010.safetensors",
58
+ "transformer.h.14.ln_1.weight": "model-00004-of-00010.safetensors",
59
+ "transformer.h.14.ln_2.weight": "model-00004-of-00010.safetensors",
60
+ "transformer.h.14.mlp.c_proj.weight": "model-00004-of-00010.safetensors",
61
+ "transformer.h.14.mlp.w1.weight": "model-00004-of-00010.safetensors",
62
+ "transformer.h.14.mlp.w2.weight": "model-00004-of-00010.safetensors",
63
+ "transformer.h.15.attn.c_attn.bias": "model-00004-of-00010.safetensors",
64
+ "transformer.h.15.attn.c_attn.weight": "model-00004-of-00010.safetensors",
65
+ "transformer.h.15.attn.c_proj.weight": "model-00004-of-00010.safetensors",
66
+ "transformer.h.15.ln_1.weight": "model-00004-of-00010.safetensors",
67
+ "transformer.h.15.ln_2.weight": "model-00004-of-00010.safetensors",
68
+ "transformer.h.15.mlp.c_proj.weight": "model-00004-of-00010.safetensors",
69
+ "transformer.h.15.mlp.w1.weight": "model-00004-of-00010.safetensors",
70
+ "transformer.h.15.mlp.w2.weight": "model-00004-of-00010.safetensors",
71
+ "transformer.h.16.attn.c_attn.bias": "model-00004-of-00010.safetensors",
72
+ "transformer.h.16.attn.c_attn.weight": "model-00004-of-00010.safetensors",
73
+ "transformer.h.16.attn.c_proj.weight": "model-00004-of-00010.safetensors",
74
+ "transformer.h.16.ln_1.weight": "model-00004-of-00010.safetensors",
75
+ "transformer.h.16.ln_2.weight": "model-00004-of-00010.safetensors",
76
+ "transformer.h.16.mlp.c_proj.weight": "model-00005-of-00010.safetensors",
77
+ "transformer.h.16.mlp.w1.weight": "model-00004-of-00010.safetensors",
78
+ "transformer.h.16.mlp.w2.weight": "model-00004-of-00010.safetensors",
79
+ "transformer.h.17.attn.c_attn.bias": "model-00005-of-00010.safetensors",
80
+ "transformer.h.17.attn.c_attn.weight": "model-00005-of-00010.safetensors",
81
+ "transformer.h.17.attn.c_proj.weight": "model-00005-of-00010.safetensors",
82
+ "transformer.h.17.ln_1.weight": "model-00005-of-00010.safetensors",
83
+ "transformer.h.17.ln_2.weight": "model-00005-of-00010.safetensors",
84
+ "transformer.h.17.mlp.c_proj.weight": "model-00005-of-00010.safetensors",
85
+ "transformer.h.17.mlp.w1.weight": "model-00005-of-00010.safetensors",
86
+ "transformer.h.17.mlp.w2.weight": "model-00005-of-00010.safetensors",
87
+ "transformer.h.18.attn.c_attn.bias": "model-00005-of-00010.safetensors",
88
+ "transformer.h.18.attn.c_attn.weight": "model-00005-of-00010.safetensors",
89
+ "transformer.h.18.attn.c_proj.weight": "model-00005-of-00010.safetensors",
90
+ "transformer.h.18.ln_1.weight": "model-00005-of-00010.safetensors",
91
+ "transformer.h.18.ln_2.weight": "model-00005-of-00010.safetensors",
92
+ "transformer.h.18.mlp.c_proj.weight": "model-00005-of-00010.safetensors",
93
+ "transformer.h.18.mlp.w1.weight": "model-00005-of-00010.safetensors",
94
+ "transformer.h.18.mlp.w2.weight": "model-00005-of-00010.safetensors",
95
+ "transformer.h.19.attn.c_attn.bias": "model-00005-of-00010.safetensors",
96
+ "transformer.h.19.attn.c_attn.weight": "model-00005-of-00010.safetensors",
97
+ "transformer.h.19.attn.c_proj.weight": "model-00005-of-00010.safetensors",
98
+ "transformer.h.19.ln_1.weight": "model-00005-of-00010.safetensors",
99
+ "transformer.h.19.ln_2.weight": "model-00005-of-00010.safetensors",
100
+ "transformer.h.19.mlp.c_proj.weight": "model-00005-of-00010.safetensors",
101
+ "transformer.h.19.mlp.w1.weight": "model-00005-of-00010.safetensors",
102
+ "transformer.h.19.mlp.w2.weight": "model-00005-of-00010.safetensors",
103
+ "transformer.h.2.attn.c_attn.bias": "model-00002-of-00010.safetensors",
104
+ "transformer.h.2.attn.c_attn.weight": "model-00002-of-00010.safetensors",
105
+ "transformer.h.2.attn.c_proj.weight": "model-00002-of-00010.safetensors",
106
+ "transformer.h.2.ln_1.weight": "model-00002-of-00010.safetensors",
107
+ "transformer.h.2.ln_2.weight": "model-00002-of-00010.safetensors",
108
+ "transformer.h.2.mlp.c_proj.weight": "model-00002-of-00010.safetensors",
109
+ "transformer.h.2.mlp.w1.weight": "model-00002-of-00010.safetensors",
110
+ "transformer.h.2.mlp.w2.weight": "model-00002-of-00010.safetensors",
111
+ "transformer.h.20.attn.c_attn.bias": "model-00005-of-00010.safetensors",
112
+ "transformer.h.20.attn.c_attn.weight": "model-00005-of-00010.safetensors",
113
+ "transformer.h.20.attn.c_proj.weight": "model-00005-of-00010.safetensors",
114
+ "transformer.h.20.ln_1.weight": "model-00005-of-00010.safetensors",
115
+ "transformer.h.20.ln_2.weight": "model-00005-of-00010.safetensors",
116
+ "transformer.h.20.mlp.c_proj.weight": "model-00005-of-00010.safetensors",
117
+ "transformer.h.20.mlp.w1.weight": "model-00005-of-00010.safetensors",
118
+ "transformer.h.20.mlp.w2.weight": "model-00005-of-00010.safetensors",
119
+ "transformer.h.21.attn.c_attn.bias": "model-00005-of-00010.safetensors",
120
+ "transformer.h.21.attn.c_attn.weight": "model-00005-of-00010.safetensors",
121
+ "transformer.h.21.attn.c_proj.weight": "model-00005-of-00010.safetensors",
122
+ "transformer.h.21.ln_1.weight": "model-00005-of-00010.safetensors",
123
+ "transformer.h.21.ln_2.weight": "model-00005-of-00010.safetensors",
124
+ "transformer.h.21.mlp.c_proj.weight": "model-00006-of-00010.safetensors",
125
+ "transformer.h.21.mlp.w1.weight": "model-00005-of-00010.safetensors",
126
+ "transformer.h.21.mlp.w2.weight": "model-00005-of-00010.safetensors",
127
+ "transformer.h.22.attn.c_attn.bias": "model-00006-of-00010.safetensors",
128
+ "transformer.h.22.attn.c_attn.weight": "model-00006-of-00010.safetensors",
129
+ "transformer.h.22.attn.c_proj.weight": "model-00006-of-00010.safetensors",
130
+ "transformer.h.22.ln_1.weight": "model-00006-of-00010.safetensors",
131
+ "transformer.h.22.ln_2.weight": "model-00006-of-00010.safetensors",
132
+ "transformer.h.22.mlp.c_proj.weight": "model-00006-of-00010.safetensors",
133
+ "transformer.h.22.mlp.w1.weight": "model-00006-of-00010.safetensors",
134
+ "transformer.h.22.mlp.w2.weight": "model-00006-of-00010.safetensors",
135
+ "transformer.h.23.attn.c_attn.bias": "model-00006-of-00010.safetensors",
136
+ "transformer.h.23.attn.c_attn.weight": "model-00006-of-00010.safetensors",
137
+ "transformer.h.23.attn.c_proj.weight": "model-00006-of-00010.safetensors",
138
+ "transformer.h.23.ln_1.weight": "model-00006-of-00010.safetensors",
139
+ "transformer.h.23.ln_2.weight": "model-00006-of-00010.safetensors",
140
+ "transformer.h.23.mlp.c_proj.weight": "model-00006-of-00010.safetensors",
141
+ "transformer.h.23.mlp.w1.weight": "model-00006-of-00010.safetensors",
142
+ "transformer.h.23.mlp.w2.weight": "model-00006-of-00010.safetensors",
143
+ "transformer.h.24.attn.c_attn.bias": "model-00006-of-00010.safetensors",
144
+ "transformer.h.24.attn.c_attn.weight": "model-00006-of-00010.safetensors",
145
+ "transformer.h.24.attn.c_proj.weight": "model-00006-of-00010.safetensors",
146
+ "transformer.h.24.ln_1.weight": "model-00006-of-00010.safetensors",
147
+ "transformer.h.24.ln_2.weight": "model-00006-of-00010.safetensors",
148
+ "transformer.h.24.mlp.c_proj.weight": "model-00006-of-00010.safetensors",
149
+ "transformer.h.24.mlp.w1.weight": "model-00006-of-00010.safetensors",
150
+ "transformer.h.24.mlp.w2.weight": "model-00006-of-00010.safetensors",
151
+ "transformer.h.25.attn.c_attn.bias": "model-00006-of-00010.safetensors",
152
+ "transformer.h.25.attn.c_attn.weight": "model-00006-of-00010.safetensors",
153
+ "transformer.h.25.attn.c_proj.weight": "model-00006-of-00010.safetensors",
154
+ "transformer.h.25.ln_1.weight": "model-00006-of-00010.safetensors",
155
+ "transformer.h.25.ln_2.weight": "model-00006-of-00010.safetensors",
156
+ "transformer.h.25.mlp.c_proj.weight": "model-00006-of-00010.safetensors",
157
+ "transformer.h.25.mlp.w1.weight": "model-00006-of-00010.safetensors",
158
+ "transformer.h.25.mlp.w2.weight": "model-00006-of-00010.safetensors",
159
+ "transformer.h.26.attn.c_attn.bias": "model-00006-of-00010.safetensors",
160
+ "transformer.h.26.attn.c_attn.weight": "model-00006-of-00010.safetensors",
161
+ "transformer.h.26.attn.c_proj.weight": "model-00006-of-00010.safetensors",
162
+ "transformer.h.26.ln_1.weight": "model-00006-of-00010.safetensors",
163
+ "transformer.h.26.ln_2.weight": "model-00006-of-00010.safetensors",
164
+ "transformer.h.26.mlp.c_proj.weight": "model-00007-of-00010.safetensors",
165
+ "transformer.h.26.mlp.w1.weight": "model-00006-of-00010.safetensors",
166
+ "transformer.h.26.mlp.w2.weight": "model-00006-of-00010.safetensors",
167
+ "transformer.h.27.attn.c_attn.bias": "model-00007-of-00010.safetensors",
168
+ "transformer.h.27.attn.c_attn.weight": "model-00007-of-00010.safetensors",
169
+ "transformer.h.27.attn.c_proj.weight": "model-00007-of-00010.safetensors",
170
+ "transformer.h.27.ln_1.weight": "model-00007-of-00010.safetensors",
171
+ "transformer.h.27.ln_2.weight": "model-00007-of-00010.safetensors",
172
+ "transformer.h.27.mlp.c_proj.weight": "model-00007-of-00010.safetensors",
173
+ "transformer.h.27.mlp.w1.weight": "model-00007-of-00010.safetensors",
174
+ "transformer.h.27.mlp.w2.weight": "model-00007-of-00010.safetensors",
175
+ "transformer.h.28.attn.c_attn.bias": "model-00007-of-00010.safetensors",
176
+ "transformer.h.28.attn.c_attn.weight": "model-00007-of-00010.safetensors",
177
+ "transformer.h.28.attn.c_proj.weight": "model-00007-of-00010.safetensors",
178
+ "transformer.h.28.ln_1.weight": "model-00007-of-00010.safetensors",
179
+ "transformer.h.28.ln_2.weight": "model-00007-of-00010.safetensors",
180
+ "transformer.h.28.mlp.c_proj.weight": "model-00007-of-00010.safetensors",
181
+ "transformer.h.28.mlp.w1.weight": "model-00007-of-00010.safetensors",
182
+ "transformer.h.28.mlp.w2.weight": "model-00007-of-00010.safetensors",
183
+ "transformer.h.29.attn.c_attn.bias": "model-00007-of-00010.safetensors",
184
+ "transformer.h.29.attn.c_attn.weight": "model-00007-of-00010.safetensors",
185
+ "transformer.h.29.attn.c_proj.weight": "model-00007-of-00010.safetensors",
186
+ "transformer.h.29.ln_1.weight": "model-00007-of-00010.safetensors",
187
+ "transformer.h.29.ln_2.weight": "model-00007-of-00010.safetensors",
188
+ "transformer.h.29.mlp.c_proj.weight": "model-00007-of-00010.safetensors",
189
+ "transformer.h.29.mlp.w1.weight": "model-00007-of-00010.safetensors",
190
+ "transformer.h.29.mlp.w2.weight": "model-00007-of-00010.safetensors",
191
+ "transformer.h.3.attn.c_attn.bias": "model-00002-of-00010.safetensors",
192
+ "transformer.h.3.attn.c_attn.weight": "model-00002-of-00010.safetensors",
193
+ "transformer.h.3.attn.c_proj.weight": "model-00002-of-00010.safetensors",
194
+ "transformer.h.3.ln_1.weight": "model-00002-of-00010.safetensors",
195
+ "transformer.h.3.ln_2.weight": "model-00002-of-00010.safetensors",
196
+ "transformer.h.3.mlp.c_proj.weight": "model-00002-of-00010.safetensors",
197
+ "transformer.h.3.mlp.w1.weight": "model-00002-of-00010.safetensors",
198
+ "transformer.h.3.mlp.w2.weight": "model-00002-of-00010.safetensors",
199
+ "transformer.h.30.attn.c_attn.bias": "model-00007-of-00010.safetensors",
200
+ "transformer.h.30.attn.c_attn.weight": "model-00007-of-00010.safetensors",
201
+ "transformer.h.30.attn.c_proj.weight": "model-00007-of-00010.safetensors",
202
+ "transformer.h.30.ln_1.weight": "model-00007-of-00010.safetensors",
203
+ "transformer.h.30.ln_2.weight": "model-00007-of-00010.safetensors",
204
+ "transformer.h.30.mlp.c_proj.weight": "model-00007-of-00010.safetensors",
205
+ "transformer.h.30.mlp.w1.weight": "model-00007-of-00010.safetensors",
206
+ "transformer.h.30.mlp.w2.weight": "model-00007-of-00010.safetensors",
207
+ "transformer.h.31.attn.c_attn.bias": "model-00007-of-00010.safetensors",
208
+ "transformer.h.31.attn.c_attn.weight": "model-00007-of-00010.safetensors",
209
+ "transformer.h.31.attn.c_proj.weight": "model-00007-of-00010.safetensors",
210
+ "transformer.h.31.ln_1.weight": "model-00007-of-00010.safetensors",
211
+ "transformer.h.31.ln_2.weight": "model-00007-of-00010.safetensors",
212
+ "transformer.h.31.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
213
+ "transformer.h.31.mlp.w1.weight": "model-00007-of-00010.safetensors",
214
+ "transformer.h.31.mlp.w2.weight": "model-00007-of-00010.safetensors",
215
+ "transformer.h.4.attn.c_attn.bias": "model-00002-of-00010.safetensors",
216
+ "transformer.h.4.attn.c_attn.weight": "model-00002-of-00010.safetensors",
217
+ "transformer.h.4.attn.c_proj.weight": "model-00002-of-00010.safetensors",
218
+ "transformer.h.4.ln_1.weight": "model-00002-of-00010.safetensors",
219
+ "transformer.h.4.ln_2.weight": "model-00002-of-00010.safetensors",
220
+ "transformer.h.4.mlp.c_proj.weight": "model-00002-of-00010.safetensors",
221
+ "transformer.h.4.mlp.w1.weight": "model-00002-of-00010.safetensors",
222
+ "transformer.h.4.mlp.w2.weight": "model-00002-of-00010.safetensors",
223
+ "transformer.h.5.attn.c_attn.bias": "model-00002-of-00010.safetensors",
224
+ "transformer.h.5.attn.c_attn.weight": "model-00002-of-00010.safetensors",
225
+ "transformer.h.5.attn.c_proj.weight": "model-00002-of-00010.safetensors",
226
+ "transformer.h.5.ln_1.weight": "model-00002-of-00010.safetensors",
227
+ "transformer.h.5.ln_2.weight": "model-00002-of-00010.safetensors",
228
+ "transformer.h.5.mlp.c_proj.weight": "model-00002-of-00010.safetensors",
229
+ "transformer.h.5.mlp.w1.weight": "model-00002-of-00010.safetensors",
230
+ "transformer.h.5.mlp.w2.weight": "model-00002-of-00010.safetensors",
231
+ "transformer.h.6.attn.c_attn.bias": "model-00002-of-00010.safetensors",
232
+ "transformer.h.6.attn.c_attn.weight": "model-00002-of-00010.safetensors",
233
+ "transformer.h.6.attn.c_proj.weight": "model-00002-of-00010.safetensors",
234
+ "transformer.h.6.ln_1.weight": "model-00002-of-00010.safetensors",
235
+ "transformer.h.6.ln_2.weight": "model-00002-of-00010.safetensors",
236
+ "transformer.h.6.mlp.c_proj.weight": "model-00003-of-00010.safetensors",
237
+ "transformer.h.6.mlp.w1.weight": "model-00002-of-00010.safetensors",
238
+ "transformer.h.6.mlp.w2.weight": "model-00002-of-00010.safetensors",
239
+ "transformer.h.7.attn.c_attn.bias": "model-00003-of-00010.safetensors",
240
+ "transformer.h.7.attn.c_attn.weight": "model-00003-of-00010.safetensors",
241
+ "transformer.h.7.attn.c_proj.weight": "model-00003-of-00010.safetensors",
242
+ "transformer.h.7.ln_1.weight": "model-00003-of-00010.safetensors",
243
+ "transformer.h.7.ln_2.weight": "model-00003-of-00010.safetensors",
244
+ "transformer.h.7.mlp.c_proj.weight": "model-00003-of-00010.safetensors",
245
+ "transformer.h.7.mlp.w1.weight": "model-00003-of-00010.safetensors",
246
+ "transformer.h.7.mlp.w2.weight": "model-00003-of-00010.safetensors",
247
+ "transformer.h.8.attn.c_attn.bias": "model-00003-of-00010.safetensors",
248
+ "transformer.h.8.attn.c_attn.weight": "model-00003-of-00010.safetensors",
249
+ "transformer.h.8.attn.c_proj.weight": "model-00003-of-00010.safetensors",
250
+ "transformer.h.8.ln_1.weight": "model-00003-of-00010.safetensors",
251
+ "transformer.h.8.ln_2.weight": "model-00003-of-00010.safetensors",
252
+ "transformer.h.8.mlp.c_proj.weight": "model-00003-of-00010.safetensors",
253
+ "transformer.h.8.mlp.w1.weight": "model-00003-of-00010.safetensors",
254
+ "transformer.h.8.mlp.w2.weight": "model-00003-of-00010.safetensors",
255
+ "transformer.h.9.attn.c_attn.bias": "model-00003-of-00010.safetensors",
256
+ "transformer.h.9.attn.c_attn.weight": "model-00003-of-00010.safetensors",
257
+ "transformer.h.9.attn.c_proj.weight": "model-00003-of-00010.safetensors",
258
+ "transformer.h.9.ln_1.weight": "model-00003-of-00010.safetensors",
259
+ "transformer.h.9.ln_2.weight": "model-00003-of-00010.safetensors",
260
+ "transformer.h.9.mlp.c_proj.weight": "model-00003-of-00010.safetensors",
261
+ "transformer.h.9.mlp.w1.weight": "model-00003-of-00010.safetensors",
262
+ "transformer.h.9.mlp.w2.weight": "model-00003-of-00010.safetensors",
263
+ "transformer.ln_f.weight": "model-00008-of-00010.safetensors",
264
+ "transformer.visual.attn_pool.attn.in_proj_bias": "model-00009-of-00010.safetensors",
265
+ "transformer.visual.attn_pool.attn.in_proj_weight": "model-00009-of-00010.safetensors",
266
+ "transformer.visual.attn_pool.attn.out_proj.bias": "model-00009-of-00010.safetensors",
267
+ "transformer.visual.attn_pool.attn.out_proj.weight": "model-00009-of-00010.safetensors",
268
+ "transformer.visual.attn_pool.kv_proj.weight": "model-00009-of-00010.safetensors",
269
+ "transformer.visual.attn_pool.ln_kv.bias": "model-00009-of-00010.safetensors",
270
+ "transformer.visual.attn_pool.ln_kv.weight": "model-00009-of-00010.safetensors",
271
+ "transformer.visual.attn_pool.ln_q.bias": "model-00009-of-00010.safetensors",
272
+ "transformer.visual.attn_pool.ln_q.weight": "model-00009-of-00010.safetensors",
273
+ "transformer.visual.attn_pool.pos_embed": "model-00009-of-00010.safetensors",
274
+ "transformer.visual.attn_pool.query": "model-00009-of-00010.safetensors",
275
+ "transformer.visual.conv1.weight": "model-00008-of-00010.safetensors",
276
+ "transformer.visual.ln_post.bias": "model-00009-of-00010.safetensors",
277
+ "transformer.visual.ln_post.weight": "model-00009-of-00010.safetensors",
278
+ "transformer.visual.ln_pre.bias": "model-00008-of-00010.safetensors",
279
+ "transformer.visual.ln_pre.weight": "model-00008-of-00010.safetensors",
280
+ "transformer.visual.positional_embedding": "model-00008-of-00010.safetensors",
281
+ "transformer.visual.proj": "model-00008-of-00010.safetensors",
282
+ "transformer.visual.transformer.resblocks.0.attn.in_proj.bias": "model-00008-of-00010.safetensors",
283
+ "transformer.visual.transformer.resblocks.0.attn.in_proj.weight": "model-00008-of-00010.safetensors",
284
+ "transformer.visual.transformer.resblocks.0.attn.out_proj.bias": "model-00008-of-00010.safetensors",
285
+ "transformer.visual.transformer.resblocks.0.attn.out_proj.weight": "model-00008-of-00010.safetensors",
286
+ "transformer.visual.transformer.resblocks.0.ln_1.bias": "model-00008-of-00010.safetensors",
287
+ "transformer.visual.transformer.resblocks.0.ln_1.weight": "model-00008-of-00010.safetensors",
288
+ "transformer.visual.transformer.resblocks.0.ln_2.bias": "model-00008-of-00010.safetensors",
289
+ "transformer.visual.transformer.resblocks.0.ln_2.weight": "model-00008-of-00010.safetensors",
290
+ "transformer.visual.transformer.resblocks.0.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
291
+ "transformer.visual.transformer.resblocks.0.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
292
+ "transformer.visual.transformer.resblocks.0.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
293
+ "transformer.visual.transformer.resblocks.0.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
294
+ "transformer.visual.transformer.resblocks.1.attn.in_proj.bias": "model-00008-of-00010.safetensors",
295
+ "transformer.visual.transformer.resblocks.1.attn.in_proj.weight": "model-00008-of-00010.safetensors",
296
+ "transformer.visual.transformer.resblocks.1.attn.out_proj.bias": "model-00008-of-00010.safetensors",
297
+ "transformer.visual.transformer.resblocks.1.attn.out_proj.weight": "model-00008-of-00010.safetensors",
298
+ "transformer.visual.transformer.resblocks.1.ln_1.bias": "model-00008-of-00010.safetensors",
299
+ "transformer.visual.transformer.resblocks.1.ln_1.weight": "model-00008-of-00010.safetensors",
300
+ "transformer.visual.transformer.resblocks.1.ln_2.bias": "model-00008-of-00010.safetensors",
301
+ "transformer.visual.transformer.resblocks.1.ln_2.weight": "model-00008-of-00010.safetensors",
302
+ "transformer.visual.transformer.resblocks.1.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
303
+ "transformer.visual.transformer.resblocks.1.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
304
+ "transformer.visual.transformer.resblocks.1.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
305
+ "transformer.visual.transformer.resblocks.1.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
306
+ "transformer.visual.transformer.resblocks.10.attn.in_proj.bias": "model-00008-of-00010.safetensors",
307
+ "transformer.visual.transformer.resblocks.10.attn.in_proj.weight": "model-00008-of-00010.safetensors",
308
+ "transformer.visual.transformer.resblocks.10.attn.out_proj.bias": "model-00008-of-00010.safetensors",
309
+ "transformer.visual.transformer.resblocks.10.attn.out_proj.weight": "model-00008-of-00010.safetensors",
310
+ "transformer.visual.transformer.resblocks.10.ln_1.bias": "model-00008-of-00010.safetensors",
311
+ "transformer.visual.transformer.resblocks.10.ln_1.weight": "model-00008-of-00010.safetensors",
312
+ "transformer.visual.transformer.resblocks.10.ln_2.bias": "model-00008-of-00010.safetensors",
313
+ "transformer.visual.transformer.resblocks.10.ln_2.weight": "model-00008-of-00010.safetensors",
314
+ "transformer.visual.transformer.resblocks.10.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
315
+ "transformer.visual.transformer.resblocks.10.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
316
+ "transformer.visual.transformer.resblocks.10.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
317
+ "transformer.visual.transformer.resblocks.10.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
318
+ "transformer.visual.transformer.resblocks.11.attn.in_proj.bias": "model-00008-of-00010.safetensors",
319
+ "transformer.visual.transformer.resblocks.11.attn.in_proj.weight": "model-00008-of-00010.safetensors",
320
+ "transformer.visual.transformer.resblocks.11.attn.out_proj.bias": "model-00008-of-00010.safetensors",
321
+ "transformer.visual.transformer.resblocks.11.attn.out_proj.weight": "model-00008-of-00010.safetensors",
322
+ "transformer.visual.transformer.resblocks.11.ln_1.bias": "model-00008-of-00010.safetensors",
323
+ "transformer.visual.transformer.resblocks.11.ln_1.weight": "model-00008-of-00010.safetensors",
324
+ "transformer.visual.transformer.resblocks.11.ln_2.bias": "model-00008-of-00010.safetensors",
325
+ "transformer.visual.transformer.resblocks.11.ln_2.weight": "model-00008-of-00010.safetensors",
326
+ "transformer.visual.transformer.resblocks.11.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
327
+ "transformer.visual.transformer.resblocks.11.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
328
+ "transformer.visual.transformer.resblocks.11.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
329
+ "transformer.visual.transformer.resblocks.11.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
330
+ "transformer.visual.transformer.resblocks.12.attn.in_proj.bias": "model-00008-of-00010.safetensors",
331
+ "transformer.visual.transformer.resblocks.12.attn.in_proj.weight": "model-00008-of-00010.safetensors",
332
+ "transformer.visual.transformer.resblocks.12.attn.out_proj.bias": "model-00008-of-00010.safetensors",
333
+ "transformer.visual.transformer.resblocks.12.attn.out_proj.weight": "model-00008-of-00010.safetensors",
334
+ "transformer.visual.transformer.resblocks.12.ln_1.bias": "model-00008-of-00010.safetensors",
335
+ "transformer.visual.transformer.resblocks.12.ln_1.weight": "model-00008-of-00010.safetensors",
336
+ "transformer.visual.transformer.resblocks.12.ln_2.bias": "model-00008-of-00010.safetensors",
337
+ "transformer.visual.transformer.resblocks.12.ln_2.weight": "model-00008-of-00010.safetensors",
338
+ "transformer.visual.transformer.resblocks.12.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
339
+ "transformer.visual.transformer.resblocks.12.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
340
+ "transformer.visual.transformer.resblocks.12.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
341
+ "transformer.visual.transformer.resblocks.12.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
342
+ "transformer.visual.transformer.resblocks.13.attn.in_proj.bias": "model-00008-of-00010.safetensors",
343
+ "transformer.visual.transformer.resblocks.13.attn.in_proj.weight": "model-00008-of-00010.safetensors",
344
+ "transformer.visual.transformer.resblocks.13.attn.out_proj.bias": "model-00008-of-00010.safetensors",
345
+ "transformer.visual.transformer.resblocks.13.attn.out_proj.weight": "model-00008-of-00010.safetensors",
346
+ "transformer.visual.transformer.resblocks.13.ln_1.bias": "model-00008-of-00010.safetensors",
347
+ "transformer.visual.transformer.resblocks.13.ln_1.weight": "model-00008-of-00010.safetensors",
348
+ "transformer.visual.transformer.resblocks.13.ln_2.bias": "model-00008-of-00010.safetensors",
349
+ "transformer.visual.transformer.resblocks.13.ln_2.weight": "model-00008-of-00010.safetensors",
350
+ "transformer.visual.transformer.resblocks.13.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
351
+ "transformer.visual.transformer.resblocks.13.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
352
+ "transformer.visual.transformer.resblocks.13.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
353
+ "transformer.visual.transformer.resblocks.13.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
354
+ "transformer.visual.transformer.resblocks.14.attn.in_proj.bias": "model-00008-of-00010.safetensors",
355
+ "transformer.visual.transformer.resblocks.14.attn.in_proj.weight": "model-00008-of-00010.safetensors",
356
+ "transformer.visual.transformer.resblocks.14.attn.out_proj.bias": "model-00008-of-00010.safetensors",
357
+ "transformer.visual.transformer.resblocks.14.attn.out_proj.weight": "model-00008-of-00010.safetensors",
358
+ "transformer.visual.transformer.resblocks.14.ln_1.bias": "model-00008-of-00010.safetensors",
359
+ "transformer.visual.transformer.resblocks.14.ln_1.weight": "model-00008-of-00010.safetensors",
360
+ "transformer.visual.transformer.resblocks.14.ln_2.bias": "model-00008-of-00010.safetensors",
361
+ "transformer.visual.transformer.resblocks.14.ln_2.weight": "model-00008-of-00010.safetensors",
362
+ "transformer.visual.transformer.resblocks.14.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
363
+ "transformer.visual.transformer.resblocks.14.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
364
+ "transformer.visual.transformer.resblocks.14.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
365
+ "transformer.visual.transformer.resblocks.14.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
366
+ "transformer.visual.transformer.resblocks.15.attn.in_proj.bias": "model-00008-of-00010.safetensors",
367
+ "transformer.visual.transformer.resblocks.15.attn.in_proj.weight": "model-00008-of-00010.safetensors",
368
+ "transformer.visual.transformer.resblocks.15.attn.out_proj.bias": "model-00008-of-00010.safetensors",
369
+ "transformer.visual.transformer.resblocks.15.attn.out_proj.weight": "model-00008-of-00010.safetensors",
370
+ "transformer.visual.transformer.resblocks.15.ln_1.bias": "model-00008-of-00010.safetensors",
371
+ "transformer.visual.transformer.resblocks.15.ln_1.weight": "model-00008-of-00010.safetensors",
372
+ "transformer.visual.transformer.resblocks.15.ln_2.bias": "model-00008-of-00010.safetensors",
373
+ "transformer.visual.transformer.resblocks.15.ln_2.weight": "model-00008-of-00010.safetensors",
374
+ "transformer.visual.transformer.resblocks.15.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
375
+ "transformer.visual.transformer.resblocks.15.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
376
+ "transformer.visual.transformer.resblocks.15.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
377
+ "transformer.visual.transformer.resblocks.15.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
378
+ "transformer.visual.transformer.resblocks.16.attn.in_proj.bias": "model-00008-of-00010.safetensors",
379
+ "transformer.visual.transformer.resblocks.16.attn.in_proj.weight": "model-00008-of-00010.safetensors",
380
+ "transformer.visual.transformer.resblocks.16.attn.out_proj.bias": "model-00008-of-00010.safetensors",
381
+ "transformer.visual.transformer.resblocks.16.attn.out_proj.weight": "model-00008-of-00010.safetensors",
382
+ "transformer.visual.transformer.resblocks.16.ln_1.bias": "model-00008-of-00010.safetensors",
383
+ "transformer.visual.transformer.resblocks.16.ln_1.weight": "model-00008-of-00010.safetensors",
384
+ "transformer.visual.transformer.resblocks.16.ln_2.bias": "model-00008-of-00010.safetensors",
385
+ "transformer.visual.transformer.resblocks.16.ln_2.weight": "model-00008-of-00010.safetensors",
386
+ "transformer.visual.transformer.resblocks.16.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
387
+ "transformer.visual.transformer.resblocks.16.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
388
+ "transformer.visual.transformer.resblocks.16.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
389
+ "transformer.visual.transformer.resblocks.16.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
390
+ "transformer.visual.transformer.resblocks.17.attn.in_proj.bias": "model-00008-of-00010.safetensors",
391
+ "transformer.visual.transformer.resblocks.17.attn.in_proj.weight": "model-00008-of-00010.safetensors",
392
+ "transformer.visual.transformer.resblocks.17.attn.out_proj.bias": "model-00008-of-00010.safetensors",
393
+ "transformer.visual.transformer.resblocks.17.attn.out_proj.weight": "model-00008-of-00010.safetensors",
394
+ "transformer.visual.transformer.resblocks.17.ln_1.bias": "model-00008-of-00010.safetensors",
395
+ "transformer.visual.transformer.resblocks.17.ln_1.weight": "model-00008-of-00010.safetensors",
396
+ "transformer.visual.transformer.resblocks.17.ln_2.bias": "model-00008-of-00010.safetensors",
397
+ "transformer.visual.transformer.resblocks.17.ln_2.weight": "model-00008-of-00010.safetensors",
398
+ "transformer.visual.transformer.resblocks.17.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
399
+ "transformer.visual.transformer.resblocks.17.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
400
+ "transformer.visual.transformer.resblocks.17.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
401
+ "transformer.visual.transformer.resblocks.17.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
402
+ "transformer.visual.transformer.resblocks.18.attn.in_proj.bias": "model-00008-of-00010.safetensors",
403
+ "transformer.visual.transformer.resblocks.18.attn.in_proj.weight": "model-00008-of-00010.safetensors",
404
+ "transformer.visual.transformer.resblocks.18.attn.out_proj.bias": "model-00008-of-00010.safetensors",
405
+ "transformer.visual.transformer.resblocks.18.attn.out_proj.weight": "model-00008-of-00010.safetensors",
406
+ "transformer.visual.transformer.resblocks.18.ln_1.bias": "model-00008-of-00010.safetensors",
407
+ "transformer.visual.transformer.resblocks.18.ln_1.weight": "model-00008-of-00010.safetensors",
408
+ "transformer.visual.transformer.resblocks.18.ln_2.bias": "model-00008-of-00010.safetensors",
409
+ "transformer.visual.transformer.resblocks.18.ln_2.weight": "model-00008-of-00010.safetensors",
410
+ "transformer.visual.transformer.resblocks.18.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
411
+ "transformer.visual.transformer.resblocks.18.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
412
+ "transformer.visual.transformer.resblocks.18.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
413
+ "transformer.visual.transformer.resblocks.18.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
414
+ "transformer.visual.transformer.resblocks.19.attn.in_proj.bias": "model-00008-of-00010.safetensors",
415
+ "transformer.visual.transformer.resblocks.19.attn.in_proj.weight": "model-00008-of-00010.safetensors",
416
+ "transformer.visual.transformer.resblocks.19.attn.out_proj.bias": "model-00008-of-00010.safetensors",
417
+ "transformer.visual.transformer.resblocks.19.attn.out_proj.weight": "model-00008-of-00010.safetensors",
418
+ "transformer.visual.transformer.resblocks.19.ln_1.bias": "model-00008-of-00010.safetensors",
419
+ "transformer.visual.transformer.resblocks.19.ln_1.weight": "model-00008-of-00010.safetensors",
420
+ "transformer.visual.transformer.resblocks.19.ln_2.bias": "model-00008-of-00010.safetensors",
421
+ "transformer.visual.transformer.resblocks.19.ln_2.weight": "model-00008-of-00010.safetensors",
422
+ "transformer.visual.transformer.resblocks.19.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
423
+ "transformer.visual.transformer.resblocks.19.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
424
+ "transformer.visual.transformer.resblocks.19.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
425
+ "transformer.visual.transformer.resblocks.19.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
426
+ "transformer.visual.transformer.resblocks.2.attn.in_proj.bias": "model-00008-of-00010.safetensors",
427
+ "transformer.visual.transformer.resblocks.2.attn.in_proj.weight": "model-00008-of-00010.safetensors",
428
+ "transformer.visual.transformer.resblocks.2.attn.out_proj.bias": "model-00008-of-00010.safetensors",
429
+ "transformer.visual.transformer.resblocks.2.attn.out_proj.weight": "model-00008-of-00010.safetensors",
430
+ "transformer.visual.transformer.resblocks.2.ln_1.bias": "model-00008-of-00010.safetensors",
431
+ "transformer.visual.transformer.resblocks.2.ln_1.weight": "model-00008-of-00010.safetensors",
432
+ "transformer.visual.transformer.resblocks.2.ln_2.bias": "model-00008-of-00010.safetensors",
433
+ "transformer.visual.transformer.resblocks.2.ln_2.weight": "model-00008-of-00010.safetensors",
434
+ "transformer.visual.transformer.resblocks.2.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
435
+ "transformer.visual.transformer.resblocks.2.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
436
+ "transformer.visual.transformer.resblocks.2.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
437
+ "transformer.visual.transformer.resblocks.2.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
438
+ "transformer.visual.transformer.resblocks.20.attn.in_proj.bias": "model-00008-of-00010.safetensors",
439
+ "transformer.visual.transformer.resblocks.20.attn.in_proj.weight": "model-00008-of-00010.safetensors",
440
+ "transformer.visual.transformer.resblocks.20.attn.out_proj.bias": "model-00008-of-00010.safetensors",
441
+ "transformer.visual.transformer.resblocks.20.attn.out_proj.weight": "model-00008-of-00010.safetensors",
442
+ "transformer.visual.transformer.resblocks.20.ln_1.bias": "model-00008-of-00010.safetensors",
443
+ "transformer.visual.transformer.resblocks.20.ln_1.weight": "model-00008-of-00010.safetensors",
444
+ "transformer.visual.transformer.resblocks.20.ln_2.bias": "model-00008-of-00010.safetensors",
445
+ "transformer.visual.transformer.resblocks.20.ln_2.weight": "model-00008-of-00010.safetensors",
446
+ "transformer.visual.transformer.resblocks.20.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
447
+ "transformer.visual.transformer.resblocks.20.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
448
+ "transformer.visual.transformer.resblocks.20.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
449
+ "transformer.visual.transformer.resblocks.20.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
450
+ "transformer.visual.transformer.resblocks.21.attn.in_proj.bias": "model-00008-of-00010.safetensors",
451
+ "transformer.visual.transformer.resblocks.21.attn.in_proj.weight": "model-00008-of-00010.safetensors",
452
+ "transformer.visual.transformer.resblocks.21.attn.out_proj.bias": "model-00008-of-00010.safetensors",
453
+ "transformer.visual.transformer.resblocks.21.attn.out_proj.weight": "model-00008-of-00010.safetensors",
454
+ "transformer.visual.transformer.resblocks.21.ln_1.bias": "model-00008-of-00010.safetensors",
455
+ "transformer.visual.transformer.resblocks.21.ln_1.weight": "model-00008-of-00010.safetensors",
456
+ "transformer.visual.transformer.resblocks.21.ln_2.bias": "model-00008-of-00010.safetensors",
457
+ "transformer.visual.transformer.resblocks.21.ln_2.weight": "model-00008-of-00010.safetensors",
458
+ "transformer.visual.transformer.resblocks.21.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
459
+ "transformer.visual.transformer.resblocks.21.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
460
+ "transformer.visual.transformer.resblocks.21.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
461
+ "transformer.visual.transformer.resblocks.21.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
462
+ "transformer.visual.transformer.resblocks.22.attn.in_proj.bias": "model-00008-of-00010.safetensors",
463
+ "transformer.visual.transformer.resblocks.22.attn.in_proj.weight": "model-00008-of-00010.safetensors",
464
+ "transformer.visual.transformer.resblocks.22.attn.out_proj.bias": "model-00008-of-00010.safetensors",
465
+ "transformer.visual.transformer.resblocks.22.attn.out_proj.weight": "model-00008-of-00010.safetensors",
466
+ "transformer.visual.transformer.resblocks.22.ln_1.bias": "model-00008-of-00010.safetensors",
467
+ "transformer.visual.transformer.resblocks.22.ln_1.weight": "model-00008-of-00010.safetensors",
468
+ "transformer.visual.transformer.resblocks.22.ln_2.bias": "model-00008-of-00010.safetensors",
469
+ "transformer.visual.transformer.resblocks.22.ln_2.weight": "model-00008-of-00010.safetensors",
470
+ "transformer.visual.transformer.resblocks.22.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
471
+ "transformer.visual.transformer.resblocks.22.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
472
+ "transformer.visual.transformer.resblocks.22.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
473
+ "transformer.visual.transformer.resblocks.22.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
474
+ "transformer.visual.transformer.resblocks.23.attn.in_proj.bias": "model-00008-of-00010.safetensors",
475
+ "transformer.visual.transformer.resblocks.23.attn.in_proj.weight": "model-00008-of-00010.safetensors",
476
+ "transformer.visual.transformer.resblocks.23.attn.out_proj.bias": "model-00008-of-00010.safetensors",
477
+ "transformer.visual.transformer.resblocks.23.attn.out_proj.weight": "model-00008-of-00010.safetensors",
478
+ "transformer.visual.transformer.resblocks.23.ln_1.bias": "model-00008-of-00010.safetensors",
479
+ "transformer.visual.transformer.resblocks.23.ln_1.weight": "model-00008-of-00010.safetensors",
480
+ "transformer.visual.transformer.resblocks.23.ln_2.bias": "model-00008-of-00010.safetensors",
481
+ "transformer.visual.transformer.resblocks.23.ln_2.weight": "model-00008-of-00010.safetensors",
482
+ "transformer.visual.transformer.resblocks.23.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
483
+ "transformer.visual.transformer.resblocks.23.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
484
+ "transformer.visual.transformer.resblocks.23.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
485
+ "transformer.visual.transformer.resblocks.23.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
486
+ "transformer.visual.transformer.resblocks.24.attn.in_proj.bias": "model-00008-of-00010.safetensors",
487
+ "transformer.visual.transformer.resblocks.24.attn.in_proj.weight": "model-00008-of-00010.safetensors",
488
+ "transformer.visual.transformer.resblocks.24.attn.out_proj.bias": "model-00008-of-00010.safetensors",
489
+ "transformer.visual.transformer.resblocks.24.attn.out_proj.weight": "model-00008-of-00010.safetensors",
490
+ "transformer.visual.transformer.resblocks.24.ln_1.bias": "model-00008-of-00010.safetensors",
491
+ "transformer.visual.transformer.resblocks.24.ln_1.weight": "model-00008-of-00010.safetensors",
492
+ "transformer.visual.transformer.resblocks.24.ln_2.bias": "model-00008-of-00010.safetensors",
493
+ "transformer.visual.transformer.resblocks.24.ln_2.weight": "model-00008-of-00010.safetensors",
494
+ "transformer.visual.transformer.resblocks.24.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
495
+ "transformer.visual.transformer.resblocks.24.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
496
+ "transformer.visual.transformer.resblocks.24.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
497
+ "transformer.visual.transformer.resblocks.24.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
498
+ "transformer.visual.transformer.resblocks.25.attn.in_proj.bias": "model-00009-of-00010.safetensors",
499
+ "transformer.visual.transformer.resblocks.25.attn.in_proj.weight": "model-00009-of-00010.safetensors",
500
+ "transformer.visual.transformer.resblocks.25.attn.out_proj.bias": "model-00009-of-00010.safetensors",
501
+ "transformer.visual.transformer.resblocks.25.attn.out_proj.weight": "model-00009-of-00010.safetensors",
502
+ "transformer.visual.transformer.resblocks.25.ln_1.bias": "model-00008-of-00010.safetensors",
503
+ "transformer.visual.transformer.resblocks.25.ln_1.weight": "model-00008-of-00010.safetensors",
504
+ "transformer.visual.transformer.resblocks.25.ln_2.bias": "model-00008-of-00010.safetensors",
505
+ "transformer.visual.transformer.resblocks.25.ln_2.weight": "model-00008-of-00010.safetensors",
506
+ "transformer.visual.transformer.resblocks.25.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
507
+ "transformer.visual.transformer.resblocks.25.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
508
+ "transformer.visual.transformer.resblocks.25.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
509
+ "transformer.visual.transformer.resblocks.25.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
510
+ "transformer.visual.transformer.resblocks.26.attn.in_proj.bias": "model-00009-of-00010.safetensors",
511
+ "transformer.visual.transformer.resblocks.26.attn.in_proj.weight": "model-00009-of-00010.safetensors",
512
+ "transformer.visual.transformer.resblocks.26.attn.out_proj.bias": "model-00009-of-00010.safetensors",
513
+ "transformer.visual.transformer.resblocks.26.attn.out_proj.weight": "model-00009-of-00010.safetensors",
514
+ "transformer.visual.transformer.resblocks.26.ln_1.bias": "model-00009-of-00010.safetensors",
515
+ "transformer.visual.transformer.resblocks.26.ln_1.weight": "model-00009-of-00010.safetensors",
516
+ "transformer.visual.transformer.resblocks.26.ln_2.bias": "model-00009-of-00010.safetensors",
517
+ "transformer.visual.transformer.resblocks.26.ln_2.weight": "model-00009-of-00010.safetensors",
518
+ "transformer.visual.transformer.resblocks.26.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
519
+ "transformer.visual.transformer.resblocks.26.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
520
+ "transformer.visual.transformer.resblocks.26.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
521
+ "transformer.visual.transformer.resblocks.26.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
522
+ "transformer.visual.transformer.resblocks.27.attn.in_proj.bias": "model-00009-of-00010.safetensors",
523
+ "transformer.visual.transformer.resblocks.27.attn.in_proj.weight": "model-00009-of-00010.safetensors",
524
+ "transformer.visual.transformer.resblocks.27.attn.out_proj.bias": "model-00009-of-00010.safetensors",
525
+ "transformer.visual.transformer.resblocks.27.attn.out_proj.weight": "model-00009-of-00010.safetensors",
526
+ "transformer.visual.transformer.resblocks.27.ln_1.bias": "model-00009-of-00010.safetensors",
527
+ "transformer.visual.transformer.resblocks.27.ln_1.weight": "model-00009-of-00010.safetensors",
528
+ "transformer.visual.transformer.resblocks.27.ln_2.bias": "model-00009-of-00010.safetensors",
529
+ "transformer.visual.transformer.resblocks.27.ln_2.weight": "model-00009-of-00010.safetensors",
530
+ "transformer.visual.transformer.resblocks.27.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
531
+ "transformer.visual.transformer.resblocks.27.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
532
+ "transformer.visual.transformer.resblocks.27.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
533
+ "transformer.visual.transformer.resblocks.27.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
534
+ "transformer.visual.transformer.resblocks.28.attn.in_proj.bias": "model-00009-of-00010.safetensors",
535
+ "transformer.visual.transformer.resblocks.28.attn.in_proj.weight": "model-00009-of-00010.safetensors",
536
+ "transformer.visual.transformer.resblocks.28.attn.out_proj.bias": "model-00009-of-00010.safetensors",
537
+ "transformer.visual.transformer.resblocks.28.attn.out_proj.weight": "model-00009-of-00010.safetensors",
538
+ "transformer.visual.transformer.resblocks.28.ln_1.bias": "model-00009-of-00010.safetensors",
539
+ "transformer.visual.transformer.resblocks.28.ln_1.weight": "model-00009-of-00010.safetensors",
540
+ "transformer.visual.transformer.resblocks.28.ln_2.bias": "model-00009-of-00010.safetensors",
541
+ "transformer.visual.transformer.resblocks.28.ln_2.weight": "model-00009-of-00010.safetensors",
542
+ "transformer.visual.transformer.resblocks.28.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
543
+ "transformer.visual.transformer.resblocks.28.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
544
+ "transformer.visual.transformer.resblocks.28.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
545
+ "transformer.visual.transformer.resblocks.28.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
546
+ "transformer.visual.transformer.resblocks.29.attn.in_proj.bias": "model-00009-of-00010.safetensors",
547
+ "transformer.visual.transformer.resblocks.29.attn.in_proj.weight": "model-00009-of-00010.safetensors",
548
+ "transformer.visual.transformer.resblocks.29.attn.out_proj.bias": "model-00009-of-00010.safetensors",
549
+ "transformer.visual.transformer.resblocks.29.attn.out_proj.weight": "model-00009-of-00010.safetensors",
550
+ "transformer.visual.transformer.resblocks.29.ln_1.bias": "model-00009-of-00010.safetensors",
551
+ "transformer.visual.transformer.resblocks.29.ln_1.weight": "model-00009-of-00010.safetensors",
552
+ "transformer.visual.transformer.resblocks.29.ln_2.bias": "model-00009-of-00010.safetensors",
553
+ "transformer.visual.transformer.resblocks.29.ln_2.weight": "model-00009-of-00010.safetensors",
554
+ "transformer.visual.transformer.resblocks.29.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
555
+ "transformer.visual.transformer.resblocks.29.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
556
+ "transformer.visual.transformer.resblocks.29.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
557
+ "transformer.visual.transformer.resblocks.29.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
558
+ "transformer.visual.transformer.resblocks.3.attn.in_proj.bias": "model-00008-of-00010.safetensors",
559
+ "transformer.visual.transformer.resblocks.3.attn.in_proj.weight": "model-00008-of-00010.safetensors",
560
+ "transformer.visual.transformer.resblocks.3.attn.out_proj.bias": "model-00008-of-00010.safetensors",
561
+ "transformer.visual.transformer.resblocks.3.attn.out_proj.weight": "model-00008-of-00010.safetensors",
562
+ "transformer.visual.transformer.resblocks.3.ln_1.bias": "model-00008-of-00010.safetensors",
563
+ "transformer.visual.transformer.resblocks.3.ln_1.weight": "model-00008-of-00010.safetensors",
564
+ "transformer.visual.transformer.resblocks.3.ln_2.bias": "model-00008-of-00010.safetensors",
565
+ "transformer.visual.transformer.resblocks.3.ln_2.weight": "model-00008-of-00010.safetensors",
566
+ "transformer.visual.transformer.resblocks.3.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
567
+ "transformer.visual.transformer.resblocks.3.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
568
+ "transformer.visual.transformer.resblocks.3.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
569
+ "transformer.visual.transformer.resblocks.3.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
570
+ "transformer.visual.transformer.resblocks.30.attn.in_proj.bias": "model-00009-of-00010.safetensors",
571
+ "transformer.visual.transformer.resblocks.30.attn.in_proj.weight": "model-00009-of-00010.safetensors",
572
+ "transformer.visual.transformer.resblocks.30.attn.out_proj.bias": "model-00009-of-00010.safetensors",
573
+ "transformer.visual.transformer.resblocks.30.attn.out_proj.weight": "model-00009-of-00010.safetensors",
574
+ "transformer.visual.transformer.resblocks.30.ln_1.bias": "model-00009-of-00010.safetensors",
575
+ "transformer.visual.transformer.resblocks.30.ln_1.weight": "model-00009-of-00010.safetensors",
576
+ "transformer.visual.transformer.resblocks.30.ln_2.bias": "model-00009-of-00010.safetensors",
577
+ "transformer.visual.transformer.resblocks.30.ln_2.weight": "model-00009-of-00010.safetensors",
578
+ "transformer.visual.transformer.resblocks.30.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
579
+ "transformer.visual.transformer.resblocks.30.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
580
+ "transformer.visual.transformer.resblocks.30.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
581
+ "transformer.visual.transformer.resblocks.30.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
582
+ "transformer.visual.transformer.resblocks.31.attn.in_proj.bias": "model-00009-of-00010.safetensors",
583
+ "transformer.visual.transformer.resblocks.31.attn.in_proj.weight": "model-00009-of-00010.safetensors",
584
+ "transformer.visual.transformer.resblocks.31.attn.out_proj.bias": "model-00009-of-00010.safetensors",
585
+ "transformer.visual.transformer.resblocks.31.attn.out_proj.weight": "model-00009-of-00010.safetensors",
586
+ "transformer.visual.transformer.resblocks.31.ln_1.bias": "model-00009-of-00010.safetensors",
587
+ "transformer.visual.transformer.resblocks.31.ln_1.weight": "model-00009-of-00010.safetensors",
588
+ "transformer.visual.transformer.resblocks.31.ln_2.bias": "model-00009-of-00010.safetensors",
589
+ "transformer.visual.transformer.resblocks.31.ln_2.weight": "model-00009-of-00010.safetensors",
590
+ "transformer.visual.transformer.resblocks.31.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
591
+ "transformer.visual.transformer.resblocks.31.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
592
+ "transformer.visual.transformer.resblocks.31.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
593
+ "transformer.visual.transformer.resblocks.31.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
594
+ "transformer.visual.transformer.resblocks.32.attn.in_proj.bias": "model-00009-of-00010.safetensors",
595
+ "transformer.visual.transformer.resblocks.32.attn.in_proj.weight": "model-00009-of-00010.safetensors",
596
+ "transformer.visual.transformer.resblocks.32.attn.out_proj.bias": "model-00009-of-00010.safetensors",
597
+ "transformer.visual.transformer.resblocks.32.attn.out_proj.weight": "model-00009-of-00010.safetensors",
598
+ "transformer.visual.transformer.resblocks.32.ln_1.bias": "model-00009-of-00010.safetensors",
599
+ "transformer.visual.transformer.resblocks.32.ln_1.weight": "model-00009-of-00010.safetensors",
600
+ "transformer.visual.transformer.resblocks.32.ln_2.bias": "model-00009-of-00010.safetensors",
601
+ "transformer.visual.transformer.resblocks.32.ln_2.weight": "model-00009-of-00010.safetensors",
602
+ "transformer.visual.transformer.resblocks.32.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
603
+ "transformer.visual.transformer.resblocks.32.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
604
+ "transformer.visual.transformer.resblocks.32.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
605
+ "transformer.visual.transformer.resblocks.32.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
606
+ "transformer.visual.transformer.resblocks.33.attn.in_proj.bias": "model-00009-of-00010.safetensors",
607
+ "transformer.visual.transformer.resblocks.33.attn.in_proj.weight": "model-00009-of-00010.safetensors",
608
+ "transformer.visual.transformer.resblocks.33.attn.out_proj.bias": "model-00009-of-00010.safetensors",
609
+ "transformer.visual.transformer.resblocks.33.attn.out_proj.weight": "model-00009-of-00010.safetensors",
610
+ "transformer.visual.transformer.resblocks.33.ln_1.bias": "model-00009-of-00010.safetensors",
611
+ "transformer.visual.transformer.resblocks.33.ln_1.weight": "model-00009-of-00010.safetensors",
612
+ "transformer.visual.transformer.resblocks.33.ln_2.bias": "model-00009-of-00010.safetensors",
613
+ "transformer.visual.transformer.resblocks.33.ln_2.weight": "model-00009-of-00010.safetensors",
614
+ "transformer.visual.transformer.resblocks.33.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
615
+ "transformer.visual.transformer.resblocks.33.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
616
+ "transformer.visual.transformer.resblocks.33.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
617
+ "transformer.visual.transformer.resblocks.33.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
618
+ "transformer.visual.transformer.resblocks.34.attn.in_proj.bias": "model-00009-of-00010.safetensors",
619
+ "transformer.visual.transformer.resblocks.34.attn.in_proj.weight": "model-00009-of-00010.safetensors",
620
+ "transformer.visual.transformer.resblocks.34.attn.out_proj.bias": "model-00009-of-00010.safetensors",
621
+ "transformer.visual.transformer.resblocks.34.attn.out_proj.weight": "model-00009-of-00010.safetensors",
622
+ "transformer.visual.transformer.resblocks.34.ln_1.bias": "model-00009-of-00010.safetensors",
623
+ "transformer.visual.transformer.resblocks.34.ln_1.weight": "model-00009-of-00010.safetensors",
624
+ "transformer.visual.transformer.resblocks.34.ln_2.bias": "model-00009-of-00010.safetensors",
625
+ "transformer.visual.transformer.resblocks.34.ln_2.weight": "model-00009-of-00010.safetensors",
626
+ "transformer.visual.transformer.resblocks.34.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
627
+ "transformer.visual.transformer.resblocks.34.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
628
+ "transformer.visual.transformer.resblocks.34.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
629
+ "transformer.visual.transformer.resblocks.34.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
630
+ "transformer.visual.transformer.resblocks.35.attn.in_proj.bias": "model-00009-of-00010.safetensors",
631
+ "transformer.visual.transformer.resblocks.35.attn.in_proj.weight": "model-00009-of-00010.safetensors",
632
+ "transformer.visual.transformer.resblocks.35.attn.out_proj.bias": "model-00009-of-00010.safetensors",
633
+ "transformer.visual.transformer.resblocks.35.attn.out_proj.weight": "model-00009-of-00010.safetensors",
634
+ "transformer.visual.transformer.resblocks.35.ln_1.bias": "model-00009-of-00010.safetensors",
635
+ "transformer.visual.transformer.resblocks.35.ln_1.weight": "model-00009-of-00010.safetensors",
636
+ "transformer.visual.transformer.resblocks.35.ln_2.bias": "model-00009-of-00010.safetensors",
637
+ "transformer.visual.transformer.resblocks.35.ln_2.weight": "model-00009-of-00010.safetensors",
638
+ "transformer.visual.transformer.resblocks.35.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
639
+ "transformer.visual.transformer.resblocks.35.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
640
+ "transformer.visual.transformer.resblocks.35.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
641
+ "transformer.visual.transformer.resblocks.35.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
642
+ "transformer.visual.transformer.resblocks.36.attn.in_proj.bias": "model-00009-of-00010.safetensors",
643
+ "transformer.visual.transformer.resblocks.36.attn.in_proj.weight": "model-00009-of-00010.safetensors",
644
+ "transformer.visual.transformer.resblocks.36.attn.out_proj.bias": "model-00009-of-00010.safetensors",
645
+ "transformer.visual.transformer.resblocks.36.attn.out_proj.weight": "model-00009-of-00010.safetensors",
646
+ "transformer.visual.transformer.resblocks.36.ln_1.bias": "model-00009-of-00010.safetensors",
647
+ "transformer.visual.transformer.resblocks.36.ln_1.weight": "model-00009-of-00010.safetensors",
648
+ "transformer.visual.transformer.resblocks.36.ln_2.bias": "model-00009-of-00010.safetensors",
649
+ "transformer.visual.transformer.resblocks.36.ln_2.weight": "model-00009-of-00010.safetensors",
650
+ "transformer.visual.transformer.resblocks.36.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
651
+ "transformer.visual.transformer.resblocks.36.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
652
+ "transformer.visual.transformer.resblocks.36.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
653
+ "transformer.visual.transformer.resblocks.36.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
654
+ "transformer.visual.transformer.resblocks.37.attn.in_proj.bias": "model-00009-of-00010.safetensors",
655
+ "transformer.visual.transformer.resblocks.37.attn.in_proj.weight": "model-00009-of-00010.safetensors",
656
+ "transformer.visual.transformer.resblocks.37.attn.out_proj.bias": "model-00009-of-00010.safetensors",
657
+ "transformer.visual.transformer.resblocks.37.attn.out_proj.weight": "model-00009-of-00010.safetensors",
658
+ "transformer.visual.transformer.resblocks.37.ln_1.bias": "model-00009-of-00010.safetensors",
659
+ "transformer.visual.transformer.resblocks.37.ln_1.weight": "model-00009-of-00010.safetensors",
660
+ "transformer.visual.transformer.resblocks.37.ln_2.bias": "model-00009-of-00010.safetensors",
661
+ "transformer.visual.transformer.resblocks.37.ln_2.weight": "model-00009-of-00010.safetensors",
662
+ "transformer.visual.transformer.resblocks.37.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
663
+ "transformer.visual.transformer.resblocks.37.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
664
+ "transformer.visual.transformer.resblocks.37.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
665
+ "transformer.visual.transformer.resblocks.37.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
666
+ "transformer.visual.transformer.resblocks.38.attn.in_proj.bias": "model-00009-of-00010.safetensors",
667
+ "transformer.visual.transformer.resblocks.38.attn.in_proj.weight": "model-00009-of-00010.safetensors",
668
+ "transformer.visual.transformer.resblocks.38.attn.out_proj.bias": "model-00009-of-00010.safetensors",
669
+ "transformer.visual.transformer.resblocks.38.attn.out_proj.weight": "model-00009-of-00010.safetensors",
670
+ "transformer.visual.transformer.resblocks.38.ln_1.bias": "model-00009-of-00010.safetensors",
671
+ "transformer.visual.transformer.resblocks.38.ln_1.weight": "model-00009-of-00010.safetensors",
672
+ "transformer.visual.transformer.resblocks.38.ln_2.bias": "model-00009-of-00010.safetensors",
673
+ "transformer.visual.transformer.resblocks.38.ln_2.weight": "model-00009-of-00010.safetensors",
674
+ "transformer.visual.transformer.resblocks.38.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
675
+ "transformer.visual.transformer.resblocks.38.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
676
+ "transformer.visual.transformer.resblocks.38.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
677
+ "transformer.visual.transformer.resblocks.38.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
678
+ "transformer.visual.transformer.resblocks.39.attn.in_proj.bias": "model-00009-of-00010.safetensors",
679
+ "transformer.visual.transformer.resblocks.39.attn.in_proj.weight": "model-00009-of-00010.safetensors",
680
+ "transformer.visual.transformer.resblocks.39.attn.out_proj.bias": "model-00009-of-00010.safetensors",
681
+ "transformer.visual.transformer.resblocks.39.attn.out_proj.weight": "model-00009-of-00010.safetensors",
682
+ "transformer.visual.transformer.resblocks.39.ln_1.bias": "model-00009-of-00010.safetensors",
683
+ "transformer.visual.transformer.resblocks.39.ln_1.weight": "model-00009-of-00010.safetensors",
684
+ "transformer.visual.transformer.resblocks.39.ln_2.bias": "model-00009-of-00010.safetensors",
685
+ "transformer.visual.transformer.resblocks.39.ln_2.weight": "model-00009-of-00010.safetensors",
686
+ "transformer.visual.transformer.resblocks.39.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
687
+ "transformer.visual.transformer.resblocks.39.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
688
+ "transformer.visual.transformer.resblocks.39.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
689
+ "transformer.visual.transformer.resblocks.39.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
690
+ "transformer.visual.transformer.resblocks.4.attn.in_proj.bias": "model-00008-of-00010.safetensors",
691
+ "transformer.visual.transformer.resblocks.4.attn.in_proj.weight": "model-00008-of-00010.safetensors",
692
+ "transformer.visual.transformer.resblocks.4.attn.out_proj.bias": "model-00008-of-00010.safetensors",
693
+ "transformer.visual.transformer.resblocks.4.attn.out_proj.weight": "model-00008-of-00010.safetensors",
694
+ "transformer.visual.transformer.resblocks.4.ln_1.bias": "model-00008-of-00010.safetensors",
695
+ "transformer.visual.transformer.resblocks.4.ln_1.weight": "model-00008-of-00010.safetensors",
696
+ "transformer.visual.transformer.resblocks.4.ln_2.bias": "model-00008-of-00010.safetensors",
697
+ "transformer.visual.transformer.resblocks.4.ln_2.weight": "model-00008-of-00010.safetensors",
698
+ "transformer.visual.transformer.resblocks.4.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
699
+ "transformer.visual.transformer.resblocks.4.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
700
+ "transformer.visual.transformer.resblocks.4.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
701
+ "transformer.visual.transformer.resblocks.4.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
702
+ "transformer.visual.transformer.resblocks.40.attn.in_proj.bias": "model-00009-of-00010.safetensors",
703
+ "transformer.visual.transformer.resblocks.40.attn.in_proj.weight": "model-00009-of-00010.safetensors",
704
+ "transformer.visual.transformer.resblocks.40.attn.out_proj.bias": "model-00009-of-00010.safetensors",
705
+ "transformer.visual.transformer.resblocks.40.attn.out_proj.weight": "model-00009-of-00010.safetensors",
706
+ "transformer.visual.transformer.resblocks.40.ln_1.bias": "model-00009-of-00010.safetensors",
707
+ "transformer.visual.transformer.resblocks.40.ln_1.weight": "model-00009-of-00010.safetensors",
708
+ "transformer.visual.transformer.resblocks.40.ln_2.bias": "model-00009-of-00010.safetensors",
709
+ "transformer.visual.transformer.resblocks.40.ln_2.weight": "model-00009-of-00010.safetensors",
710
+ "transformer.visual.transformer.resblocks.40.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
711
+ "transformer.visual.transformer.resblocks.40.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
712
+ "transformer.visual.transformer.resblocks.40.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
713
+ "transformer.visual.transformer.resblocks.40.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
714
+ "transformer.visual.transformer.resblocks.41.attn.in_proj.bias": "model-00009-of-00010.safetensors",
715
+ "transformer.visual.transformer.resblocks.41.attn.in_proj.weight": "model-00009-of-00010.safetensors",
716
+ "transformer.visual.transformer.resblocks.41.attn.out_proj.bias": "model-00009-of-00010.safetensors",
717
+ "transformer.visual.transformer.resblocks.41.attn.out_proj.weight": "model-00009-of-00010.safetensors",
718
+ "transformer.visual.transformer.resblocks.41.ln_1.bias": "model-00009-of-00010.safetensors",
719
+ "transformer.visual.transformer.resblocks.41.ln_1.weight": "model-00009-of-00010.safetensors",
720
+ "transformer.visual.transformer.resblocks.41.ln_2.bias": "model-00009-of-00010.safetensors",
721
+ "transformer.visual.transformer.resblocks.41.ln_2.weight": "model-00009-of-00010.safetensors",
722
+ "transformer.visual.transformer.resblocks.41.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
723
+ "transformer.visual.transformer.resblocks.41.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
724
+ "transformer.visual.transformer.resblocks.41.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
725
+ "transformer.visual.transformer.resblocks.41.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
726
+ "transformer.visual.transformer.resblocks.42.attn.in_proj.bias": "model-00009-of-00010.safetensors",
727
+ "transformer.visual.transformer.resblocks.42.attn.in_proj.weight": "model-00009-of-00010.safetensors",
728
+ "transformer.visual.transformer.resblocks.42.attn.out_proj.bias": "model-00009-of-00010.safetensors",
729
+ "transformer.visual.transformer.resblocks.42.attn.out_proj.weight": "model-00009-of-00010.safetensors",
730
+ "transformer.visual.transformer.resblocks.42.ln_1.bias": "model-00009-of-00010.safetensors",
731
+ "transformer.visual.transformer.resblocks.42.ln_1.weight": "model-00009-of-00010.safetensors",
732
+ "transformer.visual.transformer.resblocks.42.ln_2.bias": "model-00009-of-00010.safetensors",
733
+ "transformer.visual.transformer.resblocks.42.ln_2.weight": "model-00009-of-00010.safetensors",
734
+ "transformer.visual.transformer.resblocks.42.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
735
+ "transformer.visual.transformer.resblocks.42.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
736
+ "transformer.visual.transformer.resblocks.42.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
737
+ "transformer.visual.transformer.resblocks.42.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
738
+ "transformer.visual.transformer.resblocks.43.attn.in_proj.bias": "model-00009-of-00010.safetensors",
739
+ "transformer.visual.transformer.resblocks.43.attn.in_proj.weight": "model-00009-of-00010.safetensors",
740
+ "transformer.visual.transformer.resblocks.43.attn.out_proj.bias": "model-00009-of-00010.safetensors",
741
+ "transformer.visual.transformer.resblocks.43.attn.out_proj.weight": "model-00009-of-00010.safetensors",
742
+ "transformer.visual.transformer.resblocks.43.ln_1.bias": "model-00009-of-00010.safetensors",
743
+ "transformer.visual.transformer.resblocks.43.ln_1.weight": "model-00009-of-00010.safetensors",
744
+ "transformer.visual.transformer.resblocks.43.ln_2.bias": "model-00009-of-00010.safetensors",
745
+ "transformer.visual.transformer.resblocks.43.ln_2.weight": "model-00009-of-00010.safetensors",
746
+ "transformer.visual.transformer.resblocks.43.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
747
+ "transformer.visual.transformer.resblocks.43.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
748
+ "transformer.visual.transformer.resblocks.43.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
749
+ "transformer.visual.transformer.resblocks.43.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
750
+ "transformer.visual.transformer.resblocks.44.attn.in_proj.bias": "model-00009-of-00010.safetensors",
751
+ "transformer.visual.transformer.resblocks.44.attn.in_proj.weight": "model-00009-of-00010.safetensors",
752
+ "transformer.visual.transformer.resblocks.44.attn.out_proj.bias": "model-00009-of-00010.safetensors",
753
+ "transformer.visual.transformer.resblocks.44.attn.out_proj.weight": "model-00009-of-00010.safetensors",
754
+ "transformer.visual.transformer.resblocks.44.ln_1.bias": "model-00009-of-00010.safetensors",
755
+ "transformer.visual.transformer.resblocks.44.ln_1.weight": "model-00009-of-00010.safetensors",
756
+ "transformer.visual.transformer.resblocks.44.ln_2.bias": "model-00009-of-00010.safetensors",
757
+ "transformer.visual.transformer.resblocks.44.ln_2.weight": "model-00009-of-00010.safetensors",
758
+ "transformer.visual.transformer.resblocks.44.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
759
+ "transformer.visual.transformer.resblocks.44.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
760
+ "transformer.visual.transformer.resblocks.44.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
761
+ "transformer.visual.transformer.resblocks.44.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
762
+ "transformer.visual.transformer.resblocks.45.attn.in_proj.bias": "model-00009-of-00010.safetensors",
763
+ "transformer.visual.transformer.resblocks.45.attn.in_proj.weight": "model-00009-of-00010.safetensors",
764
+ "transformer.visual.transformer.resblocks.45.attn.out_proj.bias": "model-00009-of-00010.safetensors",
765
+ "transformer.visual.transformer.resblocks.45.attn.out_proj.weight": "model-00009-of-00010.safetensors",
766
+ "transformer.visual.transformer.resblocks.45.ln_1.bias": "model-00009-of-00010.safetensors",
767
+ "transformer.visual.transformer.resblocks.45.ln_1.weight": "model-00009-of-00010.safetensors",
768
+ "transformer.visual.transformer.resblocks.45.ln_2.bias": "model-00009-of-00010.safetensors",
769
+ "transformer.visual.transformer.resblocks.45.ln_2.weight": "model-00009-of-00010.safetensors",
770
+ "transformer.visual.transformer.resblocks.45.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
771
+ "transformer.visual.transformer.resblocks.45.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
772
+ "transformer.visual.transformer.resblocks.45.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
773
+ "transformer.visual.transformer.resblocks.45.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
774
+ "transformer.visual.transformer.resblocks.46.attn.in_proj.bias": "model-00009-of-00010.safetensors",
775
+ "transformer.visual.transformer.resblocks.46.attn.in_proj.weight": "model-00009-of-00010.safetensors",
776
+ "transformer.visual.transformer.resblocks.46.attn.out_proj.bias": "model-00009-of-00010.safetensors",
777
+ "transformer.visual.transformer.resblocks.46.attn.out_proj.weight": "model-00009-of-00010.safetensors",
778
+ "transformer.visual.transformer.resblocks.46.ln_1.bias": "model-00009-of-00010.safetensors",
779
+ "transformer.visual.transformer.resblocks.46.ln_1.weight": "model-00009-of-00010.safetensors",
780
+ "transformer.visual.transformer.resblocks.46.ln_2.bias": "model-00009-of-00010.safetensors",
781
+ "transformer.visual.transformer.resblocks.46.ln_2.weight": "model-00009-of-00010.safetensors",
782
+ "transformer.visual.transformer.resblocks.46.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
783
+ "transformer.visual.transformer.resblocks.46.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
784
+ "transformer.visual.transformer.resblocks.46.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
785
+ "transformer.visual.transformer.resblocks.46.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
786
+ "transformer.visual.transformer.resblocks.47.attn.in_proj.bias": "model-00009-of-00010.safetensors",
787
+ "transformer.visual.transformer.resblocks.47.attn.in_proj.weight": "model-00009-of-00010.safetensors",
788
+ "transformer.visual.transformer.resblocks.47.attn.out_proj.bias": "model-00009-of-00010.safetensors",
789
+ "transformer.visual.transformer.resblocks.47.attn.out_proj.weight": "model-00009-of-00010.safetensors",
790
+ "transformer.visual.transformer.resblocks.47.ln_1.bias": "model-00009-of-00010.safetensors",
791
+ "transformer.visual.transformer.resblocks.47.ln_1.weight": "model-00009-of-00010.safetensors",
792
+ "transformer.visual.transformer.resblocks.47.ln_2.bias": "model-00009-of-00010.safetensors",
793
+ "transformer.visual.transformer.resblocks.47.ln_2.weight": "model-00009-of-00010.safetensors",
794
+ "transformer.visual.transformer.resblocks.47.mlp.c_fc.bias": "model-00009-of-00010.safetensors",
795
+ "transformer.visual.transformer.resblocks.47.mlp.c_fc.weight": "model-00009-of-00010.safetensors",
796
+ "transformer.visual.transformer.resblocks.47.mlp.c_proj.bias": "model-00009-of-00010.safetensors",
797
+ "transformer.visual.transformer.resblocks.47.mlp.c_proj.weight": "model-00009-of-00010.safetensors",
798
+ "transformer.visual.transformer.resblocks.5.attn.in_proj.bias": "model-00008-of-00010.safetensors",
799
+ "transformer.visual.transformer.resblocks.5.attn.in_proj.weight": "model-00008-of-00010.safetensors",
800
+ "transformer.visual.transformer.resblocks.5.attn.out_proj.bias": "model-00008-of-00010.safetensors",
801
+ "transformer.visual.transformer.resblocks.5.attn.out_proj.weight": "model-00008-of-00010.safetensors",
802
+ "transformer.visual.transformer.resblocks.5.ln_1.bias": "model-00008-of-00010.safetensors",
803
+ "transformer.visual.transformer.resblocks.5.ln_1.weight": "model-00008-of-00010.safetensors",
804
+ "transformer.visual.transformer.resblocks.5.ln_2.bias": "model-00008-of-00010.safetensors",
805
+ "transformer.visual.transformer.resblocks.5.ln_2.weight": "model-00008-of-00010.safetensors",
806
+ "transformer.visual.transformer.resblocks.5.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
807
+ "transformer.visual.transformer.resblocks.5.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
808
+ "transformer.visual.transformer.resblocks.5.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
809
+ "transformer.visual.transformer.resblocks.5.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
810
+ "transformer.visual.transformer.resblocks.6.attn.in_proj.bias": "model-00008-of-00010.safetensors",
811
+ "transformer.visual.transformer.resblocks.6.attn.in_proj.weight": "model-00008-of-00010.safetensors",
812
+ "transformer.visual.transformer.resblocks.6.attn.out_proj.bias": "model-00008-of-00010.safetensors",
813
+ "transformer.visual.transformer.resblocks.6.attn.out_proj.weight": "model-00008-of-00010.safetensors",
814
+ "transformer.visual.transformer.resblocks.6.ln_1.bias": "model-00008-of-00010.safetensors",
815
+ "transformer.visual.transformer.resblocks.6.ln_1.weight": "model-00008-of-00010.safetensors",
816
+ "transformer.visual.transformer.resblocks.6.ln_2.bias": "model-00008-of-00010.safetensors",
817
+ "transformer.visual.transformer.resblocks.6.ln_2.weight": "model-00008-of-00010.safetensors",
818
+ "transformer.visual.transformer.resblocks.6.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
819
+ "transformer.visual.transformer.resblocks.6.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
820
+ "transformer.visual.transformer.resblocks.6.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
821
+ "transformer.visual.transformer.resblocks.6.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
822
+ "transformer.visual.transformer.resblocks.7.attn.in_proj.bias": "model-00008-of-00010.safetensors",
823
+ "transformer.visual.transformer.resblocks.7.attn.in_proj.weight": "model-00008-of-00010.safetensors",
824
+ "transformer.visual.transformer.resblocks.7.attn.out_proj.bias": "model-00008-of-00010.safetensors",
825
+ "transformer.visual.transformer.resblocks.7.attn.out_proj.weight": "model-00008-of-00010.safetensors",
826
+ "transformer.visual.transformer.resblocks.7.ln_1.bias": "model-00008-of-00010.safetensors",
827
+ "transformer.visual.transformer.resblocks.7.ln_1.weight": "model-00008-of-00010.safetensors",
828
+ "transformer.visual.transformer.resblocks.7.ln_2.bias": "model-00008-of-00010.safetensors",
829
+ "transformer.visual.transformer.resblocks.7.ln_2.weight": "model-00008-of-00010.safetensors",
830
+ "transformer.visual.transformer.resblocks.7.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
831
+ "transformer.visual.transformer.resblocks.7.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
832
+ "transformer.visual.transformer.resblocks.7.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
833
+ "transformer.visual.transformer.resblocks.7.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
834
+ "transformer.visual.transformer.resblocks.8.attn.in_proj.bias": "model-00008-of-00010.safetensors",
835
+ "transformer.visual.transformer.resblocks.8.attn.in_proj.weight": "model-00008-of-00010.safetensors",
836
+ "transformer.visual.transformer.resblocks.8.attn.out_proj.bias": "model-00008-of-00010.safetensors",
837
+ "transformer.visual.transformer.resblocks.8.attn.out_proj.weight": "model-00008-of-00010.safetensors",
838
+ "transformer.visual.transformer.resblocks.8.ln_1.bias": "model-00008-of-00010.safetensors",
839
+ "transformer.visual.transformer.resblocks.8.ln_1.weight": "model-00008-of-00010.safetensors",
840
+ "transformer.visual.transformer.resblocks.8.ln_2.bias": "model-00008-of-00010.safetensors",
841
+ "transformer.visual.transformer.resblocks.8.ln_2.weight": "model-00008-of-00010.safetensors",
842
+ "transformer.visual.transformer.resblocks.8.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
843
+ "transformer.visual.transformer.resblocks.8.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
844
+ "transformer.visual.transformer.resblocks.8.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
845
+ "transformer.visual.transformer.resblocks.8.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
846
+ "transformer.visual.transformer.resblocks.9.attn.in_proj.bias": "model-00008-of-00010.safetensors",
847
+ "transformer.visual.transformer.resblocks.9.attn.in_proj.weight": "model-00008-of-00010.safetensors",
848
+ "transformer.visual.transformer.resblocks.9.attn.out_proj.bias": "model-00008-of-00010.safetensors",
849
+ "transformer.visual.transformer.resblocks.9.attn.out_proj.weight": "model-00008-of-00010.safetensors",
850
+ "transformer.visual.transformer.resblocks.9.ln_1.bias": "model-00008-of-00010.safetensors",
851
+ "transformer.visual.transformer.resblocks.9.ln_1.weight": "model-00008-of-00010.safetensors",
852
+ "transformer.visual.transformer.resblocks.9.ln_2.bias": "model-00008-of-00010.safetensors",
853
+ "transformer.visual.transformer.resblocks.9.ln_2.weight": "model-00008-of-00010.safetensors",
854
+ "transformer.visual.transformer.resblocks.9.mlp.c_fc.bias": "model-00008-of-00010.safetensors",
855
+ "transformer.visual.transformer.resblocks.9.mlp.c_fc.weight": "model-00008-of-00010.safetensors",
856
+ "transformer.visual.transformer.resblocks.9.mlp.c_proj.bias": "model-00008-of-00010.safetensors",
857
+ "transformer.visual.transformer.resblocks.9.mlp.c_proj.weight": "model-00008-of-00010.safetensors",
858
+ "transformer.wte.weight": "model-00001-of-00010.safetensors"
859
+ }
860
+ }
modeling_autogui.py ADDED
@@ -0,0 +1,1204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba Cloud.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ import importlib
7
+ import math
8
+ from typing import TYPE_CHECKING, Optional, Tuple, Union, Callable, List, Any, Generator
9
+ import re
10
+
11
+ import torch
12
+ import torch.nn.functional as F
13
+ import torch.utils.checkpoint
14
+ from torch.cuda.amp import autocast
15
+
16
+ from torch.nn import CrossEntropyLoss
17
+ from transformers import PreTrainedTokenizer, GenerationConfig, StoppingCriteriaList
18
+ from transformers.generation.logits_process import LogitsProcessorList
19
+
20
+ if TYPE_CHECKING:
21
+ from transformers.generation.streamers import BaseStreamer
22
+ from transformers.generation.utils import GenerateOutput
23
+ from transformers.modeling_outputs import (
24
+ BaseModelOutputWithPast,
25
+ CausalLMOutputWithPast,
26
+ )
27
+ from transformers.modeling_utils import PreTrainedModel
28
+ from transformers.utils import logging
29
+
30
+ try:
31
+ from einops import rearrange
32
+ except ImportError:
33
+ rearrange = None
34
+ from torch import nn
35
+
36
+ SUPPORT_CUDA = torch.cuda.is_available()
37
+ SUPPORT_BF16 = SUPPORT_CUDA and torch.cuda.is_bf16_supported()
38
+ SUPPORT_FP16 = SUPPORT_CUDA and torch.cuda.get_device_capability(0)[0] >= 7
39
+
40
+ from .configuration_qwen import QWenConfig
41
+ from .qwen_generation_utils import (
42
+ HistoryType,
43
+ make_context,
44
+ decode_tokens,
45
+ get_stop_words_ids,
46
+ StopWordsLogitsProcessor,
47
+ )
48
+ from .visual import VisionTransformer
49
+
50
+
51
+ logger = logging.get_logger(__name__)
52
+
53
+ _CHECKPOINT_FOR_DOC = "qwen"
54
+ _CONFIG_FOR_DOC = "QWenConfig"
55
+
56
+ QWen_PRETRAINED_MODEL_ARCHIVE_LIST = ["qwen-7b"]
57
+
58
+ _ERROR_BAD_CHAT_FORMAT = """\
59
+ We detect you are probably using the pretrained model (rather than chat model) for chatting, since the chat_format in generation_config is not "chatml".
60
+ If you are directly using the model downloaded from Huggingface, please make sure you are using our "Qwen/Qwen-7B-Chat" Huggingface model (rather than "Qwen/Qwen-7B") when you call model.chat().
61
+ 我们检测到您可能在使用预训练模型(而非chat模型)进行多轮chat,因为您当前在generation_config指定的chat_format,并未设置为我们在对话中所支持的"chatml"格式。
62
+ 如果您在直接使用我们从Huggingface提供的模型,请确保您在调用model.chat()时,使用的是"Qwen/Qwen-7B-Chat"模型(而非"Qwen/Qwen-7B"预训练模型)。
63
+ """
64
+
65
+ _SENTINEL = object()
66
+ _ERROR_STREAM_IN_CHAT = """\
67
+ Pass argument `stream` to model.chat() is buggy, deprecated, and marked for removal. Please use model.chat_stream(...) instead of model.chat(..., stream=True).
68
+ 向model.chat()传入参数stream的用法可能存在Bug,该用法已被废弃,将在未来被移除。请使用model.chat_stream(...)代替model.chat(..., stream=True)。
69
+ """
70
+
71
+ apply_rotary_emb_func = None
72
+ rms_norm = None
73
+
74
+
75
+ # Copied from transformers.models.bart.modeling_bart._make_causal_mask
76
+ def _make_causal_mask(
77
+ input_ids_shape: torch.Size, dtype: torch.dtype, device: torch.device, past_key_values_length: int = 0
78
+ ):
79
+ """
80
+ Make causal mask used for bi-directional self-attention.
81
+ """
82
+ bsz, tgt_len = input_ids_shape
83
+ mask = torch.full((tgt_len, tgt_len), torch.finfo(dtype).min, device=device)
84
+ mask_cond = torch.arange(mask.size(-1), device=device)
85
+ mask.masked_fill_(mask_cond < (mask_cond + 1).view(mask.size(-1), 1), 0)
86
+ mask = mask.to(dtype)
87
+
88
+ if past_key_values_length > 0:
89
+ mask = torch.cat([torch.zeros(tgt_len, past_key_values_length, dtype=dtype, device=device), mask], dim=-1)
90
+ return mask[None, None, :, :].expand(bsz, 1, tgt_len, tgt_len + past_key_values_length)
91
+
92
+
93
+ # Copied from transformers.models.bart.modeling_bart._expand_mask
94
+ def _expand_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int] = None):
95
+ """
96
+ Expands attention_mask from `[bsz, seq_len]` to `[bsz, 1, tgt_seq_len, src_seq_len]`.
97
+ """
98
+ bsz, src_len = mask.size()
99
+ tgt_len = tgt_len if tgt_len is not None else src_len
100
+
101
+ expanded_mask = mask[:, None, None, :].expand(bsz, 1, tgt_len, src_len).to(dtype)
102
+
103
+ inverted_mask = 1.0 - expanded_mask
104
+
105
+ return inverted_mask.masked_fill(inverted_mask.to(torch.bool), torch.finfo(dtype).min)
106
+
107
+
108
+ class QWenAttention(nn.Module):
109
+ def __init__(self, config):
110
+ super().__init__()
111
+
112
+ self.register_buffer("masked_bias", torch.tensor(-1e4), persistent=False)
113
+ self.seq_length = config.seq_length
114
+
115
+ self.hidden_size = config.hidden_size
116
+ self.split_size = config.hidden_size
117
+ self.num_heads = config.num_attention_heads
118
+ self.head_dim = self.hidden_size // self.num_heads
119
+
120
+ self.scale_attn_weights = True
121
+
122
+ self.projection_size = config.kv_channels * config.num_attention_heads
123
+
124
+ assert self.projection_size % config.num_attention_heads == 0
125
+ self.hidden_size_per_attention_head = (
126
+ self.projection_size // config.num_attention_heads
127
+ )
128
+
129
+ self.c_attn = nn.Linear(config.hidden_size, 3 * self.projection_size)
130
+
131
+ self.c_proj = nn.Linear(
132
+ config.hidden_size, self.projection_size, bias=not config.no_bias
133
+ )
134
+
135
+ self.is_fp32 = not (config.bf16 or config.fp16)
136
+ self.bf16 = config.bf16
137
+
138
+ self.use_dynamic_ntk = config.use_dynamic_ntk
139
+ self.use_logn_attn = config.use_logn_attn
140
+
141
+ logn_list = [
142
+ math.log(i, self.seq_length) if i > self.seq_length else 1
143
+ for i in range(1, 32768)
144
+ ]
145
+ self.logn_tensor = torch.tensor(logn_list)[None, :, None, None]
146
+
147
+ self.attn_dropout = nn.Dropout(config.attn_dropout_prob)
148
+
149
+ def _attn(self, query, key, value, registered_causal_mask, attention_mask=None, head_mask=None):
150
+ attn_weights = torch.matmul(query, key.transpose(-1, -2))
151
+
152
+ if self.scale_attn_weights:
153
+ attn_weights = attn_weights / torch.full(
154
+ [],
155
+ value.size(-1) ** 0.5,
156
+ dtype=attn_weights.dtype,
157
+ device=attn_weights.device,
158
+ )
159
+
160
+ query_length, key_length = query.size(-2), key.size(-2)
161
+ # causal_mask = self.bias[
162
+ # :, :, key_length - query_length : key_length, :key_length
163
+ # ]
164
+ # mask_value = torch.finfo(attn_weights.dtype).min
165
+ # mask_value = torch.full([], mask_value, dtype=attn_weights.dtype).to(
166
+ # attn_weights.device
167
+ # )
168
+ # attn_weights = torch.where(
169
+ # causal_mask, attn_weights.to(attn_weights.dtype), mask_value
170
+ # )
171
+ attn_weights = attn_weights + attention_mask
172
+
173
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1)
174
+
175
+ attn_weights = attn_weights.type(value.dtype)
176
+ attn_weights = self.attn_dropout(attn_weights)
177
+
178
+ if head_mask is not None:
179
+ attn_weights = attn_weights * head_mask
180
+
181
+ attn_output = torch.matmul(attn_weights, value)
182
+ attn_output = attn_output.transpose(1, 2)
183
+
184
+ return attn_output, attn_weights
185
+
186
+ def _upcast_and_reordered_attn(
187
+ self, query, key, value, registered_causal_mask, attention_mask=None, head_mask=None
188
+ ):
189
+ bsz, num_heads, q_seq_len, dk = query.size()
190
+ _, _, k_seq_len, _ = key.size()
191
+
192
+ attn_weights = torch.empty(
193
+ bsz * num_heads,
194
+ q_seq_len,
195
+ k_seq_len,
196
+ dtype=torch.float32,
197
+ device=query.device,
198
+ )
199
+
200
+ scale_factor = 1.0
201
+ if self.scale_attn_weights:
202
+ scale_factor /= float(value.size(-1)) ** 0.5
203
+
204
+ with autocast(enabled=False):
205
+ q, k = query.reshape(-1, q_seq_len, dk), key.transpose(-1, -2).reshape(
206
+ -1, dk, k_seq_len
207
+ )
208
+ attn_weights = torch.baddbmm(
209
+ attn_weights, q.float(), k.float(), beta=0, alpha=scale_factor
210
+ )
211
+ attn_weights = attn_weights.reshape(bsz, num_heads, q_seq_len, k_seq_len)
212
+
213
+ query_length, key_length = query.size(-2), key.size(-2)
214
+ causal_mask = registered_causal_mask[
215
+ :, :, key_length - query_length : key_length, :key_length
216
+ ]
217
+ mask_value = torch.finfo(attn_weights.dtype).min
218
+ mask_value = torch.tensor(mask_value, dtype=attn_weights.dtype).to(
219
+ attn_weights.device
220
+ )
221
+ attn_weights = torch.where(causal_mask, attn_weights, mask_value)
222
+
223
+ if attention_mask is not None:
224
+ attn_weights = attn_weights + attention_mask
225
+
226
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1)
227
+
228
+ if attn_weights.dtype != torch.float32:
229
+ raise RuntimeError(
230
+ "Error with upcasting, attn_weights does not have dtype torch.float32"
231
+ )
232
+ attn_weights = attn_weights.type(value.dtype)
233
+ attn_weights = self.attn_dropout(attn_weights)
234
+
235
+ if head_mask is not None:
236
+ attn_weights = attn_weights * head_mask
237
+
238
+ attn_output = torch.matmul(attn_weights, value)
239
+
240
+ return attn_output, attn_weights
241
+
242
+ def _split_heads(self, tensor, num_heads, attn_head_size):
243
+ new_shape = tensor.size()[:-1] + (num_heads, attn_head_size)
244
+ tensor = tensor.view(new_shape)
245
+ return tensor
246
+
247
+ def _merge_heads(self, tensor, num_heads, attn_head_size):
248
+ tensor = tensor.contiguous()
249
+ new_shape = tensor.size()[:-2] + (num_heads * attn_head_size,)
250
+ return tensor.view(new_shape)
251
+
252
+ def forward(
253
+ self,
254
+ hidden_states: Optional[Tuple[torch.FloatTensor]],
255
+ rotary_pos_emb: Optional[List[torch.Tensor]] = None,
256
+ registered_causal_mask: Optional[torch.Tensor] = None,
257
+ layer_past: Optional[Tuple[torch.Tensor]] = None,
258
+ attention_mask: Optional[torch.FloatTensor] = None,
259
+ head_mask: Optional[torch.FloatTensor] = None,
260
+ encoder_hidden_states: Optional[torch.Tensor] = None,
261
+ encoder_attention_mask: Optional[torch.FloatTensor] = None,
262
+ output_attentions: Optional[bool] = False,
263
+ use_cache: Optional[bool] = False,
264
+ ):
265
+
266
+ mixed_x_layer = self.c_attn(hidden_states)
267
+
268
+ query, key, value = mixed_x_layer.split(self.split_size, dim=2)
269
+
270
+ query = self._split_heads(query, self.num_heads, self.head_dim)
271
+ key = self._split_heads(key, self.num_heads, self.head_dim)
272
+ value = self._split_heads(value, self.num_heads, self.head_dim)
273
+
274
+ if rotary_pos_emb is not None:
275
+ cur_len = query.shape[1]
276
+ rotary_pos_emb = [i[:, -cur_len:, :, :] for i in rotary_pos_emb]
277
+ rotary_pos_emb = (rotary_pos_emb,) * 2
278
+ q_pos_emb, k_pos_emb = rotary_pos_emb
279
+ # Slice the pos emb for current inference
280
+ query = apply_rotary_pos_emb(query, q_pos_emb)
281
+ key = apply_rotary_pos_emb(key, k_pos_emb)
282
+
283
+ if layer_past is not None:
284
+ past_key, past_value = layer_past[0], layer_past[1]
285
+ key = torch.cat((past_key, key), dim=1)
286
+ value = torch.cat((past_value, value), dim=1)
287
+
288
+ if use_cache:
289
+ present = (key, value)
290
+ else:
291
+ present = None
292
+
293
+ if self.use_logn_attn and not self.training:
294
+ if self.logn_tensor.device != query.device or self.logn_tensor.dtype != query.dtype:
295
+ self.logn_tensor = self.logn_tensor.to(query.device).type_as(query)
296
+ seq_start = key.size(1) - query.size(1)
297
+ seq_end = key.size(1)
298
+ logn_tensor = self.logn_tensor[:, seq_start:seq_end, :, :]
299
+ query = query * logn_tensor.expand_as(query)
300
+
301
+ query = query.permute(0, 2, 1, 3)
302
+ key = key.permute(0, 2, 1, 3)
303
+ value = value.permute(0, 2, 1, 3)
304
+ attn_output, attn_weight = self._attn(
305
+ query, key, value, registered_causal_mask, attention_mask, head_mask
306
+ )
307
+ context_layer = self._merge_heads(
308
+ attn_output, self.num_heads, self.head_dim
309
+ )
310
+
311
+ attn_output = self.c_proj(context_layer)
312
+
313
+ outputs = (attn_output, present)
314
+ if output_attentions:
315
+ outputs += (attn_weight,)
316
+
317
+ return outputs
318
+
319
+
320
+ class QWenMLP(nn.Module):
321
+ def __init__(self, config):
322
+ super().__init__()
323
+ self.w1 = nn.Linear(
324
+ config.hidden_size, config.intermediate_size // 2, bias=not config.no_bias
325
+ )
326
+ self.w2 = nn.Linear(
327
+ config.hidden_size, config.intermediate_size // 2, bias=not config.no_bias
328
+ )
329
+ ff_dim_in = config.intermediate_size // 2
330
+ self.c_proj = nn.Linear(ff_dim_in, config.hidden_size, bias=not config.no_bias)
331
+
332
+ def forward(self, hidden_states):
333
+ a1 = self.w1(hidden_states)
334
+ a2 = self.w2(hidden_states)
335
+ intermediate_parallel = a1 * F.silu(a2)
336
+ output = self.c_proj(intermediate_parallel)
337
+ return output
338
+
339
+ class QWenBlock(nn.Module):
340
+ def __init__(self, config):
341
+ super().__init__()
342
+ hidden_size = config.hidden_size
343
+ self.bf16 = config.bf16
344
+
345
+ self.ln_1 = RMSNorm(
346
+ hidden_size,
347
+ eps=config.layer_norm_epsilon,
348
+ )
349
+ self.attn = QWenAttention(config)
350
+ self.ln_2 = RMSNorm(
351
+ hidden_size,
352
+ eps=config.layer_norm_epsilon,
353
+ )
354
+
355
+ self.mlp = QWenMLP(config)
356
+
357
+ def forward(
358
+ self,
359
+ hidden_states: Optional[Tuple[torch.FloatTensor]],
360
+ rotary_pos_emb: Optional[List[torch.Tensor]] = None,
361
+ registered_causal_mask: Optional[torch.Tensor] = None,
362
+ layer_past: Optional[Tuple[torch.Tensor]] = None,
363
+ attention_mask: Optional[torch.FloatTensor] = None,
364
+ head_mask: Optional[torch.FloatTensor] = None,
365
+ encoder_hidden_states: Optional[torch.Tensor] = None,
366
+ encoder_attention_mask: Optional[torch.FloatTensor] = None,
367
+ use_cache: Optional[bool] = False,
368
+ output_attentions: Optional[bool] = False,
369
+ ):
370
+ layernorm_output = self.ln_1(hidden_states)
371
+
372
+ attn_outputs = self.attn(
373
+ layernorm_output,
374
+ rotary_pos_emb,
375
+ registered_causal_mask=registered_causal_mask,
376
+ layer_past=layer_past,
377
+ attention_mask=attention_mask,
378
+ head_mask=head_mask,
379
+ use_cache=use_cache,
380
+ output_attentions=output_attentions,
381
+ )
382
+ attn_output = attn_outputs[0]
383
+
384
+ outputs = attn_outputs[1:]
385
+
386
+ residual = hidden_states
387
+ layernorm_input = attn_output + residual
388
+
389
+ layernorm_output = self.ln_2(layernorm_input)
390
+
391
+ residual = layernorm_input
392
+ mlp_output = self.mlp(layernorm_output)
393
+ hidden_states = residual + mlp_output
394
+
395
+ if use_cache:
396
+ outputs = (hidden_states,) + outputs
397
+ else:
398
+ outputs = (hidden_states,) + outputs[1:]
399
+
400
+ return outputs
401
+
402
+
403
+ class QWenPreTrainedModel(PreTrainedModel):
404
+ config_class = QWenConfig
405
+ base_model_prefix = "transformer"
406
+ is_parallelizable = False
407
+ supports_gradient_checkpointing = True
408
+ _no_split_modules = ["QWenBlock"]
409
+
410
+ def __init__(self, *inputs, **kwargs):
411
+ super().__init__(*inputs, **kwargs)
412
+
413
+ def _init_weights(self, module):
414
+ """Initialize the weights."""
415
+ if isinstance(module, nn.Linear):
416
+ module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
417
+ if module.bias is not None:
418
+ module.bias.data.zero_()
419
+ elif isinstance(module, nn.Embedding):
420
+ module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
421
+ if module.padding_idx is not None:
422
+ module.weight.data[module.padding_idx].zero_()
423
+ elif isinstance(module, RMSNorm):
424
+ module.weight.data.fill_(1.0)
425
+
426
+ for name, p in module.named_parameters():
427
+ if name == "c_proj.weight":
428
+ p.data.normal_(
429
+ mean=0.0,
430
+ std=(
431
+ self.config.initializer_range
432
+ / math.sqrt(2 * self.config.num_hidden_layers)
433
+ ),
434
+ )
435
+
436
+ def _set_gradient_checkpointing(self, module, value=False):
437
+ if isinstance(module, AutoGUIModel):
438
+ module.gradient_checkpointing = value
439
+
440
+
441
+ class AutoGUIModel(QWenPreTrainedModel):
442
+ _keys_to_ignore_on_load_missing = ["attn.masked_bias"]
443
+
444
+ def __init__(self, config):
445
+ super().__init__(config)
446
+ self.vocab_size = config.vocab_size
447
+ self.num_hidden_layers = config.num_hidden_layers
448
+ self.embed_dim = config.hidden_size
449
+
450
+ self.gradient_checkpointing = False
451
+ self.use_dynamic_ntk = config.use_dynamic_ntk
452
+ self.seq_length = config.seq_length
453
+
454
+ self.wte = nn.Embedding(self.vocab_size, self.embed_dim)
455
+
456
+ self.drop = nn.Dropout(config.emb_dropout_prob)
457
+
458
+ if config.rotary_pct == 1.0:
459
+ self.rotary_ndims = None
460
+ else:
461
+ assert config.rotary_pct < 1
462
+ self.rotary_ndims = int(
463
+ config.kv_channels * config.rotary_pct
464
+ )
465
+ dim = (
466
+ self.rotary_ndims
467
+ if self.rotary_ndims is not None
468
+ else config.kv_channels
469
+ )
470
+ self.rotary_emb = RotaryEmbedding(dim, base=config.rotary_emb_base)
471
+
472
+ self.use_flash_attn = config.use_flash_attn
473
+ self.is_fp32 = not (config.bf16 or config.fp16)
474
+ self.registered_causal_mask = None
475
+ # if (
476
+ # self.use_flash_attn
477
+ # and flash_attn_unpadded_func is not None
478
+ # and not self.is_fp32
479
+ # ):
480
+ # self.registered_causal_mask = None
481
+ # else:
482
+ # max_positions = config.max_position_embeddings
483
+ # self.register_buffer(
484
+ # "registered_causal_mask",
485
+ # torch.tril(
486
+ # torch.ones((max_positions, max_positions), dtype=torch.bool)
487
+ # ).view(1, 1, max_positions, max_positions),
488
+ # persistent=False,
489
+ # )
490
+
491
+ self.h = nn.ModuleList(
492
+ [
493
+ QWenBlock(
494
+ config
495
+ )
496
+ for i in range(config.num_hidden_layers)
497
+ ]
498
+ )
499
+ self.ln_f = RMSNorm(
500
+ self.embed_dim,
501
+ eps=config.layer_norm_epsilon,
502
+ )
503
+
504
+ self.visual = VisionTransformer(**config.visual)
505
+
506
+ self.post_init()
507
+
508
+ def get_input_embeddings(self):
509
+ return self.wte
510
+
511
+ def set_input_embeddings(self, new_embeddings):
512
+ self.wte = new_embeddings
513
+
514
+ # Copied from transformers.models.bart.modeling_bart.BartDecoder._prepare_decoder_attention_mask
515
+ def _prepare_decoder_attention_mask(self, attention_mask, input_shape, inputs_embeds, past_key_values_length):
516
+ # create causal mask
517
+ # [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
518
+ combined_attention_mask = None
519
+ if input_shape[-1] > 1:
520
+ combined_attention_mask = _make_causal_mask(
521
+ input_shape,
522
+ inputs_embeds.dtype,
523
+ device=inputs_embeds.device,
524
+ past_key_values_length=past_key_values_length,
525
+ )
526
+
527
+ if attention_mask is not None:
528
+ # [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
529
+ expanded_attn_mask = _expand_mask(attention_mask, inputs_embeds.dtype, tgt_len=input_shape[-1]).to(
530
+ inputs_embeds.device
531
+ )
532
+ combined_attention_mask = (
533
+ expanded_attn_mask if combined_attention_mask is None else expanded_attn_mask + combined_attention_mask
534
+ )
535
+
536
+ return combined_attention_mask
537
+
538
+
539
+ def forward(
540
+ self,
541
+ input_ids: Optional[torch.LongTensor] = None,
542
+ points: Optional[torch.LongTensor] = None,
543
+ past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
544
+ attention_mask: Optional[torch.FloatTensor] = None,
545
+ token_type_ids: Optional[torch.LongTensor] = None,
546
+ position_ids: Optional[torch.LongTensor] = None,
547
+ head_mask: Optional[torch.FloatTensor] = None,
548
+ inputs_embeds: Optional[torch.FloatTensor] = None,
549
+ encoder_hidden_states: Optional[torch.Tensor] = None,
550
+ encoder_attention_mask: Optional[torch.FloatTensor] = None,
551
+ use_cache: Optional[bool] = None,
552
+ output_attentions: Optional[bool] = None,
553
+ output_hidden_states: Optional[bool] = None,
554
+ return_dict: Optional[bool] = None,
555
+ ):
556
+ if past_key_values is None and torch.any(input_ids == self.config.visual['image_start_id']):
557
+ bos_pos = torch.where(input_ids == self.config.visual['image_start_id'])
558
+ eos_pos = torch.where(input_ids == self.config.visual['image_start_id'] + 1)
559
+ ref_pos = torch.where(input_ids == 151851) #CJF: 151851 denotes <ref> token, ref_pos[1] denotes the bs index, ref_pos[2] denotes the token position
560
+ assert (bos_pos[0] == eos_pos[0]).all()
561
+ img_pos = torch.stack((bos_pos[0], bos_pos[1], eos_pos[1]), dim=1)
562
+ ground_pos = torch.stack((ref_pos[0], ref_pos[1]), dim=1)
563
+ images = []
564
+ for i, a, b in img_pos:
565
+ image = input_ids[i][a + 1 : b - 1].tolist()
566
+ image = image[ : image.index(self.config.visual['image_start_id'] + 2)]
567
+ images.append(bytes(image).decode('utf-8'))
568
+ try:
569
+ images, points_feature = self.visual.encode(images, points)
570
+ except torch.cuda.OutOfMemoryError as e:
571
+ print(e)
572
+ print(f"images: {images}\npoints: {points}\nindex: {ref_pos}")
573
+ raise e
574
+ assert len(points_feature) if points_feature is not None else 0 == len(ground_pos)
575
+ assert images.shape[0] == len(images)
576
+ fake_images = None
577
+ elif self.training:
578
+ fake_images=torch.zeros(1,3,224,224).to(
579
+ dtype=self.visual.conv1.weight.dtype, device=self.visual.conv1.weight.device)
580
+ images = self.visual(fake_images)
581
+ else:
582
+ fake_images = None
583
+ images = None
584
+
585
+ output_attentions = (
586
+ output_attentions
587
+ if output_attentions is not None
588
+ else self.config.output_attentions
589
+ )
590
+ output_hidden_states = (
591
+ output_hidden_states
592
+ if output_hidden_states is not None
593
+ else self.config.output_hidden_states
594
+ )
595
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
596
+ return_dict = (
597
+ return_dict if return_dict is not None else self.config.use_return_dict
598
+ )
599
+
600
+ if input_ids is not None and inputs_embeds is not None:
601
+ raise ValueError(
602
+ "You cannot specify both input_ids and inputs_embeds at the same time"
603
+ )
604
+ elif input_ids is not None:
605
+ input_shape = input_ids.size()
606
+ input_ids = input_ids.view(-1, input_shape[-1])
607
+ batch_size = input_ids.shape[0]
608
+ elif inputs_embeds is not None:
609
+ input_shape = inputs_embeds.size()[:-1]
610
+ batch_size = inputs_embeds.shape[0]
611
+ else:
612
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
613
+
614
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
615
+
616
+ if token_type_ids is not None:
617
+ token_type_ids = token_type_ids.view(-1, input_shape[-1])
618
+ if position_ids is not None:
619
+ position_ids = position_ids.view(-1, input_shape[-1])
620
+
621
+ if past_key_values is None:
622
+ past_length = 0
623
+ past_key_values = tuple([None] * len(self.h))
624
+ else:
625
+ past_length = past_key_values[0][0].size(-2)
626
+
627
+ if position_ids is None:
628
+ position_ids = torch.arange(
629
+ past_length,
630
+ input_shape[-1] + past_length,
631
+ dtype=torch.long,
632
+ device=device,
633
+ )
634
+ position_ids = position_ids.unsqueeze(0).view(-1, input_shape[-1])
635
+
636
+ encoder_attention_mask = None
637
+ head_mask = self.get_head_mask(head_mask, self.config.num_hidden_layers)
638
+
639
+ if inputs_embeds is None:
640
+ inputs_embeds = self.wte(input_ids)
641
+
642
+ if batch_size <= 0:
643
+ raise ValueError("batch_size has to be defined and > 0")
644
+ attention_mask = self._prepare_decoder_attention_mask(
645
+ attention_mask, input_shape, inputs_embeds, past_length
646
+ )
647
+
648
+ hidden_states = inputs_embeds
649
+
650
+ kv_seq_len = hidden_states.size()[1]
651
+ if past_key_values[0] is not None:
652
+ # past key values[0][0] shape: bs * seq_len * head_num * dim
653
+ kv_seq_len += past_key_values[0][0].shape[1]
654
+ if (
655
+ self.use_dynamic_ntk
656
+ and kv_seq_len == hidden_states.size()[1]
657
+ and not self.training
658
+ ):
659
+ context_value = math.log(kv_seq_len / self.seq_length, 2) + 1
660
+ ntk_alpha = 2 ** math.ceil(context_value) - 1
661
+ ntk_alpha = max(ntk_alpha, 1)
662
+ else:
663
+ ntk_alpha = self.rotary_emb._ntk_alpha_cached
664
+
665
+ rotary_pos_emb = self.rotary_emb(kv_seq_len, ntk_alpha=ntk_alpha)
666
+ for idx in range(len(rotary_pos_emb)):
667
+ rotary_pos_emb[idx] = rotary_pos_emb[idx].to(hidden_states.device)
668
+
669
+ hidden_states = self.drop(hidden_states).clone()
670
+ if fake_images is not None:
671
+ hidden_states = hidden_states + images.mean()*0
672
+ elif images is not None:
673
+ for idx, (i, a, b) in enumerate(img_pos):
674
+ hidden_states[i][a + 1 : b] = images[idx]
675
+ for idx, (i, a) in enumerate(ground_pos):
676
+ assert input_ids[i][a] == 151851 #CJF: must be <ref> 151851
677
+ # assert input_ids[i][a+256] == 151859 #CJF: double check <imgpad>, see tokenization_qwen.py
678
+ # assert input_ids[i][a+256+1] != 151859 #CJF: double check not <image_pad>, see tokenization_qwen.py
679
+ assert input_ids[i][a+1] != 151859 #CJF: double check not <ref>, see tokenization_qwen.py
680
+ # hidden_states[i][a+1:a+256+1] = points_feature[idx]
681
+ hidden_states[i][a:a+1] = points_feature[idx]
682
+ output_shape = input_shape + (hidden_states.size(-1),)
683
+
684
+ if self.gradient_checkpointing and self.training:
685
+ if use_cache:
686
+ logger.warning_once(
687
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
688
+ )
689
+ use_cache = False
690
+
691
+ presents = () if use_cache else None
692
+ all_self_attentions = () if output_attentions else None
693
+ all_hidden_states = () if output_hidden_states else None
694
+ for i, (block, layer_past) in enumerate(zip(self.h, past_key_values)):
695
+
696
+ if output_hidden_states:
697
+ all_hidden_states = all_hidden_states + (hidden_states,)
698
+
699
+ if self.gradient_checkpointing and self.training:
700
+
701
+ def create_custom_forward(module):
702
+ def custom_forward(*inputs):
703
+ # None for past_key_value
704
+ return module(*inputs, use_cache, output_attentions)
705
+
706
+ return custom_forward
707
+
708
+ outputs = torch.utils.checkpoint.checkpoint(
709
+ create_custom_forward(block),
710
+ hidden_states,
711
+ rotary_pos_emb,
712
+ self.registered_causal_mask,
713
+ None,
714
+ attention_mask,
715
+ head_mask[i],
716
+ encoder_hidden_states,
717
+ encoder_attention_mask,
718
+ )
719
+ else:
720
+ outputs = block(
721
+ hidden_states,
722
+ layer_past=layer_past,
723
+ rotary_pos_emb=rotary_pos_emb,
724
+ registered_causal_mask=self.registered_causal_mask,
725
+ attention_mask=attention_mask,
726
+ head_mask=head_mask[i],
727
+ encoder_hidden_states=encoder_hidden_states,
728
+ encoder_attention_mask=encoder_attention_mask,
729
+ use_cache=use_cache,
730
+ output_attentions=output_attentions,
731
+ )
732
+
733
+ hidden_states = outputs[0]
734
+ if use_cache is True:
735
+ presents = presents + (outputs[1],)
736
+
737
+ if output_attentions:
738
+ all_self_attentions = all_self_attentions + (outputs[2 if use_cache else 1],)
739
+
740
+ hidden_states = self.ln_f(hidden_states)
741
+ hidden_states = hidden_states.view(output_shape)
742
+ # Add last hidden state
743
+ if output_hidden_states:
744
+ all_hidden_states = all_hidden_states + (hidden_states,)
745
+
746
+ if not return_dict:
747
+ return tuple(
748
+ v for v in [hidden_states, presents, all_hidden_states] if v is not None
749
+ )
750
+
751
+ return BaseModelOutputWithPast(
752
+ last_hidden_state=hidden_states,
753
+ past_key_values=presents,
754
+ hidden_states=all_hidden_states,
755
+ attentions=all_self_attentions,
756
+ )
757
+
758
+
759
+ class AutoGUILMHeadModel(QWenPreTrainedModel):
760
+ _keys_to_ignore_on_load_missing = [r"h\.\d+\.attn\.rotary_emb\.inv_freq"]
761
+ _keys_to_ignore_on_load_unexpected = [r"h\.\d+\.attn\.masked_bias"]
762
+
763
+ def __init__(self, config):
764
+ super().__init__(config)
765
+ assert (
766
+ config.bf16 + config.fp16 + config.fp32 <= 1
767
+ ), "Only one of \"bf16\", \"fp16\", \"fp32\" can be true"
768
+
769
+ autoset_precision = config.bf16 + config.fp16 + config.fp32 == 0
770
+
771
+ if autoset_precision:
772
+ if SUPPORT_BF16:
773
+ logger.warn(
774
+ "The model is automatically converting to bf16 for faster inference. "
775
+ "If you want to disable the automatic precision, please manually add bf16/fp16/fp32=True to \"AutoModelForCausalLM.from_pretrained\"."
776
+ )
777
+ config.bf16 = True
778
+ elif SUPPORT_FP16:
779
+ logger.warn(
780
+ "The model is automatically converting to fp16 for faster inference. "
781
+ "If you want to disable the automatic precision, please manually add bf16/fp16/fp32=True to \"AutoModelForCausalLM.from_pretrained\"."
782
+ )
783
+ config.fp16 = True
784
+ else:
785
+ config.fp32 = True
786
+
787
+ if config.bf16 and SUPPORT_CUDA and not SUPPORT_BF16:
788
+ logger.warn("Your device does NOT seem to support bf16, you can switch to fp16 or fp32 by by passing fp16/fp32=True in \"AutoModelForCausalLM.from_pretrained\".")
789
+ if config.fp16 and SUPPORT_CUDA and not SUPPORT_FP16:
790
+ logger.warn("Your device does NOT support faster inference with fp16, please switch to fp32 which is likely to be faster")
791
+ if config.fp32:
792
+ if SUPPORT_BF16:
793
+ logger.warn("Your device support faster inference by passing bf16=True in \"AutoModelForCausalLM.from_pretrained\".")
794
+ elif SUPPORT_FP16:
795
+ logger.warn("Your device support faster inference by passing fp16=True in \"AutoModelForCausalLM.from_pretrained\".")
796
+
797
+ self.transformer = AutoGUIModel(config)
798
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
799
+
800
+ if config.bf16:
801
+ self.transformer.bfloat16()
802
+ self.lm_head.bfloat16()
803
+ if config.fp16:
804
+ self.transformer.half()
805
+ self.lm_head.half()
806
+ self.post_init()
807
+
808
+ def get_output_embeddings(self):
809
+ return self.lm_head
810
+
811
+ def set_output_embeddings(self, new_embeddings):
812
+ self.lm_head = new_embeddings
813
+
814
+ def prepare_inputs_for_generation(
815
+ self, input_ids, past_key_values=None, inputs_embeds=None, **kwargs
816
+ ):
817
+ token_type_ids = kwargs.get("token_type_ids", None)
818
+ if past_key_values:
819
+ input_ids = input_ids[:, -1].unsqueeze(-1)
820
+ if token_type_ids is not None:
821
+ token_type_ids = token_type_ids[:, -1].unsqueeze(-1)
822
+
823
+ attention_mask = kwargs.get("attention_mask", None)
824
+ position_ids = kwargs.get("position_ids", None)
825
+
826
+ if attention_mask is not None and position_ids is None:
827
+ position_ids = attention_mask.long().cumsum(-1) - 1
828
+ position_ids.masked_fill_(attention_mask == 0, 1)
829
+ if past_key_values:
830
+ position_ids = position_ids[:, -1].unsqueeze(-1)
831
+ else:
832
+ position_ids = None
833
+
834
+ if inputs_embeds is not None and past_key_values is None:
835
+ model_inputs = {"inputs_embeds": inputs_embeds}
836
+ else:
837
+ model_inputs = {"input_ids": input_ids}
838
+
839
+ model_inputs.update(
840
+ {
841
+ "past_key_values": past_key_values,
842
+ "use_cache": kwargs.get("use_cache"),
843
+ "position_ids": position_ids,
844
+ "attention_mask": attention_mask,
845
+ "token_type_ids": token_type_ids,
846
+ }
847
+ )
848
+ if 'points' in kwargs:
849
+ model_inputs.update({"points": kwargs.get("points")})
850
+ return model_inputs
851
+
852
+ def forward(
853
+ self,
854
+ input_ids: Optional[torch.LongTensor] = None,
855
+ points: Optional[torch.LongTensor] = None, #CJF
856
+ past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
857
+ attention_mask: Optional[torch.FloatTensor] = None,
858
+ token_type_ids: Optional[torch.LongTensor] = None,
859
+ position_ids: Optional[torch.LongTensor] = None,
860
+ head_mask: Optional[torch.FloatTensor] = None,
861
+ inputs_embeds: Optional[torch.FloatTensor] = None,
862
+ encoder_hidden_states: Optional[torch.Tensor] = None,
863
+ encoder_attention_mask: Optional[torch.FloatTensor] = None,
864
+ labels: Optional[torch.LongTensor] = None,
865
+ use_cache: Optional[bool] = None,
866
+ output_attentions: Optional[bool] = None,
867
+ output_hidden_states: Optional[bool] = None,
868
+ return_dict: Optional[bool] = None,
869
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
870
+
871
+ return_dict = (
872
+ return_dict if return_dict is not None else self.config.use_return_dict
873
+ )
874
+
875
+ transformer_outputs = self.transformer(
876
+ input_ids,
877
+ points,
878
+ past_key_values=past_key_values,
879
+ attention_mask=attention_mask,
880
+ token_type_ids=token_type_ids,
881
+ position_ids=position_ids,
882
+ head_mask=head_mask,
883
+ inputs_embeds=inputs_embeds,
884
+ encoder_hidden_states=encoder_hidden_states,
885
+ encoder_attention_mask=encoder_attention_mask,
886
+ use_cache=use_cache,
887
+ output_attentions=output_attentions,
888
+ output_hidden_states=output_hidden_states,
889
+ return_dict=return_dict,
890
+ )
891
+ hidden_states = transformer_outputs[0]
892
+
893
+ lm_logits = self.lm_head(hidden_states)
894
+
895
+ loss = None
896
+ if labels is not None:
897
+ labels = labels.to(lm_logits.device)
898
+ shift_logits = lm_logits[..., :-1, :].contiguous()
899
+ shift_labels = labels[..., 1:].contiguous()
900
+ loss_fct = CrossEntropyLoss()
901
+ loss = loss_fct(
902
+ shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1)
903
+ )
904
+
905
+ if not return_dict:
906
+ output = (lm_logits,) + transformer_outputs[1:]
907
+ return ((loss,) + output) if loss is not None else output
908
+
909
+ return CausalLMOutputWithPast(
910
+ loss=loss,
911
+ logits=lm_logits,
912
+ past_key_values=transformer_outputs.past_key_values,
913
+ hidden_states=transformer_outputs.hidden_states,
914
+ attentions=transformer_outputs.attentions,
915
+ )
916
+
917
+ @staticmethod
918
+ def _reorder_cache(
919
+ past_key_values: Tuple[Tuple[torch.Tensor]], beam_idx: torch.Tensor
920
+ ) -> Tuple[Tuple[torch.Tensor]]:
921
+
922
+ return tuple(
923
+ tuple(
924
+ past_state.index_select(0, beam_idx.to(past_state.device))
925
+ for past_state in layer_past
926
+ )
927
+ for layer_past in past_key_values
928
+ )
929
+
930
+ def get_point(self, tokenizer, sentence):
931
+ #This function is used to extract the points from the sentence, and get the '<ref>' position in the tokenzied_ids of sentence.
932
+ points, index = [], []
933
+ # sentence = sentence.replace('<point>', TAG_MAP['<point>'])#.replace('<bbox>', TAG_MAP['<bbox>'])
934
+ tokenized_id = tokenizer(sentence).input_ids
935
+ point_id = tokenizer('<ref>').input_ids
936
+ # box_id = tokenizer(TAG_MAP['<bbox>']).input_ids
937
+ for x, y in re.findall(r"\((\d+),(\d+)\)", sentence):
938
+ points.append([int(x), int(y)])
939
+ if len(points) == 0:
940
+ points.append([-100, -100])
941
+ index = [i for i, token in enumerate(tokenized_id) if token == point_id[0]]
942
+ # index_box = [i for i, token in enumerate(tokenized_id) if token == box_id[0]]
943
+
944
+ return points, index
945
+
946
+ def chat(
947
+ self,
948
+ tokenizer: PreTrainedTokenizer,
949
+ query: str,
950
+ history: Optional[HistoryType],
951
+ system: str = "You are a helpful assistant.",
952
+ append_history: bool = True,
953
+ stream: Optional[bool] = _SENTINEL,
954
+ stop_words_ids: Optional[List[List[int]]] = None,
955
+ generation_config: Optional[GenerationConfig] = None,
956
+ **kwargs,
957
+ ) -> Tuple[str, HistoryType]:
958
+ generation_config = generation_config if generation_config is not None else self.generation_config
959
+
960
+ assert stream is _SENTINEL, _ERROR_STREAM_IN_CHAT
961
+ assert generation_config.chat_format == 'chatml', _ERROR_BAD_CHAT_FORMAT
962
+ if history is None:
963
+ history = []
964
+ if stop_words_ids is None:
965
+ stop_words_ids = []
966
+
967
+ max_window_size = kwargs.get('max_window_size', None)
968
+ if max_window_size is None:
969
+ max_window_size = generation_config.max_window_size
970
+ raw_text, context_tokens = make_context(
971
+ tokenizer,
972
+ query,
973
+ history=history,
974
+ system=system,
975
+ max_window_size=max_window_size,
976
+ chat_format=generation_config.chat_format,
977
+ )
978
+
979
+ stop_words_ids.extend(get_stop_words_ids(
980
+ generation_config.chat_format, tokenizer
981
+ ))
982
+ input_ids = torch.tensor([context_tokens]).to(self.device)
983
+ bs = input_ids.size(0)
984
+ if '<ref>' in query:
985
+ points, _ = self.get_point(tokenizer, query)
986
+ points = torch.tensor(points).unsqueeze(0).repeat(bs, 1, 1).to(self.device)
987
+ else:
988
+ points = -100 * torch.ones([bs,1,2]).to(self.device)
989
+ kwargs['points'] = points
990
+ outputs = self.generate(
991
+ input_ids,
992
+ stop_words_ids=stop_words_ids,
993
+ return_dict_in_generate=False,
994
+ generation_config=generation_config,
995
+ **kwargs,
996
+ )
997
+
998
+ response = decode_tokens(
999
+ outputs[0],
1000
+ tokenizer,
1001
+ raw_text_len=len(raw_text),
1002
+ context_length=len(context_tokens),
1003
+ chat_format=generation_config.chat_format,
1004
+ verbose=False,
1005
+ errors='replace'
1006
+ )
1007
+
1008
+ if append_history:
1009
+ history.append((query, response))
1010
+
1011
+ return response, history
1012
+
1013
+ def chat_stream(
1014
+ self,
1015
+ tokenizer: PreTrainedTokenizer,
1016
+ query: str,
1017
+ history: Optional[HistoryType],
1018
+ system: str = "You are a helpful assistant.",
1019
+ stop_words_ids: Optional[List[List[int]]] = None,
1020
+ logits_processor: Optional[LogitsProcessorList] = None,
1021
+ generation_config: Optional[GenerationConfig] = None,
1022
+ **kwargs,
1023
+ ) -> Generator[str, Any, None]:
1024
+ generation_config = generation_config if generation_config is not None else self.generation_config
1025
+ assert generation_config.chat_format == 'chatml', _ERROR_BAD_CHAT_FORMAT
1026
+ if history is None:
1027
+ history = []
1028
+ if stop_words_ids is None:
1029
+ stop_words_ids = []
1030
+
1031
+ max_window_size = kwargs.get('max_window_size', None)
1032
+ if max_window_size is None:
1033
+ max_window_size = generation_config.max_window_size
1034
+ raw_text, context_tokens = make_context(
1035
+ tokenizer,
1036
+ query,
1037
+ history=history,
1038
+ system=system,
1039
+ max_window_size=max_window_size,
1040
+ chat_format=generation_config.chat_format,
1041
+ )
1042
+
1043
+ stop_words_ids.extend(get_stop_words_ids(
1044
+ generation_config.chat_format, tokenizer
1045
+ ))
1046
+ if stop_words_ids is not None:
1047
+ stop_words_logits_processor = StopWordsLogitsProcessor(
1048
+ stop_words_ids=stop_words_ids,
1049
+ eos_token_id=generation_config.eos_token_id,
1050
+ )
1051
+ if logits_processor is None:
1052
+ logits_processor = LogitsProcessorList([stop_words_logits_processor])
1053
+ else:
1054
+ logits_processor.append(stop_words_logits_processor)
1055
+ input_ids = torch.tensor([context_tokens]).to(self.device)
1056
+
1057
+ from transformers_stream_generator.main import NewGenerationMixin, StreamGenerationConfig
1058
+ self.__class__.generate_stream = NewGenerationMixin.generate
1059
+ self.__class__.sample_stream = NewGenerationMixin.sample_stream
1060
+ stream_config = StreamGenerationConfig(**generation_config.to_dict(), do_stream=True)
1061
+
1062
+ def stream_generator():
1063
+ outputs = []
1064
+ for token in self.generate_stream(
1065
+ input_ids,
1066
+ return_dict_in_generate=False,
1067
+ generation_config=stream_config,
1068
+ logits_processor=logits_processor,
1069
+ seed=-1,
1070
+ **kwargs):
1071
+ outputs.append(token.item())
1072
+ yield tokenizer.decode(outputs, skip_special_tokens=True, errors='ignore', keep_image_special=True)
1073
+
1074
+ return stream_generator()
1075
+
1076
+ def generate(
1077
+ self,
1078
+ inputs: Optional[torch.Tensor] = None,
1079
+ generation_config: Optional[GenerationConfig] = None,
1080
+ logits_processor: Optional[LogitsProcessorList] = None,
1081
+ stopping_criteria: Optional[StoppingCriteriaList] = None,
1082
+ prefix_allowed_tokens_fn: Optional[
1083
+ Callable[[int, torch.Tensor], List[int]]
1084
+ ] = None,
1085
+ synced_gpus: Optional[bool] = None,
1086
+ assistant_model: Optional["PreTrainedModel"] = None,
1087
+ streamer: Optional["BaseStreamer"] = None,
1088
+ **kwargs,
1089
+ ) -> Union[GenerateOutput, torch.LongTensor]:
1090
+ generation_config = generation_config if generation_config is not None else self.generation_config
1091
+
1092
+ # Process stop_words_ids.
1093
+ stop_words_ids = kwargs.pop("stop_words_ids", None)
1094
+ if stop_words_ids is None and generation_config is not None:
1095
+ stop_words_ids = getattr(generation_config, "stop_words_ids", None)
1096
+ if stop_words_ids is None:
1097
+ stop_words_ids = getattr(generation_config, "stop_words_ids", None)
1098
+
1099
+ if stop_words_ids is not None:
1100
+ stop_words_logits_processor = StopWordsLogitsProcessor(
1101
+ stop_words_ids=stop_words_ids,
1102
+ eos_token_id=generation_config.eos_token_id,
1103
+ )
1104
+ if logits_processor is None:
1105
+ logits_processor = LogitsProcessorList([stop_words_logits_processor])
1106
+ else:
1107
+ logits_processor.append(stop_words_logits_processor)
1108
+ return super().generate(
1109
+ inputs,
1110
+ generation_config=generation_config,
1111
+ logits_processor=logits_processor,
1112
+ stopping_criteria=stopping_criteria,
1113
+ prefix_allowed_tokens_fn=prefix_allowed_tokens_fn,
1114
+ synced_gpus=synced_gpus,
1115
+ assistant_model=assistant_model,
1116
+ streamer=streamer,
1117
+ **kwargs,
1118
+ )
1119
+
1120
+
1121
+ class RotaryEmbedding(torch.nn.Module):
1122
+ def __init__(self, dim, base=10000):
1123
+ super().__init__()
1124
+ self.dim = dim
1125
+ self.base = base
1126
+ self.inv_freq = 1.0 / (base ** (torch.arange(0, dim, 2).float() / dim))
1127
+ if importlib.util.find_spec("einops") is None:
1128
+ raise RuntimeError("einops is required for Rotary Embedding")
1129
+
1130
+ self._rotary_pos_emb_cache = None
1131
+ self._seq_len_cached = 0
1132
+ self._ntk_alpha_cached = 1.0
1133
+
1134
+ def update_rotary_pos_emb_cache(self, max_seq_len, offset=0, ntk_alpha=1.0):
1135
+ seqlen = max_seq_len + offset
1136
+ if seqlen > self._seq_len_cached or ntk_alpha != self._ntk_alpha_cached:
1137
+ base = self.base * ntk_alpha ** (self.dim / (self.dim - 2))
1138
+ self.inv_freq = 1.0 / (
1139
+ base
1140
+ ** (
1141
+ torch.arange(0, self.dim, 2, device=self.inv_freq.device).float()
1142
+ / self.dim
1143
+ )
1144
+ )
1145
+ self._seq_len_cached = max(2 * seqlen, 16)
1146
+ self._ntk_alpha_cached = ntk_alpha
1147
+ seq = torch.arange(self._seq_len_cached, device=self.inv_freq.device)
1148
+ freqs = torch.outer(seq.type_as(self.inv_freq), self.inv_freq)
1149
+
1150
+ emb = torch.cat((freqs, freqs), dim=-1)
1151
+ from einops import rearrange
1152
+
1153
+ emb = rearrange(emb, "n d -> 1 n 1 d")
1154
+
1155
+ cos, sin = emb.cos(), emb.sin()
1156
+ self._rotary_pos_emb_cache = [cos, sin]
1157
+
1158
+ def forward(self, max_seq_len, offset=0, ntk_alpha=1.0):
1159
+ self.update_rotary_pos_emb_cache(max_seq_len, offset, ntk_alpha)
1160
+ cos, sin = self._rotary_pos_emb_cache
1161
+ return [cos[:, offset : offset + max_seq_len], sin[:, offset : offset + max_seq_len]]
1162
+
1163
+
1164
+ def _rotate_half(x):
1165
+ from einops import rearrange
1166
+
1167
+ x = rearrange(x, "... (j d) -> ... j d", j=2)
1168
+ x1, x2 = x.unbind(dim=-2)
1169
+ return torch.cat((-x2, x1), dim=-1)
1170
+
1171
+
1172
+ def apply_rotary_pos_emb(t, freqs):
1173
+ cos, sin = freqs
1174
+ if apply_rotary_emb_func is not None and t.is_cuda:
1175
+ t_ = t.float()
1176
+ cos = cos.squeeze(0).squeeze(1)[:, : cos.shape[-1] // 2]
1177
+ sin = sin.squeeze(0).squeeze(1)[:, : sin.shape[-1] // 2]
1178
+ output = apply_rotary_emb_func(t_, cos, sin).type_as(t)
1179
+ return output
1180
+ else:
1181
+ rot_dim = freqs[0].shape[-1]
1182
+ cos, sin = freqs
1183
+ t_, t_pass_ = t[..., :rot_dim], t[..., rot_dim:]
1184
+ t_ = t_.float()
1185
+ t_pass_ = t_pass_.float()
1186
+ t_ = (t_ * cos) + (_rotate_half(t_) * sin)
1187
+ return torch.cat((t_, t_pass_), dim=-1).type_as(t)
1188
+
1189
+
1190
+ class RMSNorm(torch.nn.Module):
1191
+ def __init__(self, dim: int, eps: float = 1e-6):
1192
+ super().__init__()
1193
+ self.eps = eps
1194
+ self.weight = nn.Parameter(torch.ones(dim))
1195
+
1196
+ def _norm(self, x):
1197
+ return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)
1198
+
1199
+ def forward(self, x):
1200
+ if rms_norm is not None and x.is_cuda:
1201
+ return rms_norm(x, self.weight, self.eps)
1202
+ else:
1203
+ output = self._norm(x.float()).type_as(x)
1204
+ return output * self.weight
qwen_generation_utils.py ADDED
@@ -0,0 +1,424 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba Cloud.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ """Generation support."""
7
+
8
+ from typing import Tuple, List, Union, Iterable
9
+
10
+ import numpy as np
11
+ import torch
12
+ import torch.nn.functional as F
13
+ from transformers import PreTrainedTokenizer
14
+ from transformers import logging
15
+ from transformers.generation import LogitsProcessor
16
+
17
+ logger = logging.get_logger(__name__)
18
+
19
+ # Types.
20
+ HistoryType = List[Tuple[str, str]]
21
+ TokensType = List[int]
22
+ BatchTokensType = List[List[int]]
23
+
24
+
25
+ def pad_batch(batch: BatchTokensType, pad_id: int, seq_length: int) -> BatchTokensType:
26
+ for tokens in batch:
27
+ context_length = len(tokens)
28
+ if context_length < seq_length:
29
+ tokens.extend([pad_id] * (seq_length - context_length))
30
+ return batch
31
+
32
+
33
+ def get_ltor_masks_and_position_ids(
34
+ data,
35
+ eod_token,
36
+ reset_position_ids,
37
+ reset_attention_mask,
38
+ eod_mask_loss,
39
+ ):
40
+ """Build masks and position id for left to right model."""
41
+
42
+ # Extract batch size and sequence length.
43
+ micro_batch_size, seq_length = data.size()
44
+
45
+ # Attention mask (lower triangular).
46
+ if reset_attention_mask:
47
+ att_mask_batch = micro_batch_size
48
+ else:
49
+ att_mask_batch = 1
50
+ attention_mask = torch.tril(
51
+ torch.ones((att_mask_batch, seq_length, seq_length), device=data.device)
52
+ ).view(att_mask_batch, 1, seq_length, seq_length)
53
+
54
+ # Loss mask.
55
+ loss_mask = torch.ones(data.size(), dtype=torch.float, device=data.device)
56
+ if eod_mask_loss:
57
+ loss_mask[data == eod_token] = 0.0
58
+
59
+ # Position ids.
60
+ position_ids = torch.arange(seq_length, dtype=torch.long, device=data.device)
61
+ position_ids = position_ids.unsqueeze(0).expand_as(data)
62
+ # We need to clone as the ids will be modifed based on batch index.
63
+ if reset_position_ids:
64
+ position_ids = position_ids.clone()
65
+
66
+ if reset_position_ids or reset_attention_mask:
67
+ # Loop through the batches:
68
+ for b in range(micro_batch_size):
69
+
70
+ # Find indecies where EOD token is.
71
+ eod_index = position_ids[b, data[b] == eod_token]
72
+ # Detach indecies from positions if going to modify positions.
73
+ if reset_position_ids:
74
+ eod_index = eod_index.clone()
75
+
76
+ # Loop through EOD indecies:
77
+ prev_index = 0
78
+ for j in range(eod_index.size()[0]):
79
+ i = eod_index[j]
80
+ # Mask attention loss.
81
+ if reset_attention_mask:
82
+ attention_mask[b, 0, (i + 1) :, : (i + 1)] = 0
83
+ # Reset positions.
84
+ if reset_position_ids:
85
+ position_ids[b, (i + 1) :] -= i + 1 - prev_index
86
+ prev_index = i + 1
87
+
88
+ # Convert attention mask to binary:
89
+ attention_mask = attention_mask < 0.5
90
+
91
+ return attention_mask, loss_mask, position_ids
92
+
93
+
94
+ def get_batch(context_tokens: torch.LongTensor, eod_id: int):
95
+ """Generate batch from context tokens."""
96
+ # Move to GPU.
97
+ tokens = context_tokens.contiguous().to(context_tokens.device)
98
+ # Get the attention mask and postition ids.
99
+ attention_mask, _, position_ids = get_ltor_masks_and_position_ids(
100
+ tokens,
101
+ eod_id,
102
+ reset_position_ids=False,
103
+ reset_attention_mask=False,
104
+ eod_mask_loss=False,
105
+ )
106
+ return tokens, attention_mask, position_ids
107
+
108
+
109
+ def get_stop_words_ids(chat_format, tokenizer):
110
+ if chat_format == "raw":
111
+ stop_words_ids = [tokenizer.encode("Human:"), [tokenizer.eod_id]]
112
+ elif chat_format == "chatml":
113
+ stop_words_ids = [[tokenizer.im_end_id], [tokenizer.im_start_id]]
114
+ else:
115
+ raise NotImplementedError(f"Unknown chat format {chat_format!r}")
116
+ return stop_words_ids
117
+
118
+
119
+ def make_context(
120
+ tokenizer: PreTrainedTokenizer,
121
+ query: str,
122
+ history: List[Tuple[str, str]] = None,
123
+ system: str = "",
124
+ max_window_size: int = 6144,
125
+ chat_format: str = "chatml",
126
+ ):
127
+ if history is None:
128
+ history = []
129
+
130
+ if chat_format == "chatml":
131
+ im_start, im_end = "<|im_start|>", "<|im_end|>"
132
+ im_start_tokens = [tokenizer.im_start_id]
133
+ im_end_tokens = [tokenizer.im_end_id]
134
+ nl_tokens = tokenizer.encode("\n")
135
+
136
+ def _tokenize_str(role, content):
137
+ inputs_id = tokenizer.encode(
138
+ role, allowed_special=set(tokenizer.IMAGE_ST)
139
+ ) + nl_tokens + tokenizer.encode(content, allowed_special=set(tokenizer.IMAGE_ST))
140
+ if 151851 in inputs_id:
141
+ # insert 256 tokens after the index of 151851
142
+ inputs_id = inputs_id[:inputs_id.index(151851)+1] + inputs_id[inputs_id.index(151851)+1:] # + [tokenizer('<imgpad>').input_ids[0]] * 256
143
+ return f"{role}\n{content}", inputs_id
144
+
145
+ system_text, system_tokens_part = _tokenize_str("system", system)
146
+ system_tokens = im_start_tokens + system_tokens_part + im_end_tokens
147
+
148
+ raw_text = ""
149
+ context_tokens = []
150
+
151
+ for turn_query, turn_response in reversed(history):
152
+ query_text, query_tokens_part = _tokenize_str("user", turn_query)
153
+ query_tokens = im_start_tokens + query_tokens_part + im_end_tokens
154
+ if turn_response is not None:
155
+ response_text, response_tokens_part = _tokenize_str(
156
+ "assistant", turn_response
157
+ )
158
+ response_tokens = im_start_tokens + response_tokens_part + im_end_tokens
159
+
160
+ next_context_tokens = nl_tokens + query_tokens + nl_tokens + response_tokens
161
+ prev_chat = (
162
+ f"\n{im_start}{query_text}{im_end}\n{im_start}{response_text}{im_end}"
163
+ )
164
+ else:
165
+ next_context_tokens = nl_tokens + query_tokens + nl_tokens
166
+ prev_chat = f"\n{im_start}{query_text}{im_end}\n"
167
+
168
+ current_context_size = (
169
+ len(system_tokens) + len(next_context_tokens) + len(context_tokens)
170
+ )
171
+ if current_context_size < max_window_size:
172
+ context_tokens = next_context_tokens + context_tokens
173
+ raw_text = prev_chat + raw_text
174
+ else:
175
+ break
176
+
177
+ context_tokens = system_tokens + context_tokens
178
+ raw_text = f"{im_start}{system_text}{im_end}" + raw_text
179
+ context_tokens += (
180
+ nl_tokens
181
+ + im_start_tokens
182
+ + _tokenize_str("user", query)[1]
183
+ + im_end_tokens
184
+ + nl_tokens
185
+ + im_start_tokens
186
+ + tokenizer.encode("assistant")
187
+ + nl_tokens
188
+ )
189
+ raw_text += f"\n{im_start}user\n{query}{im_end}\n{im_start}assistant\n"
190
+
191
+ elif chat_format == "raw":
192
+ raw_text = query
193
+ context_tokens = tokenizer.encode(raw_text)
194
+ else:
195
+ raise NotImplementedError(f"Unknown chat format {chat_format!r}")
196
+
197
+ return raw_text, context_tokens
198
+
199
+
200
+ def _decode_default(
201
+ tokens: List[int],
202
+ *,
203
+ stop_words: List[str],
204
+ eod_words: List[str],
205
+ tokenizer: PreTrainedTokenizer,
206
+ raw_text_len: int,
207
+ verbose: bool = False,
208
+ return_end_reason: bool = False,
209
+ errors: str='replace',
210
+ ):
211
+ trim_decode_tokens = tokenizer.decode(tokens, errors=errors)[raw_text_len:]
212
+ if verbose:
213
+ print("\nRaw Generate: ", trim_decode_tokens)
214
+
215
+ end_reason = f"Gen length {len(tokens)}"
216
+ for stop_word in stop_words:
217
+ trim_decode_tokens = trim_decode_tokens.replace(stop_word, "").strip()
218
+ for eod_word in eod_words:
219
+ if eod_word in trim_decode_tokens:
220
+ end_reason = f"Gen {eod_word!r}"
221
+ trim_decode_tokens = trim_decode_tokens.split(eod_word)[0]
222
+ trim_decode_tokens = trim_decode_tokens.strip()
223
+ if verbose:
224
+ print("\nEnd Reason:", end_reason)
225
+ print("\nGenerate: ", trim_decode_tokens)
226
+
227
+ if return_end_reason:
228
+ return trim_decode_tokens, end_reason
229
+ else:
230
+ return trim_decode_tokens
231
+
232
+
233
+ def _decode_chatml(
234
+ tokens: List[int],
235
+ *,
236
+ stop_words: List[str],
237
+ eod_token_ids: List[int],
238
+ tokenizer: PreTrainedTokenizer,
239
+ raw_text_len: int,
240
+ context_length: int,
241
+ verbose: bool = False,
242
+ return_end_reason: bool = False,
243
+ errors: str='replace'
244
+ ):
245
+ end_reason = f"Gen length {len(tokens)}"
246
+ eod_token_idx = context_length
247
+ for eod_token_idx in range(context_length, len(tokens)):
248
+ if tokens[eod_token_idx] in eod_token_ids:
249
+ end_reason = f"Gen {tokenizer.decode([tokens[eod_token_idx]])!r}"
250
+ break
251
+
252
+ trim_decode_tokens = tokenizer.decode(tokens[:eod_token_idx], errors=errors)[raw_text_len:]
253
+ if verbose:
254
+ print("\nRaw Generate w/o EOD:", tokenizer.decode(tokens, errors=errors)[raw_text_len:])
255
+ print("\nRaw Generate:", trim_decode_tokens)
256
+ print("\nEnd Reason:", end_reason)
257
+ for stop_word in stop_words:
258
+ trim_decode_tokens = trim_decode_tokens.replace(stop_word, "").strip()
259
+ trim_decode_tokens = trim_decode_tokens.strip()
260
+ if verbose:
261
+ print("\nGenerate:", trim_decode_tokens)
262
+
263
+ if return_end_reason:
264
+ return trim_decode_tokens, end_reason
265
+ else:
266
+ return trim_decode_tokens
267
+
268
+
269
+ def decode_tokens(
270
+ tokens: Union[torch.LongTensor, TokensType],
271
+ tokenizer: PreTrainedTokenizer,
272
+ raw_text_len: int,
273
+ context_length: int,
274
+ chat_format: str,
275
+ verbose: bool = False,
276
+ return_end_reason: bool = False,
277
+ errors: str="replace",
278
+ ) -> str:
279
+ if torch.is_tensor(tokens):
280
+ tokens = tokens.cpu().numpy().tolist()
281
+
282
+ if chat_format == "chatml":
283
+ return _decode_chatml(
284
+ tokens,
285
+ stop_words=[],
286
+ eod_token_ids=[tokenizer.im_start_id, tokenizer.im_end_id],
287
+ tokenizer=tokenizer,
288
+ raw_text_len=raw_text_len,
289
+ context_length=context_length,
290
+ verbose=verbose,
291
+ return_end_reason=return_end_reason,
292
+ errors=errors,
293
+ )
294
+ elif chat_format == "raw":
295
+ return _decode_default(
296
+ tokens,
297
+ stop_words=["<|endoftext|>"],
298
+ eod_words=["<|endoftext|>"],
299
+ tokenizer=tokenizer,
300
+ raw_text_len=raw_text_len,
301
+ verbose=verbose,
302
+ return_end_reason=return_end_reason,
303
+ errors=errors,
304
+ )
305
+ else:
306
+ raise NotImplementedError(f"Unknown chat format {chat_format!r}")
307
+
308
+
309
+ class StopWordsLogitsProcessor(LogitsProcessor):
310
+ """
311
+ :class:`transformers.LogitsProcessor` that enforces that when specified sequences appear, stop geration.
312
+
313
+ Args:
314
+ stop_words_ids (:obj:`List[List[int]]`):
315
+ List of list of token ids of stop ids. In order to get the tokens of the words
316
+ that should not appear in the generated text, use :obj:`tokenizer(bad_word,
317
+ add_prefix_space=True).input_ids`.
318
+ eos_token_id (:obj:`int`):
319
+ The id of the `end-of-sequence` token.
320
+ """
321
+
322
+ def __init__(self, stop_words_ids: Iterable[Iterable[int]], eos_token_id: int):
323
+
324
+ if not isinstance(stop_words_ids, List) or len(stop_words_ids) == 0:
325
+ raise ValueError(
326
+ f"`stop_words_ids` has to be a non-emtpy list, but is {stop_words_ids}."
327
+ )
328
+ if any(not isinstance(bad_word_ids, list) for bad_word_ids in stop_words_ids):
329
+ raise ValueError(
330
+ f"`stop_words_ids` has to be a list of lists, but is {stop_words_ids}."
331
+ )
332
+ if any(
333
+ any(
334
+ (not isinstance(token_id, (int, np.integer)) or token_id < 0)
335
+ for token_id in stop_word_ids
336
+ )
337
+ for stop_word_ids in stop_words_ids
338
+ ):
339
+ raise ValueError(
340
+ f"Each list in `stop_words_ids` has to be a list of positive integers, but is {stop_words_ids}."
341
+ )
342
+
343
+ self.stop_words_ids = list(
344
+ filter(
345
+ lambda bad_token_seq: bad_token_seq != [eos_token_id], stop_words_ids
346
+ )
347
+ )
348
+ self.eos_token_id = eos_token_id
349
+ for stop_token_seq in self.stop_words_ids:
350
+ assert (
351
+ len(stop_token_seq) > 0
352
+ ), "Stop words token sequences {} cannot have an empty list".format(
353
+ stop_words_ids
354
+ )
355
+
356
+ def __call__(
357
+ self, input_ids: torch.LongTensor, scores: torch.FloatTensor
358
+ ) -> torch.FloatTensor:
359
+ stopped_samples = self._calc_stopped_samples(input_ids)
360
+ for i, should_stop in enumerate(stopped_samples):
361
+ if should_stop:
362
+ scores[i, self.eos_token_id] = float(2**15)
363
+ return scores
364
+
365
+ def _tokens_match(self, prev_tokens: torch.LongTensor, tokens: List[int]) -> bool:
366
+ if len(tokens) == 0:
367
+ # if bad word tokens is just one token always ban it
368
+ return True
369
+ elif len(tokens) > len(prev_tokens):
370
+ # if bad word tokens are longer then prev input_ids they can't be equal
371
+ return False
372
+ elif prev_tokens[-len(tokens) :].tolist() == tokens:
373
+ # if tokens match
374
+ return True
375
+ else:
376
+ return False
377
+
378
+ def _calc_stopped_samples(self, prev_input_ids: Iterable[int]) -> Iterable[int]:
379
+ stopped_samples = []
380
+ for prev_input_ids_slice in prev_input_ids:
381
+ match = False
382
+ for stop_token_seq in self.stop_words_ids:
383
+ if self._tokens_match(prev_input_ids_slice, stop_token_seq):
384
+ # if tokens do not match continue
385
+ match = True
386
+ break
387
+ stopped_samples.append(match)
388
+
389
+ return stopped_samples
390
+
391
+
392
+ def top_k_logits(logits, top_k=0, top_p=0.0, filter_value=-float("Inf")):
393
+ """This function has been mostly taken from huggingface conversational
394
+ ai code at
395
+ https://medium.com/huggingface/how-to-build-a-state-of-the-art-
396
+ conversational-ai-with-transfer-learning-2d818ac26313"""
397
+
398
+ if top_k > 0:
399
+ # Remove all tokens with a probability less than the
400
+ # last token of the top-k
401
+ indices_to_remove = logits < torch.topk(logits, top_k)[0][..., -1, None]
402
+ logits[indices_to_remove] = filter_value
403
+
404
+ if top_p > 0.0:
405
+ # Cconvert to 1D
406
+ sorted_logits, sorted_indices = torch.sort(logits, descending=True, dim=-1)
407
+ cumulative_probs = torch.cumsum(F.softmax(sorted_logits, dim=-1), dim=-1)
408
+
409
+ # Remove tokens with cumulative probability above the threshold
410
+ sorted_indices_to_remove = cumulative_probs > top_p
411
+ # Shift the indices to the right to keep also the first token
412
+ # above the threshold
413
+ sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[..., :-1].clone()
414
+ sorted_indices_to_remove[..., 0] = 0
415
+ for i in range(sorted_indices.size(0)):
416
+ indices_to_remove = sorted_indices[i][sorted_indices_to_remove[i]]
417
+ logits[i][indices_to_remove] = filter_value
418
+
419
+ return logits
420
+
421
+
422
+ def switch(val1, val2, boolean):
423
+ boolean = boolean.type_as(val1)
424
+ return (1 - boolean) * val1 + boolean * val2
special_tokens_map.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "pad_token": "<|endoftext|>"
3
+ }
tokenization_qwen.py ADDED
@@ -0,0 +1,598 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba Cloud.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ """Tokenization classes for QWen."""
7
+
8
+ import base64
9
+ import logging
10
+ import os
11
+ import requests
12
+ import unicodedata
13
+ from typing import Collection, Dict, List, Set, Tuple, Union, Any, Callable, Optional
14
+
15
+ import tiktoken
16
+ import numpy as np
17
+ from PIL import Image
18
+ from PIL import ImageFont
19
+ from PIL import ImageDraw
20
+ from transformers import PreTrainedTokenizer, AddedToken
21
+ from transformers.utils import try_to_load_from_cache
22
+
23
+ import matplotlib.colors as mcolors
24
+ from matplotlib.font_manager import FontProperties
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+
29
+ VOCAB_FILES_NAMES = {"vocab_file": "qwen.tiktoken", "ttf": "SimSun.ttf"}
30
+ FONT_PATH = try_to_load_from_cache("Qwen/Qwen-VL-Chat", "SimSun.ttf")
31
+ if FONT_PATH is None:
32
+ if not os.path.exists("SimSun.ttf"):
33
+ ttf = requests.get("https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/SimSun.ttf")
34
+ open("SimSun.ttf", "wb").write(ttf.content)
35
+ FONT_PATH = "SimSun.ttf"
36
+
37
+ PAT_STR = r"""(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+"""
38
+ ENDOFTEXT = "<|endoftext|>"
39
+ IMSTART = "<|im_start|>"
40
+ IMEND = "<|im_end|>"
41
+ # as the default behavior is changed to allow special tokens in
42
+ # regular texts, the surface forms of special tokens need to be
43
+ # as different as possible to minimize the impact
44
+ EXTRAS = tuple((f"<|extra_{i}|>" for i in range(205)))
45
+ SPECIAL_TOKENS = (
46
+ ENDOFTEXT,
47
+ IMSTART,
48
+ IMEND,
49
+ ) + EXTRAS
50
+ IMG_TOKEN_SPAN = 256
51
+
52
+
53
+ def _load_tiktoken_bpe(tiktoken_bpe_file: str) -> Dict[bytes, int]:
54
+ with open(tiktoken_bpe_file, "rb") as f:
55
+ contents = f.read()
56
+ return {
57
+ base64.b64decode(token): int(rank)
58
+ for token, rank in (line.split() for line in contents.splitlines() if line)
59
+ }
60
+
61
+ def _list_find(
62
+ input_list: List[Any],
63
+ candidates: Tuple[Any],
64
+ start: int = 0,
65
+ ):
66
+ for i in range(start, len(input_list)):
67
+ if input_list[i] in candidates:
68
+ return i
69
+ return -1
70
+
71
+ def _replace_closed_tag(
72
+ input_tokens: List[Any],
73
+ start_tags: Union[Any, Tuple[Any]],
74
+ end_tags: Union[Any, Tuple[Any]],
75
+ inclusive_replace_func: Callable,
76
+ exclusive_replace_func: Callable = lambda x: x,
77
+ ):
78
+ if isinstance(start_tags, (str, int)):
79
+ start_tags = (start_tags,)
80
+ if isinstance(end_tags, (str, int)):
81
+ end_tags = (end_tags,)
82
+ assert len(start_tags) == len(end_tags)
83
+
84
+ output_tokens = []
85
+ end = 0
86
+ while True:
87
+ start = _list_find(input_tokens, start_tags, end)
88
+ if start == -1:
89
+ break
90
+ output_tokens.extend(exclusive_replace_func(input_tokens[end : start]))
91
+ tag_idx = start_tags.index(input_tokens[start])
92
+ end = _list_find(input_tokens, (end_tags[tag_idx],), start)
93
+ if end == -1:
94
+ raise ValueError("Unclosed image token")
95
+ output_tokens.extend(inclusive_replace_func(input_tokens[start : end + 1]))
96
+ end += 1
97
+ output_tokens.extend(exclusive_replace_func(input_tokens[end : ]))
98
+ return output_tokens
99
+
100
+ class QWenTokenizer(PreTrainedTokenizer):
101
+ """QWen tokenizer."""
102
+
103
+ vocab_files_names = VOCAB_FILES_NAMES
104
+
105
+ def __init__(
106
+ self,
107
+ vocab_file,
108
+ errors="replace",
109
+ image_start_tag='<img>',
110
+ image_end_tag='</img>',
111
+ image_pad_tag='<imgpad>',
112
+ ref_start_tag='<ref>',
113
+ ref_end_tag='</ref>',
114
+ box_start_tag='<box>',
115
+ box_end_tag='</box>',
116
+ quad_start_tag='<quad>',
117
+ quad_end_tag='</quad>',
118
+ **kwargs,
119
+ ):
120
+ super().__init__(**kwargs)
121
+ self.image_start_tag = image_start_tag
122
+ self.image_end_tag = image_end_tag
123
+ self.image_pad_tag = image_pad_tag
124
+ self.ref_start_tag = ref_start_tag
125
+ self.ref_end_tag = ref_end_tag
126
+ self.box_start_tag = box_start_tag
127
+ self.box_end_tag = box_end_tag
128
+ self.quad_start_tag = quad_start_tag
129
+ self.quad_end_tag = quad_end_tag
130
+ self.IMAGE_ST = (
131
+ ref_start_tag, ref_end_tag,
132
+ box_start_tag, box_end_tag,
133
+ quad_start_tag, quad_end_tag,
134
+ image_start_tag, image_end_tag,
135
+ image_pad_tag
136
+ )
137
+
138
+ self.errors = errors # how to handle errors in decoding
139
+
140
+ self.mergeable_ranks = _load_tiktoken_bpe(vocab_file) # type: dict[bytes, int]
141
+ self.special_tokens = {
142
+ token: index
143
+ for index, token in enumerate(
144
+ SPECIAL_TOKENS + self.IMAGE_ST, start=len(self.mergeable_ranks)
145
+ )
146
+ }
147
+ self.img_start_id = self.special_tokens[self.image_start_tag]
148
+ self.img_end_id = self.special_tokens[self.image_end_tag]
149
+ self.img_pad_id = self.special_tokens[self.image_pad_tag]
150
+ self.ref_start_id = self.special_tokens[self.ref_start_tag]
151
+ self.ref_end_id = self.special_tokens[self.ref_end_tag]
152
+ self.box_start_id = self.special_tokens[self.box_start_tag]
153
+ self.box_end_id = self.special_tokens[self.box_end_tag]
154
+ self.quad_start_id = self.special_tokens[self.quad_start_tag]
155
+ self.quad_end_id = self.special_tokens[self.quad_end_tag]
156
+ self.image_special_tokens = set([
157
+ self.ref_start_id, self.ref_end_id, self.box_start_id, self.box_end_id,
158
+ self.quad_start_id, self.quad_end_id,
159
+ ])
160
+
161
+ enc = tiktoken.Encoding(
162
+ "Qwen",
163
+ pat_str=PAT_STR,
164
+ mergeable_ranks=self.mergeable_ranks,
165
+ special_tokens=self.special_tokens,
166
+ )
167
+ assert (
168
+ len(self.mergeable_ranks) + len(self.special_tokens) == enc.n_vocab
169
+ ), f"{len(self.mergeable_ranks) + len(self.special_tokens)} != {enc.n_vocab} in encoding"
170
+
171
+ self.decoder = {
172
+ v: k for k, v in self.mergeable_ranks.items()
173
+ } # type: dict[int, bytes|str]
174
+ self.decoder.update({v: k for k, v in self.special_tokens.items()})
175
+
176
+ self.tokenizer = enc # type: tiktoken.Encoding
177
+
178
+ self.eod_id = self.tokenizer.eot_token
179
+ self.im_start_id = self.special_tokens[IMSTART]
180
+ self.im_end_id = self.special_tokens[IMEND]
181
+
182
+ def __getstate__(self):
183
+ # for pickle lovers
184
+ state = self.__dict__.copy()
185
+ del state['tokenizer']
186
+ return state
187
+
188
+ def __setstate__(self, state):
189
+ # tokenizer is not python native; don't pass it; rebuild it
190
+ self.__dict__.update(state)
191
+ enc = tiktoken.Encoding(
192
+ "Qwen",
193
+ pat_str=PAT_STR,
194
+ mergeable_ranks=self.mergeable_ranks,
195
+ special_tokens=self.special_tokens,
196
+ )
197
+ self.tokenizer = enc
198
+
199
+
200
+ def __len__(self) -> int:
201
+ return self.tokenizer.n_vocab
202
+
203
+ def get_vocab(self) -> Dict[bytes, int]:
204
+ return self.mergeable_ranks
205
+
206
+ def convert_tokens_to_ids(
207
+ self, tokens: Union[bytes, str, List[Union[bytes, str]]]
208
+ ) -> List[int]:
209
+ ids = []
210
+ if isinstance(tokens, (str, bytes)):
211
+ if tokens in self.special_tokens:
212
+ return self.special_tokens[tokens]
213
+ else:
214
+ return self.mergeable_ranks.get(tokens)
215
+ for token in tokens:
216
+ if token in self.special_tokens:
217
+ ids.append(self.special_tokens[token])
218
+ else:
219
+ ids.append(self.mergeable_ranks.get(token))
220
+ return ids
221
+
222
+ def _add_tokens(self, new_tokens: Union[List[str], List[AddedToken]], special_tokens: bool = False) -> int:
223
+ if not special_tokens and new_tokens:
224
+ raise ValueError('Adding regular tokens is not supported')
225
+ for token in new_tokens:
226
+ surface_form = token.content if isinstance(token, AddedToken) else token
227
+ if surface_form not in SPECIAL_TOKENS + self.IMAGE_ST:
228
+ raise ValueError('Adding unknown special tokens is not supported')
229
+ return 0
230
+
231
+ def save_vocabulary(self, save_directory: str, **kwargs) -> Tuple[str]:
232
+ """
233
+ Save only the vocabulary of the tokenizer (vocabulary).
234
+
235
+ Returns:
236
+ `Tuple(str)`: Paths to the files saved.
237
+ """
238
+ file_path = os.path.join(save_directory, "qwen.tiktoken")
239
+ with open(file_path, "w", encoding="utf8") as w:
240
+ for k, v in self.mergeable_ranks.items():
241
+ line = base64.b64encode(k).decode("utf8") + " " + str(v) + "\n"
242
+ w.write(line)
243
+ return (file_path,)
244
+
245
+ def tokenize(
246
+ self,
247
+ text: str,
248
+ allowed_special: Union[Set, str] = "all",
249
+ disallowed_special: Union[Collection, str] = (),
250
+ **kwargs,
251
+ ) -> List[Union[bytes, str]]:
252
+ """
253
+ Converts a string in a sequence of tokens.
254
+
255
+ Args:
256
+ text (`str`):
257
+ The sequence to be encoded.
258
+ allowed_special (`Literal["all"]` or `set`):
259
+ The surface forms of the tokens to be encoded as special tokens in regular texts.
260
+ Default to "all".
261
+ disallowed_special (`Literal["all"]` or `Collection`):
262
+ The surface forms of the tokens that should not be in regular texts and trigger errors.
263
+ Default to an empty tuple.
264
+
265
+ kwargs (additional keyword arguments, *optional*):
266
+ Will be passed to the underlying model specific encode method.
267
+
268
+ Returns:
269
+ `List[bytes|str]`: The list of tokens.
270
+ """
271
+ tokens = []
272
+ text = unicodedata.normalize("NFC", text)
273
+
274
+ # this implementation takes a detour: text -> token id -> token surface forms
275
+ for t in self.tokenizer.encode(
276
+ text, allowed_special=allowed_special, disallowed_special=disallowed_special
277
+ ):
278
+ tokens.append(self.decoder[t])
279
+
280
+ def _encode_imgurl(img_tokens):
281
+ assert img_tokens[0] == self.image_start_tag and img_tokens[-1] == self.image_end_tag
282
+ img_tokens = img_tokens[1:-1]
283
+ img_url = b''.join(img_tokens)
284
+ out_img_tokens = list(map(self.decoder.get, img_url))
285
+ if len(out_img_tokens) > IMG_TOKEN_SPAN:
286
+ raise ValueError("The content in {}..{} is too long".format(
287
+ self.image_start_tag, self.image_end_tag))
288
+ out_img_tokens.extend([self.image_pad_tag] * (IMG_TOKEN_SPAN - len(out_img_tokens)))
289
+ out_img_tokens = [self.image_start_tag] + out_img_tokens + [self.image_end_tag]
290
+ return out_img_tokens
291
+
292
+ return _replace_closed_tag(tokens, self.image_start_tag, self.image_end_tag, _encode_imgurl)
293
+
294
+ def convert_tokens_to_string(self, tokens: List[Union[bytes, str]]) -> str:
295
+ """
296
+ Converts a sequence of tokens in a single string.
297
+ """
298
+ text = ""
299
+ temp = b""
300
+ for t in tokens:
301
+ if isinstance(t, str):
302
+ if temp:
303
+ text += temp.decode("utf-8", errors=self.errors)
304
+ temp = b""
305
+ text += t
306
+ elif isinstance(t, bytes):
307
+ temp += t
308
+ else:
309
+ raise TypeError("token should only be of type types or str")
310
+ if temp:
311
+ text += temp.decode("utf-8", errors=self.errors)
312
+ return text
313
+
314
+ @property
315
+ def vocab_size(self):
316
+ return self.tokenizer.n_vocab
317
+
318
+ def _convert_id_to_token(self, index: int) -> Union[bytes, str]:
319
+ """Converts an id to a token, special tokens included"""
320
+ if index in self.decoder:
321
+ return self.decoder[index]
322
+ raise ValueError("unknown ids")
323
+
324
+ def _convert_token_to_id(self, token: Union[bytes, str]) -> int:
325
+ """Converts a token to an id using the vocab, special tokens included"""
326
+ if token in self.special_tokens:
327
+ return self.special_tokens[token]
328
+ if token in self.mergeable_ranks:
329
+ return self.mergeable_ranks[token]
330
+ raise ValueError("unknown token")
331
+
332
+ def _tokenize(self, text: str, **kwargs):
333
+ """
334
+ Converts a string in a sequence of tokens (string), using the tokenizer. Split in words for word-based
335
+ vocabulary or sub-words for sub-word-based vocabularies (BPE/SentencePieces/WordPieces).
336
+
337
+ Do NOT take care of added tokens.
338
+ """
339
+ raise NotImplementedError
340
+
341
+ def _decode(
342
+ self,
343
+ token_ids: Union[int, List[int]],
344
+ skip_special_tokens: bool = False,
345
+ errors: str = None,
346
+ **kwargs,
347
+ ) -> str:
348
+ if isinstance(token_ids, int):
349
+ token_ids = [token_ids]
350
+
351
+ def _decode_imgurl(img_token_ids):
352
+ assert img_token_ids[0] == self.img_start_id and img_token_ids[-1] == self.img_end_id
353
+ img_token_ids = img_token_ids[1:-1]
354
+ img_token_ids = img_token_ids[ : img_token_ids.index(self.img_pad_id)]
355
+ img_url = bytes(img_token_ids).decode('utf-8')
356
+ return [self.img_start_id] + self.tokenizer.encode(img_url) + [self.img_end_id]
357
+
358
+ token_ids = _replace_closed_tag(token_ids, self.img_start_id, self.img_end_id, _decode_imgurl)
359
+
360
+ if skip_special_tokens:
361
+ if kwargs.get('keep_image_special', False):
362
+ token_ids = [i for i in token_ids if i < self.eod_id
363
+ or i in self.image_special_tokens]
364
+ else:
365
+ token_ids = [i for i in token_ids if i < self.eod_id]
366
+ return self.tokenizer.decode(token_ids, errors=errors or self.errors)
367
+
368
+ def to_list_format(self, text: str):
369
+ text = unicodedata.normalize("NFC", text)
370
+ token_ids = self.tokenizer.encode(
371
+ text, allowed_special=set(self.IMAGE_ST + (ENDOFTEXT,)))
372
+
373
+ def _encode_vl_info(tokens):
374
+ if len(tokens) == 0:
375
+ return []
376
+ if tokens[0] == self.img_start_id and tokens[-1] == self.img_end_id:
377
+ key = 'image'
378
+ elif tokens[0] == self.ref_start_id and tokens[-1] == self.ref_end_id:
379
+ key = 'ref'
380
+ elif tokens[0] == self.box_start_id and tokens[-1] == self.box_end_id:
381
+ key = 'box'
382
+ elif tokens[0] == self.quad_start_id and tokens[-1] == self.quad_end_id:
383
+ key = 'quad'
384
+ else:
385
+ _tobytes = lambda x: x.encode('utf-8') if isinstance(x, str) else x
386
+ return [{'text': b''.join(map(_tobytes, map(self.decoder.get, tokens))).decode('utf-8')}]
387
+ _tobytes = lambda x: x.encode('utf-8') if isinstance(x, str) else x
388
+ val = b''.join(map(_tobytes, map(self.decoder.get, tokens[1:-1]))).decode('utf-8')
389
+ return [{key: val}]
390
+
391
+ return _replace_closed_tag(
392
+ token_ids,
393
+ (self.img_start_id, self.ref_start_id, self.box_start_id, self.quad_start_id),
394
+ (self.img_end_id, self.ref_end_id, self.box_end_id, self.quad_end_id),
395
+ _encode_vl_info,
396
+ _encode_vl_info,
397
+ )
398
+
399
+ def from_list_format(self, list_format: List[Dict]):
400
+ text = ''
401
+ num_images = 0
402
+ for ele in list_format:
403
+ if 'image' in ele:
404
+ num_images += 1
405
+ text += f'Picture {num_images}: '
406
+ text += self.image_start_tag + ele['image'] + self.image_end_tag
407
+ text += '\n'
408
+ elif 'text' in ele:
409
+ text += ele['text']
410
+ elif 'box' in ele:
411
+ if 'ref' in ele:
412
+ text += self.ref_start_tag + ele['ref'] + self.ref_end_tag
413
+ for box in ele['box']:
414
+ text += self.box_start_tag + '(%d,%d),(%d,%d)' % (box[0], box[1], box[2], box[3]) + self.box_end_tag
415
+ else:
416
+ raise ValueError("Unsupport element: " + str(ele))
417
+ return text
418
+
419
+ def _fetch_latest_picture(self, response, history):
420
+ if history is None:
421
+ history = []
422
+ _history = history + [(response, None)]
423
+ for q, r in _history[::-1]:
424
+ for ele in self.to_list_format(q)[::-1]:
425
+ if 'image' in ele:
426
+ return ele['image']
427
+ return None
428
+
429
+ def _fetch_all_box_with_ref(self, text):
430
+ list_format = self.to_list_format(text)
431
+ output = []
432
+ for i, ele in enumerate(list_format):
433
+ if 'box' in ele:
434
+ bbox = tuple(map(int, ele['box'].replace('(', '').replace(')', '').split(',')))
435
+ assert len(bbox) == 4
436
+ output.append({'box': bbox})
437
+ if i > 0 and 'ref' in list_format[i-1]:
438
+ output[-1]['ref'] = list_format[i-1]['ref'].strip()
439
+ return output
440
+
441
+ def draw_bbox_on_latest_picture(
442
+ self,
443
+ response,
444
+ history=None,
445
+ ) -> Optional[Image.Image]:
446
+ image = self._fetch_latest_picture(response, history)
447
+ if image is None:
448
+ return None
449
+ if image.startswith("http://") or image.startswith("https://"):
450
+ image = Image.open(requests.get(image, stream=True).raw).convert("RGB")
451
+ h, w = image.height, image.width
452
+ else:
453
+ image = np.asarray(Image.open(image).convert("RGB"))
454
+ h, w = image.shape[0], image.shape[1]
455
+ visualizer = Visualizer(image)
456
+
457
+ boxes = self._fetch_all_box_with_ref(response)
458
+ if not boxes:
459
+ return None
460
+ color = random.choice([_ for _ in mcolors.TABLEAU_COLORS.keys()]) # init color
461
+ for box in boxes:
462
+ if 'ref' in box: # random new color for new refexps
463
+ color = random.choice([_ for _ in mcolors.TABLEAU_COLORS.keys()])
464
+ x1, y1, x2, y2 = box['box']
465
+ x1, y1, x2, y2 = (int(x1 / 1000 * w), int(y1 / 1000 * h), int(x2 / 1000 * w), int(y2 / 1000 * h))
466
+ visualizer.draw_box((x1, y1, x2, y2), alpha=1, edge_color=color)
467
+ if 'ref' in box:
468
+ visualizer.draw_text(box['ref'], (x1, y1), color=color, horizontal_alignment="left")
469
+ return visualizer.output
470
+
471
+
472
+ import colorsys
473
+ import logging
474
+ import math
475
+ import numpy as np
476
+ import matplotlib as mpl
477
+ import matplotlib.colors as mplc
478
+ import matplotlib.figure as mplfigure
479
+ import torch
480
+ from matplotlib.backends.backend_agg import FigureCanvasAgg
481
+ from PIL import Image
482
+ import random
483
+
484
+ logger = logging.getLogger(__name__)
485
+
486
+
487
+ class VisImage:
488
+ def __init__(self, img, scale=1.0):
489
+ self.img = img
490
+ self.scale = scale
491
+ self.width, self.height = img.shape[1], img.shape[0]
492
+ self._setup_figure(img)
493
+
494
+ def _setup_figure(self, img):
495
+ fig = mplfigure.Figure(frameon=False)
496
+ self.dpi = fig.get_dpi()
497
+ # add a small 1e-2 to avoid precision lost due to matplotlib's truncation
498
+ # (https://github.com/matplotlib/matplotlib/issues/15363)
499
+ fig.set_size_inches(
500
+ (self.width * self.scale + 1e-2) / self.dpi,
501
+ (self.height * self.scale + 1e-2) / self.dpi,
502
+ )
503
+ self.canvas = FigureCanvasAgg(fig)
504
+ # self.canvas = mpl.backends.backend_cairo.FigureCanvasCairo(fig)
505
+ ax = fig.add_axes([0.0, 0.0, 1.0, 1.0])
506
+ ax.axis("off")
507
+ self.fig = fig
508
+ self.ax = ax
509
+ self.reset_image(img)
510
+
511
+ def reset_image(self, img):
512
+ img = img.astype("uint8")
513
+ self.ax.imshow(img, extent=(0, self.width, self.height, 0), interpolation="nearest")
514
+
515
+ def save(self, filepath):
516
+ self.fig.savefig(filepath)
517
+
518
+ def get_image(self):
519
+ canvas = self.canvas
520
+ s, (width, height) = canvas.print_to_buffer()
521
+
522
+ buffer = np.frombuffer(s, dtype="uint8")
523
+
524
+ img_rgba = buffer.reshape(height, width, 4)
525
+ rgb, alpha = np.split(img_rgba, [3], axis=2)
526
+ return rgb.astype("uint8")
527
+
528
+
529
+ class Visualizer:
530
+ def __init__(self, img_rgb, metadata=None, scale=1.0):
531
+ self.img = np.asarray(img_rgb).clip(0, 255).astype(np.uint8)
532
+ self.font_path = FONT_PATH
533
+ self.output = VisImage(self.img, scale=scale)
534
+ self.cpu_device = torch.device("cpu")
535
+
536
+ # too small texts are useless, therefore clamp to 14
537
+ self._default_font_size = max(
538
+ np.sqrt(self.output.height * self.output.width) // 30, 15 // scale
539
+ )
540
+
541
+ def draw_text(
542
+ self,
543
+ text,
544
+ position,
545
+ *,
546
+ font_size=None,
547
+ color="g",
548
+ horizontal_alignment="center",
549
+ rotation=0,
550
+ ):
551
+ if not font_size:
552
+ font_size = self._default_font_size
553
+
554
+ # since the text background is dark, we don't want the text to be dark
555
+ color = np.maximum(list(mplc.to_rgb(color)), 0.2)
556
+ color[np.argmax(color)] = max(0.8, np.max(color))
557
+
558
+ x, y = position
559
+ self.output.ax.text(
560
+ x,
561
+ y,
562
+ text,
563
+ size=font_size * self.output.scale,
564
+ fontproperties=FontProperties(fname=self.font_path),
565
+ bbox={"facecolor": "black", "alpha": 0.8, "pad": 0.7, "edgecolor": "none"},
566
+ verticalalignment="top",
567
+ horizontalalignment=horizontal_alignment,
568
+ color=color,
569
+ zorder=10,
570
+ rotation=rotation,
571
+ )
572
+ return self.output
573
+
574
+ def draw_box(self, box_coord, alpha=0.5, edge_color="g", line_style="-"):
575
+
576
+ x0, y0, x1, y1 = box_coord
577
+ width = x1 - x0
578
+ height = y1 - y0
579
+
580
+ linewidth = max(self._default_font_size / 4, 1)
581
+
582
+ self.output.ax.add_patch(
583
+ mpl.patches.Rectangle(
584
+ (x0, y0),
585
+ width,
586
+ height,
587
+ fill=False,
588
+ edgecolor=edge_color,
589
+ linewidth=linewidth * self.output.scale,
590
+ alpha=alpha,
591
+ linestyle=line_style,
592
+ )
593
+ )
594
+ return self.output
595
+
596
+ def get_output(self):
597
+
598
+ return self.output
tokenizer_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {},
3
+ "auto_map": {
4
+ "AutoTokenizer": [
5
+ "tokenization_qwen.QWenTokenizer",
6
+ null
7
+ ]
8
+ },
9
+ "clean_up_tokenization_spaces": true,
10
+ "model_max_length": 768,
11
+ "pad_token": "<|endoftext|>",
12
+ "padding_side": "right",
13
+ "tokenizer_class": "QWenTokenizer"
14
+ }
visual.py ADDED
@@ -0,0 +1,476 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba Cloud.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ from collections import OrderedDict
7
+ import math
8
+ import requests
9
+ from io import BytesIO
10
+ from functools import partial
11
+ from PIL import Image
12
+ from typing import Callable, Optional, Sequence, Tuple, List
13
+ import numpy as np
14
+
15
+ import torch
16
+ from torch import nn
17
+ from torch.nn import functional as F
18
+ from torch.nn.init import trunc_normal_
19
+ from torchvision import transforms
20
+ from torchvision.transforms import InterpolationMode
21
+
22
+
23
+ def get_abs_pos(abs_pos, tgt_size):
24
+ # abs_pos: L, C
25
+ # tgt_size: M
26
+ # return: M, C
27
+ src_size = int(math.sqrt(abs_pos.size(0)))
28
+ tgt_size = int(math.sqrt(tgt_size))
29
+ dtype = abs_pos.dtype
30
+
31
+ if src_size != tgt_size:
32
+ return F.interpolate(
33
+ abs_pos.float().reshape(1, src_size, src_size, -1).permute(0, 3, 1, 2),
34
+ size=(tgt_size, tgt_size),
35
+ mode="bicubic",
36
+ align_corners=False,
37
+ ).permute(0, 2, 3, 1).flatten(0, 2).to(dtype=dtype)
38
+ else:
39
+ return abs_pos
40
+
41
+ # https://github.com/facebookresearch/mae/blob/efb2a8062c206524e35e47d04501ed4f544c0ae8/util/pos_embed.py#L20
42
+ def get_2d_sincos_pos_embed(embed_dim, grid_size, cls_token=False):
43
+ """
44
+ grid_size: int of the grid height and width
45
+ return:
46
+ pos_embed: [grid_size*grid_size, embed_dim] or [1+grid_size*grid_size, embed_dim] (w/ or w/o cls_token)
47
+ """
48
+ grid_h = np.arange(grid_size, dtype=np.float32)
49
+ grid_w = np.arange(grid_size, dtype=np.float32)
50
+ grid = np.meshgrid(grid_w, grid_h) # here w goes first
51
+ grid = np.stack(grid, axis=0)
52
+
53
+ grid = grid.reshape([2, 1, grid_size, grid_size])
54
+ pos_embed = get_2d_sincos_pos_embed_from_grid(embed_dim, grid)
55
+ if cls_token:
56
+ pos_embed = np.concatenate([np.zeros([1, embed_dim]), pos_embed], axis=0)
57
+ return pos_embed
58
+
59
+
60
+ def get_2d_sincos_pos_embed_from_grid(embed_dim, grid):
61
+ assert embed_dim % 2 == 0
62
+
63
+ # use half of dimensions to encode grid_h
64
+ emb_h = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0]) # (H*W, D/2)
65
+ emb_w = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1]) # (H*W, D/2)
66
+
67
+ emb = np.concatenate([emb_h, emb_w], axis=1) # (H*W, D)
68
+ return emb
69
+
70
+
71
+ def get_1d_sincos_pos_embed_from_grid(embed_dim, pos):
72
+ """
73
+ embed_dim: output dimension for each position
74
+ pos: a list of positions to be encoded: size (M,)
75
+ out: (M, D)
76
+ """
77
+ assert embed_dim % 2 == 0
78
+ omega = np.arange(embed_dim // 2, dtype=np.float32)
79
+ omega /= embed_dim / 2.
80
+ omega = 1. / 10000**omega # (D/2,)
81
+
82
+ pos = pos.reshape(-1) # (M,)
83
+ out = np.einsum('m,d->md', pos, omega) # (M, D/2), outer product
84
+
85
+ emb_sin = np.sin(out) # (M, D/2)
86
+ emb_cos = np.cos(out) # (M, D/2)
87
+
88
+ emb = np.concatenate([emb_sin, emb_cos], axis=1) # (M, D)
89
+ return emb
90
+
91
+
92
+ class Resampler(nn.Module):
93
+ """
94
+ A 2D perceiver-resampler network with one cross attention layers by
95
+ (grid_size**2) learnable queries and 2d sincos pos_emb
96
+ Outputs:
97
+ A tensor with the shape of (grid_size**2, embed_dim)
98
+ """
99
+ def __init__(
100
+ self,
101
+ grid_size,
102
+ embed_dim,
103
+ num_heads,
104
+ kv_dim=None,
105
+ norm_layer=nn.LayerNorm
106
+ ):
107
+ super().__init__()
108
+ self.num_queries = grid_size ** 2
109
+ self.embed_dim = embed_dim
110
+ self.num_heads = num_heads
111
+
112
+ self.pos_embed = nn.Parameter(
113
+ torch.from_numpy(get_2d_sincos_pos_embed(embed_dim, grid_size)).float()
114
+ ).requires_grad_(False)
115
+
116
+ self.query = nn.Parameter(torch.zeros(self.num_queries, embed_dim))
117
+ trunc_normal_(self.query, std=.02)
118
+
119
+ if kv_dim is not None and kv_dim != embed_dim:
120
+ self.kv_proj = nn.Linear(kv_dim, embed_dim, bias=False)
121
+ else:
122
+ self.kv_proj = nn.Identity()
123
+
124
+ self.attn = nn.MultiheadAttention(embed_dim, num_heads)
125
+ self.ln_q = norm_layer(embed_dim)
126
+ self.ln_kv = norm_layer(embed_dim)
127
+
128
+ # self.apply(self._init_weights)
129
+
130
+ def _init_weights(self, m):
131
+ if isinstance(m, nn.Linear):
132
+ trunc_normal_(m.weight, std=.02)
133
+ if isinstance(m, nn.Linear) and m.bias is not None:
134
+ nn.init.constant_(m.bias, 0)
135
+ elif isinstance(m, nn.LayerNorm):
136
+ nn.init.constant_(m.bias, 0)
137
+ nn.init.constant_(m.weight, 1.0)
138
+
139
+ def forward(self, x, attn_mask=None):
140
+
141
+ pos_embed = get_abs_pos(self.pos_embed, x.size(1))
142
+
143
+ x = self.kv_proj(x)
144
+ x = self.ln_kv(x).permute(1, 0, 2)
145
+
146
+ N = x.shape[1]
147
+ q = self.ln_q(self.query)
148
+ out = self.attn(
149
+ self._repeat(q, N) + self.pos_embed.unsqueeze(1),
150
+ x + pos_embed.unsqueeze(1),
151
+ x,
152
+ attn_mask=attn_mask)[0]
153
+ return out.permute(1, 0, 2)
154
+
155
+ def _forward(self, x, attn_mask=None):
156
+
157
+ x = self.kv_proj(x)
158
+ x = self.ln_kv(x).permute(1, 0, 2)
159
+
160
+ out = self.attn(x, x, x, attn_mask=attn_mask)[0]
161
+ return out.permute(1, 0, 2)
162
+
163
+ def _repeat(self, query, N: int):
164
+ return query.unsqueeze(1).repeat(1, N, 1)
165
+
166
+
167
+ class VisualAttention(nn.Module):
168
+ """self-attention layer class.
169
+
170
+ Self-attention layer takes input with size [s, b, h]
171
+ and returns output of the same size.
172
+ """
173
+
174
+ def __init__(self, embed_dim, num_heads,
175
+ bias=True, kdim=None, vdim=None):
176
+ super(VisualAttention, self).__init__()
177
+ self.embed_dim = embed_dim
178
+ self.kdim = kdim if kdim is not None else embed_dim
179
+ self.vdim = vdim if vdim is not None else embed_dim
180
+ self._qkv_same_embed_dim = self.kdim == embed_dim and self.vdim == embed_dim
181
+
182
+ self.num_heads = num_heads
183
+
184
+ # Per attention head and per partition values.
185
+ assert embed_dim % num_heads == 0
186
+ self.hidden_size_per_attention_head = embed_dim // num_heads
187
+ self.num_attention_heads_per_partition = num_heads
188
+ self.hidden_size_per_partition = embed_dim
189
+
190
+ # Strided linear layer.
191
+ assert self._qkv_same_embed_dim, 'Only Support SelfAttention Currently'
192
+ self.in_proj = nn.Linear(embed_dim, 3 * embed_dim)
193
+ self.out_proj = nn.Linear(embed_dim, embed_dim)
194
+ self.norm_factor = math.sqrt(self.hidden_size_per_attention_head)
195
+
196
+ def forward(self, query, key, value, attn_mask = None):
197
+ # query/key/value: [sq, b, h]
198
+ sq, b, _ = query.size()
199
+
200
+ assert torch.allclose(query, key), 'Only Support Self-Attention Currently'
201
+ sk = sq
202
+ mixed_x_layer = self.in_proj(query)
203
+
204
+ # [sq, b, (np * 3 * hn)] --> [sq, b, np, 3 * hn]
205
+ new_tensor_shape = mixed_x_layer.size()[:-1] + \
206
+ (self.num_attention_heads_per_partition,
207
+ 3 * self.hidden_size_per_attention_head)
208
+ mixed_x_layer = mixed_x_layer.view(*new_tensor_shape)
209
+
210
+ # [sq, b, np, 3 * hn] --> 3 [sq, b, np, hn]
211
+ query_layer, key_layer, value_layer = mixed_x_layer.split(
212
+ self.hidden_size_per_attention_head, dim=-1)
213
+
214
+ # [sq, b, np, hn] -> [sq, b * np, hn]
215
+ query_layer = query_layer.view(sq,
216
+ b * self.num_attention_heads_per_partition,
217
+ self.hidden_size_per_attention_head).transpose(0, 1)
218
+ # [sk, b, np, hn] -> [sk, b * np, hn]
219
+ key_layer = key_layer.view(sk,
220
+ b * self.num_attention_heads_per_partition,
221
+ self.hidden_size_per_attention_head).transpose(0, 1)
222
+
223
+ q_scaled = query_layer / self.norm_factor
224
+ if attn_mask is not None:
225
+ attention_probs = torch.baddbmm(attn_mask, q_scaled, key_layer.transpose(-2, -1))
226
+ else:
227
+ attention_probs = torch.bmm(q_scaled, key_layer.transpose(-2, -1))
228
+ attention_probs = attention_probs.softmax(dim=-1)
229
+
230
+ value_layer = value_layer.view(sk,
231
+ b * self.num_attention_heads_per_partition,
232
+ self.hidden_size_per_attention_head).transpose(0, 1)
233
+
234
+ # matmul: [b * np, sq, hn]
235
+ context_layer = torch.bmm(attention_probs, value_layer)
236
+
237
+ # change view [b, np, sq, hn]
238
+ context_layer = context_layer.view(b,
239
+ self.num_attention_heads_per_partition,
240
+ sq, self.hidden_size_per_attention_head)
241
+
242
+ # [b, np, sq, hn] --> [sq, b, np, hn]
243
+ context_layer = context_layer.permute(2, 0, 1, 3).contiguous()
244
+
245
+ # [sq, b, np, hn] --> [sq, b, hp]
246
+ new_context_layer_shape = context_layer.size()[:-2] + \
247
+ (self.hidden_size_per_partition,)
248
+ context_layer = context_layer.view(*new_context_layer_shape)
249
+
250
+ output = self.out_proj(context_layer)
251
+
252
+ return output
253
+
254
+
255
+ class VisualAttentionBlock(nn.Module):
256
+ def __init__(
257
+ self,
258
+ d_model: int,
259
+ n_head: int,
260
+ mlp_ratio: float = 4.0,
261
+ act_layer: Callable = nn.GELU,
262
+ norm_layer: Callable = nn.LayerNorm,
263
+ is_cross_attention: bool = False,
264
+ ):
265
+ super().__init__()
266
+
267
+ self.ln_1 = norm_layer(d_model)
268
+ if is_cross_attention:
269
+ self.ln_1_kv = norm_layer(d_model)
270
+
271
+ self.ln_2 = norm_layer(d_model)
272
+ mlp_width = int(d_model * mlp_ratio)
273
+ self.attn = VisualAttention(d_model, n_head)
274
+ self.mlp = nn.Sequential(OrderedDict([
275
+ ("c_fc", nn.Linear(d_model, mlp_width)),
276
+ ("gelu", act_layer()),
277
+ ("c_proj", nn.Linear(mlp_width, d_model))
278
+ ]))
279
+
280
+ def attention(
281
+ self,
282
+ q_x: torch.Tensor,
283
+ k_x: Optional[torch.Tensor] = None,
284
+ v_x: Optional[torch.Tensor] = None,
285
+ attn_mask: Optional[torch.Tensor] = None,
286
+ ):
287
+ k_x = k_x if k_x is not None else q_x
288
+ v_x = v_x if v_x is not None else q_x
289
+
290
+ attn_mask = attn_mask.to(q_x.dtype) if attn_mask is not None else None
291
+ return self.attn(q_x, k_x, v_x, attn_mask=attn_mask)
292
+
293
+ def forward(
294
+ self,
295
+ q_x: torch.Tensor,
296
+ k_x: Optional[torch.Tensor] = None,
297
+ v_x: Optional[torch.Tensor] = None,
298
+ attn_mask: Optional[torch.Tensor] = None,
299
+ ):
300
+ k_x = self.ln_1_kv(k_x) if hasattr(self, "ln_1_kv") and k_x is not None else None
301
+ v_x = self.ln_1_kv(v_x) if hasattr(self, "ln_1_kv") and v_x is not None else None
302
+
303
+ x = q_x + self.attention(q_x=self.ln_1(q_x), k_x=k_x, v_x=v_x, attn_mask=attn_mask)
304
+ x = x + self.mlp(self.ln_2(x))
305
+ return x
306
+
307
+
308
+ class TransformerBlock(nn.Module):
309
+ def __init__(
310
+ self,
311
+ width: int,
312
+ layers: int,
313
+ heads: int,
314
+ mlp_ratio: float = 4.0,
315
+ act_layer: Callable = nn.GELU,
316
+ norm_layer: Callable = nn.LayerNorm,
317
+ ):
318
+ super().__init__()
319
+ self.width = width
320
+ self.layers = layers
321
+
322
+ self.resblocks = nn.ModuleList([
323
+ VisualAttentionBlock(
324
+ width, heads, mlp_ratio, act_layer=act_layer, norm_layer=norm_layer)
325
+ for _ in range(layers)
326
+ ])
327
+
328
+ def get_cast_dtype(self) -> torch.dtype:
329
+ return self.resblocks[0].mlp.c_fc.weight.dtype
330
+
331
+ def get_cast_device(self) -> torch.device:
332
+ return self.resblocks[0].mlp.c_fc.weight.device
333
+
334
+ def forward(self, x: torch.Tensor, attn_mask: Optional[torch.Tensor] = None):
335
+ for r in self.resblocks:
336
+ x = r(x, attn_mask=attn_mask)
337
+ return x
338
+
339
+
340
+ class VisionTransformer(nn.Module):
341
+
342
+ def __init__(
343
+ self,
344
+ image_size: int,
345
+ patch_size: int,
346
+ width: int,
347
+ layers: int,
348
+ heads: int,
349
+ mlp_ratio: float,
350
+ n_queries: int = 256,
351
+ output_dim: int = 512,
352
+ **kwargs
353
+ ):
354
+ super().__init__()
355
+ image_height, image_width = self.image_size = (image_size, image_size)
356
+ patch_height, patch_width = self.patch_size = (patch_size, patch_size)
357
+ self.grid_size = (image_height // patch_height, image_width // patch_width)
358
+ self.output_dim = output_dim
359
+
360
+ mean = (0.48145466, 0.4578275, 0.40821073)
361
+ std = (0.26862954, 0.26130258, 0.27577711)
362
+ self.image_transform = transforms.Compose([
363
+ transforms.Resize(
364
+ (image_size, image_size),
365
+ interpolation=InterpolationMode.BICUBIC
366
+ ),
367
+ transforms.ToTensor(),
368
+ transforms.Normalize(mean=mean, std=std),
369
+ ])
370
+
371
+ self.conv1 = nn.Conv2d(in_channels=3, out_channels=width, kernel_size=patch_size, stride=patch_size, bias=False)
372
+
373
+ # class embeddings and positional embeddings
374
+ scale = width ** -0.5
375
+ self.positional_embedding = nn.Parameter(scale * torch.randn(256, width))
376
+
377
+ norm_layer = partial(nn.LayerNorm, eps=1e-6)
378
+ act_layer = nn.GELU
379
+
380
+ self.ln_pre = norm_layer(width)
381
+ self.transformer = TransformerBlock(
382
+ width,
383
+ layers,
384
+ heads,
385
+ mlp_ratio,
386
+ act_layer=act_layer,
387
+ norm_layer=norm_layer,
388
+ )
389
+
390
+ self.attn_pool = Resampler(
391
+ grid_size=int(math.sqrt(n_queries)),
392
+ embed_dim=output_dim,
393
+ num_heads=output_dim // 128,
394
+ kv_dim=width,
395
+ norm_layer=norm_layer,
396
+ )
397
+ self.ln_post = norm_layer(output_dim)
398
+ self.proj = nn.Parameter((output_dim** -0.5) * torch.randn(output_dim, output_dim))
399
+
400
+ def local_feature(self, x: torch.Tensor, points: torch.LongTensor):
401
+ # x: bs, grid ** 2, hidden; points: bs, num, 2
402
+ # point [-100, -100] means nonexist
403
+
404
+ # point: xy -> yx
405
+ points = points.flip(-1)
406
+
407
+ mask = torch.all(points != -100, -1) # bs, num
408
+ if mask.sum() == 0:
409
+ return None
410
+
411
+ x_idx = torch.LongTensor([idx for idx, cnt in enumerate(mask.sum(1)) for _ in range(cnt)])
412
+ points = points[mask].unsqueeze(1) # new_bs, 1, 2
413
+
414
+ grid = int(math.sqrt(x.size(1)))
415
+
416
+ # interpolation
417
+ orig_dtype = x.dtype
418
+ x = x.float()
419
+ x = x.reshape(x.shape[0], grid, grid, -1).permute(0, 3, 1, 2)
420
+ x = F.interpolate(x, size=(100, 100), mode="bicubic", align_corners=False)
421
+ x = x.permute(0, 2, 3, 1)
422
+ x = x.to(dtype=orig_dtype)
423
+
424
+ # get local feature: nbs, 1, hidden
425
+ x = x[x_idx, points[:, 0, 0], points[:, 0, 1]].unsqueeze(1)
426
+
427
+ # projection
428
+ x = self.attn_pool._forward(x)
429
+ x = self.ln_post(x)
430
+ x = x @ self.proj
431
+
432
+ return x
433
+
434
+ def forward(self, x: torch.Tensor, points: Optional[torch.Tensor]):
435
+ x = x.to(
436
+ dtype=self.transformer.get_cast_dtype(),
437
+ device=self.transformer.get_cast_device(),
438
+ )
439
+ points = points.to(
440
+ device=self.transformer.get_cast_device(),
441
+ )
442
+ # to patches
443
+ x = self.conv1(x) # shape = [*, width, grid, grid]
444
+ x = x.reshape(x.shape[0], x.shape[1], -1) # shape = [*, width, grid ** 2]
445
+ x = x.permute(0, 2, 1) # shape = [*, grid ** 2, width]
446
+
447
+ x = x + get_abs_pos(self.positional_embedding, x.size(1))
448
+
449
+ x = self.ln_pre(x)
450
+
451
+ x = x.permute(1, 0, 2) # NLD -> LND
452
+ x = self.transformer(x)
453
+ x = x.permute(1, 0, 2) # LND -> NLD
454
+
455
+ points_feature = self.local_feature(x, points)
456
+
457
+ x = self.attn_pool(x)
458
+ x = self.ln_post(x)
459
+ x = x @ self.proj
460
+
461
+ return x, points_feature
462
+
463
+ def encode(self, image_paths: List[str], points: Optional[torch.Tensor]):
464
+ images = []
465
+ for image_path in image_paths:
466
+ if image_path.startswith("http://") or image_path.startswith("https://"):
467
+ image = Image.open(requests.get(image_path, stream=True).raw)
468
+ else:
469
+ image = Image.open(image_path)
470
+ try:
471
+ image = image.convert("RGB")
472
+ except:
473
+ print(f"Failed to convert image to RGB: {image_path}")
474
+ images.append(self.image_transform(image))
475
+ images = torch.stack(images, dim=0)
476
+ return self(images, points)