-
Notifications
You must be signed in to change notification settings - Fork 3
/
hf_to_rwkv.py
33 lines (28 loc) · 871 Bytes
/
hf_to_rwkv.py
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
# ------------------------------------------------------------------------------------------
# SORSA: Singular Values and Orthonormal Regularized Singular Vectors Adaptation of Large Language Models
# arXiv: https://arxiv.org/abs/2409.00055
# Copyright (c) 2024 Yang Cao
# Licensed under the Apache License, Version 2.0.
# ------------------------------------------------------------------------------------------
nmn = [
["emb", "embeddings"],
["att", "attention"],
["ffn", "feed_forward"],
["ln0", "pre_ln"],
]
def cvn(s):
for i in nmn:
if i[1] not in s:
continue
s = s.replace(i[1], i[0])
return s
def convert_to_rwkv(a):
d = {}
for i in a.keys():
if i != "head.weight":
o = cvn(i)[5:]
else:
o = i
print(i, "->", o)
d[o] = a[i]
return d