summaryrefslogtreecommitdiff
path: root/gguf-py/examples/reader.py
diff options
context:
space:
mode:
authorBrian <mofosyne@gmail.com>2024-05-04 05:36:41 +1000
committerGitHub <noreply@github.com>2024-05-03 22:36:41 +0300
commita2ac89d6efb41b535778bfeaecaae8fe295b6ed3 (patch)
tree584a6f5316a627e64bfbc3aa5e098b911aef285a /gguf-py/examples/reader.py
parent433def286e98751bf17db75dce53847d075c0be5 (diff)
convert.py : add python logging instead of print() (#6511)
* convert.py: add python logging instead of print() * convert.py: verbose flag takes priority over dump flag log suppression * convert.py: named instance logging * convert.py: use explicit logger id string * convert.py: convert extra print() to named logger * convert.py: sys.stderr.write --> logger.error * *.py: Convert all python scripts to use logging module * requirements.txt: remove extra line * flake8: update flake8 ignore and exclude to match ci settings * gh-actions: add flake8-no-print to flake8 lint step * pre-commit: add flake8-no-print to flake8 and also update pre-commit version * convert-hf-to-gguf.py: print() to logger conversion * *.py: logging basiconfig refactor to use conditional expression * *.py: removed commented out logging * fixup! *.py: logging basiconfig refactor to use conditional expression * constant.py: logger.error then exit should be a raise exception instead * *.py: Convert logger error and sys.exit() into a raise exception (for atypical error) * gguf-convert-endian.py: refactor convert_byteorder() to use tqdm progressbar * verify-checksum-model.py: This is the result of the program, it should be printed to stdout. * compare-llama-bench.py: add blank line for readability during missing repo response * reader.py: read_gguf_file() use print() over logging * convert.py: warning goes to stderr and won't hurt the dump output * gguf-dump.py: dump_metadata() should print to stdout * convert-hf-to-gguf.py: print --> logger.debug or ValueError() * verify-checksum-models.py: use print() for printing table * *.py: refactor logging.basicConfig() * gguf-py/gguf/*.py: use __name__ as logger name Since they will be imported and not run directly. * python-lint.yml: use .flake8 file instead * constants.py: logger no longer required * convert-hf-to-gguf.py: add additional logging * convert-hf-to-gguf.py: print() --> logger * *.py: fix flake8 warnings * revert changes to convert-hf-to-gguf.py for get_name() * convert-hf-to-gguf-update.py: use triple quoted f-string instead * *.py: accidentally corrected the wrong line * *.py: add compilade warning suggestions and style fixes
Diffstat (limited to 'gguf-py/examples/reader.py')
-rw-r--r--gguf-py/examples/reader.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/gguf-py/examples/reader.py b/gguf-py/examples/reader.py
index 62e0769d..d841048c 100644
--- a/gguf-py/examples/reader.py
+++ b/gguf-py/examples/reader.py
@@ -1,8 +1,10 @@
#!/usr/bin/env python3
+import logging
import sys
from pathlib import Path
from gguf.gguf_reader import GGUFReader
+logger = logging.getLogger("reader")
sys.path.insert(0, str(Path(__file__).parent.parent))
@@ -18,28 +20,28 @@ def read_gguf_file(gguf_file_path):
reader = GGUFReader(gguf_file_path)
# List all key-value pairs in a columnized format
- print("Key-Value Pairs:")
+ print("Key-Value Pairs:") # noqa: NP100
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("----")
+ print(f"{key:{max_key_length}} : {value}") # noqa: NP100
+ print("----") # noqa: NP100
# List all tensors
- print("Tensors:")
+ print("Tensors:") # noqa: NP100
tensor_info_format = "{:<30} | Shape: {:<15} | Size: {:<12} | Quantization: {}"
- print(tensor_info_format.format("Tensor Name", "Shape", "Size", "Quantization"))
- print("-" * 80)
+ print(tensor_info_format.format("Tensor Name", "Shape", "Size", "Quantization")) # noqa: NP100
+ print("-" * 80) # noqa: NP100
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))
+ print(tensor_info_format.format(tensor.name, shape_str, size_str, quantization_str)) # noqa: NP100
if __name__ == '__main__':
if len(sys.argv) < 2:
- print("Usage: reader.py <path_to_gguf_file>")
+ logger.info("Usage: reader.py <path_to_gguf_file>")
sys.exit(1)
gguf_file_path = sys.argv[1]
read_gguf_file(gguf_file_path)