char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
a2ac89d6e
char/aliceai-t5-moe
1#!/usr/bin/env python3 2 3import logging 4import os 5import hashlib 6 7logger = logging .getLogger ("verify-checksum-models" ) 8 9 10def sha256sum (file ): 11block_size = 16 * 1024 * 1024 # 16 MB block size 12b = bytearray (block_size ) 13file_hash = hashlib .sha256 () 14mv = memoryview (b ) 15with open (file ,'rb' ,buffering = 0 )as f : 16while True : 17n = f .readinto (mv ) 18if not n : 19break 20file_hash .update (mv [:n ]) 21 22return file_hash .hexdigest () 23 24 25# Define the path to the llama directory (parent folder of script directory) 26llama_path = os .path .abspath (os .path .join (os .path .dirname (__file__ ),os .pardir )) 27 28# Define the file with the list of hashes and filenames 29hash_list_file = os .path .join (llama_path ,"SHA256SUMS" ) 30 31# Check if the hash list file exists 32if not os .path .exists (hash_list_file ): 33logger .error (f"Hash list file not found: { hash_list_file } " ) 34exit (1 ) 35 36# Read the hash file content and split it into an array of lines 37with open (hash_list_file ,"r" )as f : 38hash_list = f .read ().splitlines () 39 40# Create an array to store the results 41results = [] 42 43# Loop over each line in the hash list 44for line in hash_list : 45# Split the line into hash and filename 46hash_value ,filename = line .split (" " ) 47 48# Get the full path of the file by joining the llama path and the filename 49file_path = os .path .join (llama_path ,filename ) 50 51# Informing user of the progress of the integrity check 52logger .info (f"Verifying the checksum of { file_path } " ) 53 54# Check if the file exists 55if os .path .exists (file_path ): 56# Calculate the SHA256 checksum of the file using hashlib 57file_hash = sha256sum (file_path ) 58 59# Compare the file hash with the expected hash 60if file_hash == hash_value : 61valid_checksum = "V" 62file_missing = "" 63else : 64valid_checksum = "" 65file_missing = "" 66else : 67valid_checksum = "" 68file_missing = "X" 69 70# Add the results to the array 71results .append ({ 72"filename" :filename , 73"valid checksum" :valid_checksum , 74"file missing" :file_missing 75 }) 76 77 78# Print column headers for results table 79"filename" .ljust (40 )+ "valid checksum" .center (20 )+ "file missing" .center (20 ))# noqa: NP100 80"-" * 80 )# noqa: NP100 81 82# Output the results as a table 83for r in results : 84f" { r [ 'filename' ]:40 } { r [ 'valid checksum' ]:^20 } { r [ 'file missing' ]:^20 } " )# noqa: NP100