Skip to content

Commit f7b3efc

Browse files
committed
pytorch: add gguf-info.py script to read GGUF files
1 parent e65bab5 commit f7b3efc

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import torch
2+
from gguf import GGUFReader
3+
4+
def print_tensors(r: GGUFReader):
5+
print(f"Total number of tensors: {len(r.tensors)}\n")
6+
for tensor in r.tensors:
7+
print(f"Name: {tensor.name}")
8+
print(f" shape: {tensor.shape}, type: {tensor.tensor_type}, elements: {tensor.n_elements}")
9+
10+
def print_tensor(r: GGUFReader, name: str):
11+
tensor = next(t for t in r.tensors if t.name == name)
12+
print(f"Tensor: {tensor.name}")
13+
print(f" shape: {tensor.shape}, type: {tensor.tensor_type}, elements: {tensor.n_elements}")
14+
print(f" data:\n{tensor.data}")
15+
16+
def print_field(r: GGUFReader, field_name: str):
17+
field = r.get_field(field_name)
18+
print(f"Field: {field_name}")
19+
print(f" contents: {field.contents()}")
20+
print(f" type: {type(field)}, value: {field}")
21+
22+
def main():
23+
gguf_path = "/home/danbev/work/ai/llama.cpp/models/granite-4.0-h-tiny-Q4_0.gguf"
24+
r = GGUFReader(gguf_path)
25+
#print_tensors(r)
26+
print_tensor(r, "blk.39.ssm_in.weight")
27+
28+
print_field(r, "granitehybrid.expert_used_count")
29+
if __name__ == "__main__":
30+
main()

0 commit comments

Comments
 (0)