MyAwesomeModel-CleanupRelease / .python_tmp /54bed8a4-2e49-4458-983f-45b2d078a179.py
FuryAssassin's picture
Upload folder using huggingface_hub
ac6e54b verified
from huggingface_hub import HfApi, upload_folder, hf_hub_download
import os
root = os.getcwd()
with open('hf_token.txt') as f:
token = f.read().strip()
api = HfApi()
who = api.whoami(token=token)
username = who.get('name') or who.get('login')
repo_name = 'MyAwesomeModel-CleanupRelease'
repo_id = f"{username}/{repo_name}"
# ensure repo
api.create_repo(repo_id=repo_id, token=token, exist_ok=True)
print('Repo ready:', repo_id)
# upload, excluding hf_token.txt and .swp
try:
upload_folder(repo_id=repo_id, folder_path=root, path_in_repo='.', token=token, repo_type='model', ignore_patterns=['*.swp','hf_token.txt'])
print('Upload completed')
except Exception as e:
print('Upload failed:', e)
# list files
files = api.list_repo_files(repo_id=repo_id, token=token)
print('Repo files count:', len(files))
swp_files = [f for f in files if f.endswith('.swp')]
print('.swp files in repo:', swp_files)
# load canonical bytes
canon_path = os.path.join(root,'checkpoints','step_100','config.json')
with open(canon_path,'rb') as f:
canonical = f.read()
# verify each config
mismatches = []
for dirpath, dirnames, filenames in os.walk(os.path.join(root,'checkpoints')):
for fn in filenames:
if fn == 'config.json':
local_p = os.path.join(dirpath, fn)
rel = os.path.relpath(local_p, root)
try:
dl = hf_hub_download(repo_id=repo_id, filename=rel, token=token, repo_type='model')
except Exception as e:
mismatches.append((rel, 'download_error', str(e)))
continue
with open(dl,'rb') as f:
b = f.read()
if b != canonical:
mismatches.append((rel, 'byte_mismatch', len(b)))
print('mismatches after upload:', mismatches)