flux-3-image-klein-infendpoint / verify_checkpoint.py
stsachit's picture
Publish self-contained A10 deployment and offline validation
52a6059 verified
Raw History Blame Contribute Delete
2.29 kB
"""Verify a downloaded checkpoint offline; optionally hash all selected weights."""
import argparse
import hashlib
import json
from pathlib import Path
from model_config import GGUF_FILENAME
def verify_checkpoint(path, quantization='q8_0', check_hashes=False):
path = Path(path)
manifest = json.loads((path / 'checkpoint_manifest.json').read_text())
required = ['modular_model_index.json', 'transformer/config.json', 'vae/config.json',
'text_encoder/config.json', 'text_encoder/tokenizer.json',
'text_encoder/tokenizer_config.json', 'text_encoder/chat_template.json',
'text_encoder/preprocessor_config.json', 'text_encoder/video_preprocessor_config.json',
'text_encoder/model.safetensors.index.json']
if quantization in ('bf16', 'all'):
required.append('transformer/diffusion_pytorch_model.safetensors.index.json')
for filename in required:
if not (path / filename).is_file():
raise FileNotFoundError(f'Missing checkpoint file: {filename}')
verified = []
for item in manifest['weights']:
filename = item['path']
if filename.startswith('transformer/') and quantization != 'all':
if (filename == GGUF_FILENAME) != (quantization == 'q8_0'):
continue
target = path / filename
if not target.is_file() or target.stat().st_size != item['bytes']:
raise ValueError(f'Missing or incomplete weight: {filename}')
if check_hashes:
with target.open('rb') as source:
checksum = hashlib.file_digest(source, 'sha256').hexdigest()
if checksum != item['sha256']:
raise ValueError(f'Checksum mismatch: {filename}')
verified.append(filename)
return {'quantization': quantization, 'weights': verified, 'hashes_checked': check_hashes}
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('path', type=Path)
parser.add_argument('--quantization', choices=['q8_0', 'bf16', 'all'], default='q8_0')
parser.add_argument('--hashes', action='store_true')
args = parser.parse_args()
print(json.dumps(verify_checkpoint(args.path, args.quantization, args.hashes), indent=2))