Cion-lab commited on
Commit
d5df04b
·
verified ·
1 Parent(s): e11176d

Upload train/hubckpt.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. train/hubckpt.py +11 -2
train/hubckpt.py CHANGED
@@ -33,13 +33,22 @@ def sha256_file(path, block=1 << 20):
33
 
34
 
35
  def local_manifest(dirpath):
36
- """{relpath: (bytes, sha256)} for everything under dirpath."""
 
 
 
 
 
37
  out = {}
38
  for root, _dirs, files in os.walk(dirpath):
39
  for fn in files:
40
  p = os.path.join(root, fn)
41
  rel = os.path.relpath(p, dirpath).replace(os.sep, "/")
42
- out[rel] = (os.path.getsize(p), sha256_file(p))
 
 
 
 
43
  return out
44
 
45
 
 
33
 
34
 
35
  def local_manifest(dirpath):
36
+ """{relpath: (bytes, sha256)} for everything under dirpath.
37
+
38
+ A file that disappears between the walk and the hash is skipped with a warning rather than raising:
39
+ it then shows up as a Hub-side `extra` in the comparison, which fails verification loudly and refuses
40
+ the prune. Crashing in getsize instead (E-029) killed a completed training leg at its last line.
41
+ """
42
  out = {}
43
  for root, _dirs, files in os.walk(dirpath):
44
  for fn in files:
45
  p = os.path.join(root, fn)
46
  rel = os.path.relpath(p, dirpath).replace(os.sep, "/")
47
+ try:
48
+ out[rel] = (os.path.getsize(p), sha256_file(p))
49
+ except FileNotFoundError:
50
+ print(f" WARNING: {rel} vanished while hashing {dirpath} -- "
51
+ "something else is writing here", flush=True)
52
  return out
53
 
54