File size: 1,792 Bytes
ac6e54b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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)