zixiao commited on
Commit
be3fae1
·
1 Parent(s): fab0586
merge_and_save_fireredasr2.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from safetensors.torch import save_file
2
+
3
+ model.llm = model.llm.merge_and_unload()
4
+
5
+ def save_safetensors_sharded(model, prefix="model", max_shard_size=2 * 1024**3):
6
+ state_dict = model.state_dict()
7
+
8
+ def get_size(t):
9
+ return t.numel() * t.element_size()
10
+
11
+ shards = []
12
+ shard = {}
13
+ shard_size = 0
14
+
15
+ for k, v in state_dict.items():
16
+ size = get_size(v)
17
+ if shard_size + size > max_shard_size and shard:
18
+ shards.append(shard)
19
+ shard = {}
20
+ shard_size = 0
21
+ shard[k] = v
22
+ shard_size += size
23
+
24
+ if shard:
25
+ shards.append(shard)
26
+
27
+ total = len(shards)
28
+ for i, shard in enumerate(shards):
29
+ save_file(shard, f"{prefix}-{i:05d}-of-{total:05d}.safetensors")
30
+
31
+ print("Done.")
model-00000-of-00009.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:80f47eb71913de2b2c6ca8a9a3fed5ed4822001d53c8f2ab4716aa8f552e84ae
3
+ size 2893434376
model-00001-of-00009.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:05be3bdbd25641247b44d262c31f6b4dea02304b8aaa52e4c3d8da903c140fb6
3
+ size 4161914520
model-00002-of-00009.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f17a140989e9dfa54da7828bbd304ff57c18e2698a7ebd52450162fac36cfa4b
3
+ size 4272092872
model-00003-of-00009.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:842a4da4ed977a3235ae832760c6fc105676680f86a90929722d49c48df03d0f
3
+ size 4118000240
model-00004-of-00009.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1d9f00efb70cdb7f9cb7740d8e344a406a895d7fd769285eb341b1578d93eae
3
+ size 4272092920
model-00005-of-00009.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8015b76c9c1ed2d4ed876e3e2b05731fa0525188d78c1db30f718f1921bf0e9a
3
+ size 4118000296
model-00006-of-00009.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1ee9b147e9df4a8c47b8f1bff4ea10c53c09d659a604907207463631620697d
3
+ size 4272092920
model-00007-of-00009.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3aabe71bbeb63060052eee23fb389d095b1a2d82a6d7c5cec997a3b113e4e188
3
+ size 3068322376
model-00008-of-00009.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0f395fb7d7d810a13d80da43b88f5a03c35ff610f2d64ad326620473490cfea4
3
+ size 2268099064