From 2fc88aa6e13d56b5ddbbe9d804830ba5658972f4 Mon Sep 17 00:00:00 2001 From: John <78893154+cmp-nct@users.noreply.github.com> Date: Tue, 30 Jan 2024 14:54:26 +0100 Subject: [PATCH 1/6] Update CMakeLists.txt --- examples/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 68ad899648137..653abc73ac98f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -38,6 +38,7 @@ else() add_subdirectory(speculative) add_subdirectory(lookahead) add_subdirectory(lookup) + add_subdirectory(gguf) add_subdirectory(train-text-from-scratch) add_subdirectory(imatrix) if (LLAMA_BUILD_SERVER) From ccd4e4c1da9d7bbed23da205fa41149d0974f2fc Mon Sep 17 00:00:00 2001 From: John <78893154+cmp-nct@users.noreply.github.com> Date: Tue, 30 Jan 2024 15:07:09 +0100 Subject: [PATCH 2/6] Create reader.py --- gguf-py/examples/reader.py | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 gguf-py/examples/reader.py diff --git a/gguf-py/examples/reader.py b/gguf-py/examples/reader.py new file mode 100644 index 0000000000000..1d0b97208f902 --- /dev/null +++ b/gguf-py/examples/reader.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).parent.parent)) + +from gguf.gguf_reader import GGUFReader + +def read_gguf_file(gguf_file_path): + """ + Reads and prints key-value pairs and tensor information from a GGUF file in an improved format. + + Parameters: + - gguf_file_path: Path to the GGUF file. + """ + + reader = GGUFReader(gguf_file_path) + + # List all key-value pairs in a columnized format + print("Key-Value Pairs:") + max_key_length = max(len(key) for key in reader.fields.keys()) + for key, field in reader.fields.items(): + value = field.parts[field.data[0]] + print(f"{key:{max_key_length}} : {value}") + print("----") + + # List all tensors + print("Tensors:") + tensor_info_format = "{:<30} | Shape: {:<15} | Size: {:<12} | Quantization: {}" + print(tensor_info_format.format("Tensor Name", "Shape", "Size", "Quantization")) + print("-" * 80) + for tensor in reader.tensors: + shape_str = "x".join(map(str, tensor.shape)) + size_str = str(tensor.n_elements) + quantization_str = tensor.tensor_type.name + print(tensor_info_format.format(tensor.name, shape_str, size_str, quantization_str)) + +if __name__ == '__main__': + if len(sys.argv) < 2: + print("Usage: reader.py ") + sys.exit(1) + gguf_file_path = sys.argv[1] + read_gguf_file(gguf_file_path) From e86dff5818b8f8b07f349aa994a1c718029bb65c Mon Sep 17 00:00:00 2001 From: John <78893154+cmp-nct@users.noreply.github.com> Date: Tue, 30 Jan 2024 15:54:30 +0100 Subject: [PATCH 3/6] Update reader.py --- gguf-py/examples/reader.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gguf-py/examples/reader.py b/gguf-py/examples/reader.py index 1d0b97208f902..ff97d44193616 100644 --- a/gguf-py/examples/reader.py +++ b/gguf-py/examples/reader.py @@ -4,18 +4,18 @@ sys.path.insert(0, str(Path(__file__).parent.parent)) -from gguf.gguf_reader import GGUFReader +from gguf.gguf_reader import GGUFReader def read_gguf_file(gguf_file_path): """ Reads and prints key-value pairs and tensor information from a GGUF file in an improved format. - + Parameters: - gguf_file_path: Path to the GGUF file. """ - + reader = GGUFReader(gguf_file_path) - + # List all key-value pairs in a columnized format print("Key-Value Pairs:") max_key_length = max(len(key) for key in reader.fields.keys()) @@ -23,7 +23,7 @@ def read_gguf_file(gguf_file_path): value = field.parts[field.data[0]] print(f"{key:{max_key_length}} : {value}") print("----") - + # List all tensors print("Tensors:") tensor_info_format = "{:<30} | Shape: {:<15} | Size: {:<12} | Quantization: {}" From 5960879814b3f0480274565594dfbadbfa1a94d7 Mon Sep 17 00:00:00 2001 From: John <78893154+cmp-nct@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:07:01 +0100 Subject: [PATCH 4/6] Update reader.py another whitespace :| --- gguf-py/examples/reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gguf-py/examples/reader.py b/gguf-py/examples/reader.py index ff97d44193616..a2bef3c51cfde 100644 --- a/gguf-py/examples/reader.py +++ b/gguf-py/examples/reader.py @@ -20,7 +20,7 @@ def read_gguf_file(gguf_file_path): print("Key-Value Pairs:") max_key_length = max(len(key) for key in reader.fields.keys()) for key, field in reader.fields.items(): - value = field.parts[field.data[0]] + value = field.parts[field.data[0]] print(f"{key:{max_key_length}} : {value}") print("----") From c8c2e950697db073f4735a3e23a0422186703b81 Mon Sep 17 00:00:00 2001 From: John <78893154+cmp-nct@users.noreply.github.com> Date: Tue, 13 Feb 2024 15:08:36 +0100 Subject: [PATCH 5/6] Update reader.py --- gguf-py/examples/reader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gguf-py/examples/reader.py b/gguf-py/examples/reader.py index a2bef3c51cfde..3d455e8a3439f 100644 --- a/gguf-py/examples/reader.py +++ b/gguf-py/examples/reader.py @@ -1,10 +1,10 @@ #!/usr/bin/env python3 import sys from pathlib import Path +from gguf.gguf_reader import GGUFReader -sys.path.insert(0, str(Path(__file__).parent.parent)) -from gguf.gguf_reader import GGUFReader +sys.path.insert(0, str(Path(__file__).parent.parent)) def read_gguf_file(gguf_file_path): """ From 5315a5a8e42778540906873002e0ef8d060de0bf Mon Sep 17 00:00:00 2001 From: John <78893154+cmp-nct@users.noreply.github.com> Date: Tue, 13 Feb 2024 15:17:26 +0100 Subject: [PATCH 6/6] lintlintlint --- gguf-py/examples/reader.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gguf-py/examples/reader.py b/gguf-py/examples/reader.py index 3d455e8a3439f..62e0769dacee2 100644 --- a/gguf-py/examples/reader.py +++ b/gguf-py/examples/reader.py @@ -6,6 +6,7 @@ sys.path.insert(0, str(Path(__file__).parent.parent)) + def read_gguf_file(gguf_file_path): """ Reads and prints key-value pairs and tensor information from a GGUF file in an improved format. @@ -35,6 +36,7 @@ def read_gguf_file(gguf_file_path): quantization_str = tensor.tensor_type.name print(tensor_info_format.format(tensor.name, shape_str, size_str, quantization_str)) + if __name__ == '__main__': if len(sys.argv) < 2: print("Usage: reader.py ")