Skip to content

Instantly share code, notes, and snippets.

@userbox020
Created February 19, 2024 07:51
Show Gist options
  • Save userbox020/aa3e23f892075e1670cd61dcbd1036b5 to your computer and use it in GitHub Desktop.
Save userbox020/aa3e23f892075e1670cd61dcbd1036b5 to your computer and use it in GitHub Desktop.
Get LLM data info
import os
import gguf # pip install gguf
import hashlib
import argparse
def calculate_file_hash(filepath):
"""Calculate and return the SHA-256 hash of the file specified by filepath."""
print("Calculating SHA256...", end="\r")
sha256_hash = hashlib.sha256()
try:
with open(filepath, "rb") as f:
for byte_block in iter(lambda: f.read(4096), b""):
sha256_hash.update(byte_block)
hash_value = sha256_hash.hexdigest()
print(f"SHA-256: {hash_value}")
except FileNotFoundError:
print("File not found.")
except Exception as e:
print(f"An error occurred: {e}")
def get_model_info(checkpoint):
try:
result = gguf.GGUFReader(checkpoint)
print("\n---- GGUF Model Information ----\n")
print(f"Number of Layers: {result.fields['llama.block_count'].parts[-1]}")
print(f"Context Size: {result.fields['llama.context_length'].parts[-1]}")
print(f"Number of Heads: {result.fields['llama.attention.head_count'].parts[-1]}")
print(f"Number of KV Heads: {result.fields['llama.attention.head_count_kv'].parts[-1]}")
print(f"Intermediate Size: {result.fields['llama.feed_forward_length'].parts[-1]}")
print(f"Norm Epsilon: {result.fields['llama.attention.layer_norm_rms_epsilon'].parts[-1]}")
print(f"Embedding Dimension: {result.fields['llama.embedding_length'].parts[-1]}")
except Exception as e:
print(f"Failed to get model info: {e}")
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Get GGUF Model Info')
parser.add_argument('--input', type=str, help='Path to GGUF model file')
args = parser.parse_args()
if args.input:
get_model_info(args.input)
calculate_file_hash(args.input)
else:
print("No input file specified.")
#python get_model_info.py --input /path/to/model.gguf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment