@@ -177,6 +177,64 @@ std::unordered_map<std::string, std::string> pmid_v2_name_map = {
177
177
std::string convert_open_clip_to_hf_clip (const std::string& name) {
178
178
std::string new_name = name;
179
179
std::string prefix;
180
+ if (contains (new_name, " .enc." )) {
181
+ // llama.cpp naming convention for T5
182
+ size_t pos = new_name.find (" .enc." );
183
+ if (pos != std::string::npos) {
184
+ new_name.replace (pos, 5 , " .encoder." );
185
+ }
186
+ pos = new_name.find (" blk." );
187
+ if (pos != std::string::npos) {
188
+ new_name.replace (pos, 4 , " block." );
189
+ }
190
+ pos = new_name.find (" output_norm." );
191
+ if (pos != std::string::npos) {
192
+ new_name.replace (pos, 12 , " final_layer_norm." );
193
+ }
194
+ pos = new_name.find (" attn_k." );
195
+ if (pos != std::string::npos) {
196
+ new_name.replace (pos, 7 , " layer.0.SelfAttention.k." );
197
+ }
198
+ pos = new_name.find (" attn_v." );
199
+ if (pos != std::string::npos) {
200
+ new_name.replace (pos, 7 , " layer.0.SelfAttention.v." );
201
+ }
202
+ pos = new_name.find (" attn_o." );
203
+ if (pos != std::string::npos) {
204
+ new_name.replace (pos, 7 , " layer.0.SelfAttention.o." );
205
+ }
206
+ pos = new_name.find (" attn_q." );
207
+ if (pos != std::string::npos) {
208
+ new_name.replace (pos, 7 , " layer.0.SelfAttention.q." );
209
+ }
210
+ pos = new_name.find (" attn_norm." );
211
+ if (pos != std::string::npos) {
212
+ new_name.replace (pos, 10 , " layer.0.layer_norm." );
213
+ }
214
+ pos = new_name.find (" ffn_norm." );
215
+ if (pos != std::string::npos) {
216
+ new_name.replace (pos, 9 , " layer.1.layer_norm." );
217
+ }
218
+ pos = new_name.find (" ffn_up." );
219
+ if (pos != std::string::npos) {
220
+ new_name.replace (pos, 7 , " layer.1.DenseReluDense.wi_1." );
221
+ }
222
+ pos = new_name.find (" ffn_down." );
223
+ if (pos != std::string::npos) {
224
+ new_name.replace (pos, 9 , " layer.1.DenseReluDense.wo." );
225
+ }
226
+ pos = new_name.find (" ffn_gate." );
227
+ if (pos != std::string::npos) {
228
+ new_name.replace (pos, 9 , " layer.1.DenseReluDense.wi_0." );
229
+ }
230
+ pos = new_name.find (" attn_rel_b." );
231
+ if (pos != std::string::npos) {
232
+ new_name.replace (pos, 11 , " layer.0.SelfAttention.relative_attention_bias." );
233
+ }
234
+ } else if (name == " text_encoders.t5xxl.transformer.token_embd.weight" ) {
235
+ new_name = " text_encoders.t5xxl.transformer.shared.weight" ;
236
+ }
237
+
180
238
if (starts_with (new_name, " conditioner.embedders.0.open_clip." )) {
181
239
prefix = " cond_stage_model." ;
182
240
new_name = new_name.substr (strlen (" conditioner.embedders.0.open_clip." ));
0 commit comments