-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_config.hpp
197 lines (190 loc) · 7.35 KB
/
model_config.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#pragma once
#include <iostream>
enum CLIPVersion {
OPENAI_CLIP_VIT_BASE_PATCH32 = 0,
OPENAI_CLIP_VIT_LARGE_PATCH14,
OPENAI_CLIP_VIT_large_patch14_336,
OPENAI_CLIP_VIT_BASE_PATCH16,
OFASYS_CHINESE_CLIP_VIT_HUGE_PATCH14,
OFASYS_CHINESE_CLIP_VIT_LARGE_PATCH14_336,
OFASYS_CHINESE_CLIP_VIT_BASE_PATCH16,
OFASYS_CHINESE_CLIP_VIT_LARGE_PATCH14,
VERSION_COUNT
};
const char* clip_version[] = {
"openai_clip_vit_base_patch32",
"openai_clip_vit_large_pathc14",
"openai_clip_vit_large_patch14_336",
"openai_clip_vit_base_patch16",
"ofasys_chinese_clip_vit_huge_patch14",
"ofasys_chinese_clip_vit_large_patch14_336",
"ofasys_chinese_clip_vit_base_patch16",
"ofasys_chinese_clip_vit_large_patch14"};
struct TextModelParam {
TextModelParam(CLIPVersion version) {
if (version == OPENAI_CLIP_VIT_BASE_PATCH32) {
hidden_size = 512;
intermediate_size = 2048;
max_position_embeddings = 77;
num_attention_heads = 8;
num_hidden_layers = 12;
vocab_size = 49408;
projection_dim = 512;
} else if (version == OPENAI_CLIP_VIT_LARGE_PATCH14) {
hidden_size = 768;
intermediate_size = 3072;
max_position_embeddings = 77;
num_attention_heads = 12;
num_hidden_layers = 12;
vocab_size = 49408;
projection_dim = 768;
} else if (version == OPENAI_CLIP_VIT_large_patch14_336) {
hidden_size = 768;
intermediate_size = 3072;
max_position_embeddings = 77;
num_attention_heads = 12;
num_hidden_layers = 12;
vocab_size = 49408;
projection_dim = 768;
} else if (version == OPENAI_CLIP_VIT_BASE_PATCH16) {
hidden_size = 512;
intermediate_size = 2048;
max_position_embeddings = 77;
num_attention_heads = 8;
num_hidden_layers = 12;
vocab_size = 49408;
projection_dim = 512;
} else if (version == OFASYS_CHINESE_CLIP_VIT_HUGE_PATCH14) {
hidden_size = 768;
intermediate_size = 3072;
max_position_embeddings = 512;
num_attention_heads = 12;
num_hidden_layers = 12;
vocab_size = 21128;
projection_dim = 768;
type_vocab_size = 2;
} else if (version == OFASYS_CHINESE_CLIP_VIT_LARGE_PATCH14_336) {
hidden_size = 768;
intermediate_size = 3072;
max_position_embeddings = 512;
num_attention_heads = 12;
num_hidden_layers = 12;
vocab_size = 21128;
projection_dim = 768;
type_vocab_size = 2;
} else if (version == OFASYS_CHINESE_CLIP_VIT_BASE_PATCH16) {
hidden_size = 768;
intermediate_size = 3072;
max_position_embeddings = 512;
num_attention_heads = 12;
num_hidden_layers = 12;
vocab_size = 21128;
projection_dim = 512;
type_vocab_size = 2;
} else if (version == OFASYS_CHINESE_CLIP_VIT_LARGE_PATCH14) {
hidden_size = 768;
intermediate_size = 3072;
max_position_embeddings = 512;
num_attention_heads = 12;
num_hidden_layers = 12;
vocab_size = 21128;
projection_dim = 768;
type_vocab_size = 2;
}
}
public:
int hidden_size;
int intermediate_size;
int max_position_embeddings;
int num_attention_heads;
int num_hidden_layers;
int vocab_size;
int projection_dim;
int type_vocab_size;
};
typedef struct TextModelParam ClipTextModelParam;
struct VisionParam {
VisionParam(CLIPVersion version) {
if (version == OPENAI_CLIP_VIT_BASE_PATCH32) {
hidden_size = 768;
image_size = 224;
intermediate_size = 3072;
num_attention_heads = 12;
num_hidden_layers = 12;
patch_size = 32;
projection_dim = 512;
} else if (version == OPENAI_CLIP_VIT_LARGE_PATCH14) {
hidden_size = 1024;
image_size = 224;
intermediate_size = 4096;
num_attention_heads = 16;
num_hidden_layers = 24;
patch_size = 14;
projection_dim = 768;
} else if (version == OPENAI_CLIP_VIT_large_patch14_336) {
hidden_size = 1024;
image_size = 336;
intermediate_size = 4096;
num_attention_heads = 16;
num_hidden_layers = 24;
patch_size = 14;
projection_dim = 768;
} else if (version == OPENAI_CLIP_VIT_BASE_PATCH16) {
hidden_size = 768;
image_size = 224;
intermediate_size = 3072;
num_attention_heads = 12;
num_hidden_layers = 12;
patch_size = 16;
projection_dim = 512;
} else if (version == OFASYS_CHINESE_CLIP_VIT_HUGE_PATCH14) {
hidden_size = 1024;
image_size = 224;
intermediate_size = 4096;
num_attention_heads = 16;
num_hidden_layers = 24;
patch_size = 14;
projection_dim = 768;
} else if (version == OFASYS_CHINESE_CLIP_VIT_LARGE_PATCH14_336) {
hidden_size = 1024;
image_size = 336;
intermediate_size = 4096;
num_attention_heads = 16;
num_hidden_layers = 24;
patch_size = 14;
projection_dim = 768;
} else if (version == OFASYS_CHINESE_CLIP_VIT_BASE_PATCH16) {
hidden_size = 768;
image_size = 224;
intermediate_size = 3072;
num_attention_heads = 12;
num_hidden_layers = 12;
patch_size = 16;
projection_dim = 512;
} else if (version == OFASYS_CHINESE_CLIP_VIT_LARGE_PATCH14) {
hidden_size = 1024;
image_size = 224;
intermediate_size = 3072;
num_attention_heads = 16;
num_hidden_layers = 24;
patch_size = 14;
projection_dim = 768;
}
}
public:
int hidden_size;
int image_size;
int intermediate_size;
int num_attention_heads;
int num_hidden_layers;
int patch_size;
int projection_dim;
float means[3] = {0.48145466, 0.4578275, 0.40821073};
float stds[3] = {0.26862954, 0.26130258, 0.27577711};
};
typedef struct VisionParam ClipVisionParam;
typedef struct ModelParam {
CLIPVersion version = OPENAI_CLIP_VIT_BASE_PATCH32;
ClipTextModelParam text_model_param;
ClipVisionParam vision_model_param;
} ClipModelParam;