This repository was archived by the owner on Sep 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdump_jgen_shapes.py
More file actions
51 lines (43 loc) · 1.91 KB
/
Copy pathdump_jgen_shapes.py
File metadata and controls
51 lines (43 loc) · 1.91 KB
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
import struct
def dump_jgen(path):
with open(path, "rb") as f:
magic = f.read(4)
version = struct.unpack("<I", f.read(4))[0]
offset = 8
if version == 3:
total_tensors = struct.unpack("<I", f.read(4))[0]
offset += 4
while True:
# We just want the first few
if version == 3:
name_len_bytes = f.read(2)
if not name_len_bytes: break
name_len = struct.unpack("<H", name_len_bytes)[0]
else:
name_len_bytes = f.read(4)
if not name_len_bytes: break
name_len = struct.unpack("<I", name_len_bytes)[0]
name = f.read(name_len).decode('utf-8')
if version == 3:
t_type = struct.unpack("<B", f.read(1))[0]
else:
t_type = struct.unpack("<I", f.read(4))[0]
if t_type == 1:
rows, cols, rank = struct.unpack("<III", f.read(12))
total_bytes = (rows * rank * 2) + (rank * 2) + (cols * rank * 2) + (cols * 2) + (rows * 2) + (rank * rank * 2)
print(f"SVDLossless: {name} (rows={rows}, cols={cols}, rank={rank})")
f.seek(total_bytes, 1)
elif t_type == 2:
rows, cols = struct.unpack("<II", f.read(8))
print(f"Dense2D: {name} (rows={rows}, cols={cols})")
f.seek(rows * cols * 2, 1)
elif t_type == 3:
length = struct.unpack("<I", f.read(4))[0]
print(f"Dense1D: {name} (length={length})")
f.seek(length * 2, 1)
if 'input_layernorm.weight' in name or 'embed_tokens' in name:
pass
else:
# we don't print everything to avoid spam
pass
dump_jgen("/home/ubuntu/model_glm.jgen")