1
1
#!/usr/bin/env python3
2
2
from __future__ import annotations
3
3
4
- import sys
5
4
import uuid
6
5
import hashlib
7
6
17
16
if "NO_LOCAL_GGUF" not in os .environ and (Path (__file__ ).parent .parent .parent / 'gguf-py' ).exists ():
18
17
sys .path .insert (0 , str (Path (__file__ ).parent .parent ))
19
18
20
- from gguf import GGUFReader , GGUFValueType # noqa: E402
19
+ from gguf import GGUFReader # noqa: E402
20
+
21
21
22
- logger = logging .getLogger ("gguf-dump " )
22
+ logger = logging .getLogger ("gguf-hash " )
23
23
24
24
# UUID_NAMESPACE_LLAMA_CPP = uuid.uuid5(uuid.NAMESPACE_URL, 'en.wikipedia.org/wiki/Llama.cpp')
25
25
UUID_NAMESPACE_LLAMA_CPP = uuid .UUID ('ef001206-dadc-5f6d-a15f-3359e577d4e5' )
26
26
27
+
27
28
# For more information about what field.parts and field.data represent,
28
29
# please see the comments in the modify_gguf.py example.
29
30
def gguf_hash (reader : GGUFReader , filename : str , disable_progress_bar ) -> None :
@@ -50,7 +51,6 @@ def gguf_hash(reader: GGUFReader, filename: str, disable_progress_bar) -> None:
50
51
51
52
# Hashing Process
52
53
for n , tensor in enumerate (reader .tensors , 1 ):
53
- prettydims = ', ' .join ('{0:5}' .format (d ) for d in list (tensor .shape ) + [1 ] * (4 - len (tensor .shape )))
54
54
55
55
# We don't need these
56
56
if tensor .name .endswith ((".attention.masked_bias" , ".attention.bias" , ".rotary_emb.inv_freq" )):
@@ -66,14 +66,15 @@ def gguf_hash(reader: GGUFReader, filename: str, disable_progress_bar) -> None:
66
66
sha1_layer .update (tensor .data )
67
67
sha1 .update (tensor .data )
68
68
uuidv5_sha1 .update (tensor .data )
69
- print ("sha1 {0} {1}:{2}" .format (sha1_layer .hexdigest (), filename , tensor .name ))
69
+ print ("sha1 {0} {1}:{2}" .format (sha1_layer .hexdigest (), filename , tensor .name )) # noqa: NP100
70
70
71
71
# Flush Hash Progress Bar
72
72
bar .close ()
73
73
74
74
# Display Hash Output
75
- print ("sha1 {0} {1}" .format (sha1 .hexdigest (), filename ))
76
- print ("UUIDv5 {0} {1}" .format (uuid .UUID (bytes = uuidv5_sha1 .digest ()[:16 ], version = 5 ), filename ))
75
+ print ("sha1 {0} {1}" .format (sha1 .hexdigest (), filename )) # noqa: NP100
76
+ print ("UUIDv5 {0} {1}" .format (uuid .UUID (bytes = uuidv5_sha1 .digest ()[:16 ], version = 5 ), filename )) # noqa: NP100
77
+
77
78
78
79
def main () -> None :
79
80
parser = argparse .ArgumentParser (description = "Dump GGUF file metadata" )
@@ -85,5 +86,6 @@ def main() -> None:
85
86
reader = GGUFReader (args .model , 'r' )
86
87
gguf_hash (reader , args .model , not args .progressbar )
87
88
89
+
88
90
if __name__ == '__main__' :
89
91
main ()
0 commit comments