char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
69050a11b
char/aliceai-t5-moe
1#!/usr/bin/env python3 2import logging 3import sys 4from pathlib import Path 5 6logger = logging .getLogger ("reader" ) 7 8# Necessary to load the local gguf package 9sys .path .insert (0 ,str (Path (__file__ ).parent .parent )) 10 11from gguf .gguf_reader import GGUFReader 12 13 14def read_gguf_file (gguf_file_path ): 15""" 16Reads and prints key-value pairs and tensor information from a GGUF file in an improved format. 17 18Parameters: 19- gguf_file_path: Path to the GGUF file. 20""" 21 22reader = GGUFReader (gguf_file_path ) 23 24# List all key-value pairs in a columnized format 25"Key-Value Pairs:" )# noqa: NP100 26max_key_length = max (len (key )for key in reader .fields .keys ()) 27for key ,field in reader .fields .items (): 28value = field .parts [field .data [0 ]] 29f" { key :{ max_key_length } } : { value } " )# noqa: NP100 30"----" )# noqa: NP100 31 32# List all tensors 33"Tensors:" )# noqa: NP100 34tensor_info_format = "{:<30} | Shape: {:<15} | Size: {:<12} | Quantization: {}" 35tensor_info_format .format ("Tensor Name" ,"Shape" ,"Size" ,"Quantization" ))# noqa: NP100 36"-" * 80 )# noqa: NP100 37for tensor in reader .tensors : 38shape_str = "x" .join (map (str ,tensor .shape )) 39size_str = str (tensor .n_elements ) 40quantization_str = tensor .tensor_type .name 41tensor_info_format .format (tensor .name ,shape_str ,size_str ,quantization_str ))# noqa: NP100 42 43 44if __name__ == '__main__' : 45if len (sys .argv )< 2 : 46logger .info ("Usage: reader.py <path_to_gguf_file>" ) 47sys .exit (1 ) 48gguf_file_path = sys .argv [1 ] 49read_gguf_file (gguf_file_path )