Upload 7 files
Browse files- README.md +2 -0
- config.json +180 -0
- extract_qwen_vl.py +19 -0
- preprocessor_config.json +19 -0
- process_wight.py +11 -0
- pytorch_model.bin +3 -0
- pytorch_model_org.bin +3 -0
README.md
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
# QWen-VL's Vision Encoder
|
2 |
+
The extract_qwen_vl.py can be used to extract the vision encoder from QWen-VL. After extraction, you can find other necessary files in the [folder](./qwen_clip).
|
config.json
ADDED
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_commit_hash": null,
|
3 |
+
"architectures": [
|
4 |
+
"CLIPModel"
|
5 |
+
],
|
6 |
+
"initializer_factor": 1.0,
|
7 |
+
"logit_scale_init_value": 2.6592,
|
8 |
+
"model_type": "clip",
|
9 |
+
"projection_dim": 1280,
|
10 |
+
"text_config": {
|
11 |
+
"_name_or_path": "",
|
12 |
+
"add_cross_attention": false,
|
13 |
+
"architectures": null,
|
14 |
+
"attention_dropout": 0.0,
|
15 |
+
"bad_words_ids": null,
|
16 |
+
"begin_suppress_tokens": null,
|
17 |
+
"bos_token_id": 0,
|
18 |
+
"chunk_size_feed_forward": 0,
|
19 |
+
"cross_attention_hidden_size": null,
|
20 |
+
"decoder_start_token_id": null,
|
21 |
+
"diversity_penalty": 0.0,
|
22 |
+
"do_sample": false,
|
23 |
+
"dropout": 0.0,
|
24 |
+
"early_stopping": false,
|
25 |
+
"encoder_no_repeat_ngram_size": 0,
|
26 |
+
"eos_token_id": 2,
|
27 |
+
"exponential_decay_length_penalty": null,
|
28 |
+
"finetuning_task": null,
|
29 |
+
"forced_bos_token_id": null,
|
30 |
+
"forced_eos_token_id": null,
|
31 |
+
"hidden_act": "gelu",
|
32 |
+
"hidden_size": 1280,
|
33 |
+
"id2label": {
|
34 |
+
"0": "LABEL_0",
|
35 |
+
"1": "LABEL_1"
|
36 |
+
},
|
37 |
+
"initializer_factor": 1.0,
|
38 |
+
"initializer_range": 0.02,
|
39 |
+
"intermediate_size": 5120,
|
40 |
+
"is_decoder": false,
|
41 |
+
"is_encoder_decoder": false,
|
42 |
+
"label2id": {
|
43 |
+
"LABEL_0": 0,
|
44 |
+
"LABEL_1": 1
|
45 |
+
},
|
46 |
+
"layer_norm_eps": 1e-05,
|
47 |
+
"length_penalty": 1.0,
|
48 |
+
"max_length": 20,
|
49 |
+
"max_position_embeddings": 77,
|
50 |
+
"min_length": 0,
|
51 |
+
"model_type": "clip_text_model",
|
52 |
+
"no_repeat_ngram_size": 0,
|
53 |
+
"num_attention_heads": 20,
|
54 |
+
"num_beam_groups": 1,
|
55 |
+
"num_beams": 1,
|
56 |
+
"num_hidden_layers": 32,
|
57 |
+
"num_return_sequences": 1,
|
58 |
+
"output_attentions": false,
|
59 |
+
"output_hidden_states": false,
|
60 |
+
"output_scores": false,
|
61 |
+
"pad_token_id": 1,
|
62 |
+
"prefix": null,
|
63 |
+
"problem_type": null,
|
64 |
+
"pruned_heads": {},
|
65 |
+
"remove_invalid_values": false,
|
66 |
+
"repetition_penalty": 1.0,
|
67 |
+
"return_dict": true,
|
68 |
+
"return_dict_in_generate": false,
|
69 |
+
"sep_token_id": null,
|
70 |
+
"suppress_tokens": null,
|
71 |
+
"task_specific_params": null,
|
72 |
+
"temperature": 1.0,
|
73 |
+
"tf_legacy_loss": false,
|
74 |
+
"tie_encoder_decoder": false,
|
75 |
+
"tie_word_embeddings": true,
|
76 |
+
"tokenizer_class": null,
|
77 |
+
"top_k": 50,
|
78 |
+
"top_p": 1.0,
|
79 |
+
"torch_dtype": null,
|
80 |
+
"torchscript": false,
|
81 |
+
"transformers_version": "4.24.0",
|
82 |
+
"typical_p": 1.0,
|
83 |
+
"use_bfloat16": false,
|
84 |
+
"vocab_size": 49408
|
85 |
+
},
|
86 |
+
"text_config_dict": {
|
87 |
+
"hidden_act": "gelu",
|
88 |
+
"hidden_size": 1280,
|
89 |
+
"intermediate_size": 5120,
|
90 |
+
"num_attention_heads": 20,
|
91 |
+
"num_hidden_layers": 32
|
92 |
+
},
|
93 |
+
"torch_dtype": "float32",
|
94 |
+
"transformers_version": null,
|
95 |
+
"vision_config": {
|
96 |
+
"_name_or_path": "",
|
97 |
+
"add_cross_attention": false,
|
98 |
+
"architectures": null,
|
99 |
+
"attention_dropout": 0.0,
|
100 |
+
"bad_words_ids": null,
|
101 |
+
"begin_suppress_tokens": null,
|
102 |
+
"bos_token_id": null,
|
103 |
+
"chunk_size_feed_forward": 0,
|
104 |
+
"cross_attention_hidden_size": null,
|
105 |
+
"decoder_start_token_id": null,
|
106 |
+
"diversity_penalty": 0.0,
|
107 |
+
"do_sample": false,
|
108 |
+
"dropout": 0.0,
|
109 |
+
"early_stopping": false,
|
110 |
+
"encoder_no_repeat_ngram_size": 0,
|
111 |
+
"eos_token_id": null,
|
112 |
+
"exponential_decay_length_penalty": null,
|
113 |
+
"finetuning_task": null,
|
114 |
+
"forced_bos_token_id": null,
|
115 |
+
"forced_eos_token_id": null,
|
116 |
+
"hidden_act": "gelu",
|
117 |
+
"hidden_size": 1664,
|
118 |
+
"id2label": {
|
119 |
+
"0": "LABEL_0",
|
120 |
+
"1": "LABEL_1"
|
121 |
+
},
|
122 |
+
"image_size": 224,
|
123 |
+
"initializer_factor": 1.0,
|
124 |
+
"initializer_range": 0.02,
|
125 |
+
"intermediate_size": 8192,
|
126 |
+
"is_decoder": false,
|
127 |
+
"is_encoder_decoder": false,
|
128 |
+
"label2id": {
|
129 |
+
"LABEL_0": 0,
|
130 |
+
"LABEL_1": 1
|
131 |
+
},
|
132 |
+
"layer_norm_eps": 1e-05,
|
133 |
+
"length_penalty": 1.0,
|
134 |
+
"max_length": 20,
|
135 |
+
"min_length": 0,
|
136 |
+
"model_type": "clip_vision_model",
|
137 |
+
"no_repeat_ngram_size": 0,
|
138 |
+
"num_attention_heads": 16,
|
139 |
+
"num_beam_groups": 1,
|
140 |
+
"num_beams": 1,
|
141 |
+
"num_channels": 3,
|
142 |
+
"num_hidden_layers": 48,
|
143 |
+
"num_return_sequences": 1,
|
144 |
+
"output_attentions": false,
|
145 |
+
"output_hidden_states": false,
|
146 |
+
"output_scores": false,
|
147 |
+
"pad_token_id": null,
|
148 |
+
"patch_size": 14,
|
149 |
+
"prefix": null,
|
150 |
+
"problem_type": null,
|
151 |
+
"pruned_heads": {},
|
152 |
+
"remove_invalid_values": false,
|
153 |
+
"repetition_penalty": 1.0,
|
154 |
+
"return_dict": true,
|
155 |
+
"return_dict_in_generate": false,
|
156 |
+
"sep_token_id": null,
|
157 |
+
"suppress_tokens": null,
|
158 |
+
"task_specific_params": null,
|
159 |
+
"temperature": 1.0,
|
160 |
+
"tf_legacy_loss": false,
|
161 |
+
"tie_encoder_decoder": false,
|
162 |
+
"tie_word_embeddings": true,
|
163 |
+
"tokenizer_class": null,
|
164 |
+
"top_k": 50,
|
165 |
+
"top_p": 1.0,
|
166 |
+
"torch_dtype": null,
|
167 |
+
"torchscript": false,
|
168 |
+
"transformers_version": "4.24.0",
|
169 |
+
"typical_p": 1.0,
|
170 |
+
"use_bfloat16": false
|
171 |
+
},
|
172 |
+
"vision_config_dict": {
|
173 |
+
"hidden_act": "gelu",
|
174 |
+
"hidden_size": 1664,
|
175 |
+
"intermediate_size": 8192,
|
176 |
+
"num_attention_heads": 16,
|
177 |
+
"num_hidden_layers": 48,
|
178 |
+
"patch_size": 14
|
179 |
+
}
|
180 |
+
}
|
extract_qwen_vl.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM
|
2 |
+
import torch
|
3 |
+
from modelscope import (
|
4 |
+
snapshot_download, AutoModelForCausalLM, AutoTokenizer, GenerationConfig
|
5 |
+
)
|
6 |
+
import torch
|
7 |
+
model_id = 'qwen/Qwen-VL-Chat'
|
8 |
+
revision = 'v1.0.3'
|
9 |
+
|
10 |
+
model_dir = snapshot_download(model_id, revision=revision)
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, fp16=True).eval()
|
12 |
+
|
13 |
+
state_dict = model.state_dict()
|
14 |
+
save_dict = {}
|
15 |
+
for k,v in state_dict.items():
|
16 |
+
if 'visual' in k:
|
17 |
+
if 'transformer.visual.proj' not in k: # we don't need the proj layer
|
18 |
+
save_dict[k.replace('transformer.visual.', '')] = v
|
19 |
+
torch.save(save_dict, './qwen_clip/pytorch_model.bin')
|
preprocessor_config.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"crop_size": 448,
|
3 |
+
"do_center_crop": true,
|
4 |
+
"do_normalize": true,
|
5 |
+
"do_resize": true,
|
6 |
+
"feature_extractor_type": "CLIPFeatureExtractor",
|
7 |
+
"image_mean": [
|
8 |
+
0.48145466,
|
9 |
+
0.4578275,
|
10 |
+
0.40821073
|
11 |
+
],
|
12 |
+
"image_std": [
|
13 |
+
0.26862954,
|
14 |
+
0.26130258,
|
15 |
+
0.27577711
|
16 |
+
],
|
17 |
+
"resample": 3,
|
18 |
+
"size": 448
|
19 |
+
}
|
process_wight.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
|
3 |
+
org_state_dict = torch.load("/home/cv/sxp/llava_new/llava/qwen_clip/pytorch_model.bin",map_location="cuda:1")
|
4 |
+
new_state_dict = {}
|
5 |
+
for key,value in org_state_dict.items():
|
6 |
+
if "attn_pool" not in key:
|
7 |
+
new_state_dict[key] = value
|
8 |
+
|
9 |
+
print(new_state_dict.keys())
|
10 |
+
|
11 |
+
torch.save(new_state_dict,"/home/cv/sxp/llava_new/llava/qwen_clip/pytorch_model_new.bin")
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b69fa768355e29be4cd30e9b28e51f3cfb6bcb0c18b0673eff5488831a852518
|
3 |
+
size 3685755013
|
pytorch_model_org.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3e52b0d7f1ed947f459d3609b74921a29230190093e5f166e7662d2294caec97
|
3 |
+
size 3837865297
|