Update reader.py

This commit is contained in:
John 2024-01-30 15:54:30 +01:00 committed by GitHub
parent ccd4e4c1da
commit e86dff5818
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,18 +4,18 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent)) 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): def read_gguf_file(gguf_file_path):
""" """
Reads and prints key-value pairs and tensor information from a GGUF file in an improved format. Reads and prints key-value pairs and tensor information from a GGUF file in an improved format.
Parameters: Parameters:
- gguf_file_path: Path to the GGUF file. - gguf_file_path: Path to the GGUF file.
""" """
reader = GGUFReader(gguf_file_path) reader = GGUFReader(gguf_file_path)
# List all key-value pairs in a columnized format # List all key-value pairs in a columnized format
print("Key-Value Pairs:") print("Key-Value Pairs:")
max_key_length = max(len(key) for key in reader.fields.keys()) 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]] value = field.parts[field.data[0]]
print(f"{key:{max_key_length}} : {value}") print(f"{key:{max_key_length}} : {value}")
print("----") print("----")
# List all tensors # List all tensors
print("Tensors:") print("Tensors:")
tensor_info_format = "{:<30} | Shape: {:<15} | Size: {:<12} | Quantization: {}" tensor_info_format = "{:<30} | Shape: {:<15} | Size: {:<12} | Quantization: {}"