6
6
import sys
7
7
from typing import Any , Dict , Sequence , TextIO
8
8
9
+ import numpy as np
9
10
import torch
10
11
11
- from convert import DATA_TYPE_TO_FTYPE , NUMPY_TYPE_TO_DATA_TYPE , DataType
12
+ NUMPY_TYPE_TO_FTYPE : Dict [str , int ] = {"float32" : 0 , "float16" : 1 }
13
+
12
14
13
15
HF_SUBLAYER_TO_GGML = {
14
- "self_attn.q_proj" : "attention.wq " ,
15
- "self_attn.k_proj" : "attention.wk " ,
16
- "self_attn.v_proj" : "attention.wv " ,
17
- "self_attn.o_proj" : "attention.wo " ,
18
- "mlp.gate_proj" : "feed_forward.w1 " ,
19
- "mlp.down_proj" : "feed_forward.w2 " ,
20
- "mlp.up_proj" : "feed_forward.w3 " ,
21
- "input_layernorm" : "attention_norm " ,
16
+ "self_attn.q_proj" : "attn_q " ,
17
+ "self_attn.k_proj" : "attn_k " ,
18
+ "self_attn.v_proj" : "attn_v " ,
19
+ "self_attn.o_proj" : "attn_output " ,
20
+ "mlp.gate_proj" : "ffn_gate " ,
21
+ "mlp.down_proj" : "ffn_down " ,
22
+ "mlp.up_proj" : "ffn_up " ,
23
+ "input_layernorm" : "attn_norm " ,
22
24
"post_attention_layernorm" : "ffn_norm" ,
23
- # "norm": "norm",
24
- # "embed_tokens": "tok_embeddings",
25
- # "lm_head": "output",
26
25
}
27
26
28
27
@@ -39,7 +38,7 @@ def translate_tensor_name(t: str) -> str:
39
38
sys .exit (1 )
40
39
41
40
output_string = (
42
- f"layers .{ nn } .{ HF_SUBLAYER_TO_GGML [sub_layer ]} .weight.lora{ lora_type } "
41
+ f"blk .{ nn } .{ HF_SUBLAYER_TO_GGML [sub_layer ]} .weight.lora{ lora_type } "
43
42
)
44
43
return output_string
45
44
else :
@@ -54,20 +53,22 @@ def write_file_header(fout: TextIO, params: Dict[str, Any]) -> None:
54
53
# https://opendelta.readthedocs.io/en/latest/modules/deltas.html says that `lora_alpha` is an int
55
54
# but some models ship a float value instead
56
55
# let's convert to int, but fail if lossless conversion is not possible
57
- assert int (params ["lora_alpha" ]) == params ["lora_alpha" ], "cannot convert float to int losslessly"
56
+ assert (
57
+ int (params ["lora_alpha" ]) == params ["lora_alpha" ]
58
+ ), "cannot convert float to int losslessly"
58
59
fout .write (struct .pack ("i" , int (params ["lora_alpha" ])))
59
60
60
61
61
62
def write_tensor_header (
62
- self , name : str , shape : Sequence [int ], data_type : DataType
63
+ self , name : str , shape : Sequence [int ], data_type : np . dtype
63
64
) -> None :
64
65
sname = name .encode ("utf-8" )
65
66
fout .write (
66
67
struct .pack (
67
68
"iii" ,
68
69
len (shape ),
69
70
len (sname ),
70
- DATA_TYPE_TO_FTYPE [ NUMPY_TYPE_TO_DATA_TYPE [ data_type ] ],
71
+ NUMPY_TYPE_TO_FTYPE [ data_type . name ],
71
72
)
72
73
)
73
74
fout .write (struct .pack ("i" * len (shape ), * shape [::- 1 ]))
0 commit comments