Cion-lab commited on
Commit
296474e
·
verified ·
1 Parent(s): 9e79358

Upload build/publish_mix.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. build/publish_mix.py +12 -0
build/publish_mix.py CHANGED
@@ -154,6 +154,18 @@ def main():
154
  if int(aud.get("mix_tokens_audited") or 0) != int(man.get("total_tokens") or -1):
155
  problems.append(f"audit covered {aud.get('mix_tokens_audited')} tokens but the manifest holds "
156
  f"{man.get('total_tokens')}")
 
 
 
 
 
 
 
 
 
 
 
 
157
  if problems:
158
  print("FATAL: contamination gate refuses publication:", flush=True)
159
  for p in problems:
 
154
  if int(aud.get("mix_tokens_audited") or 0) != int(man.get("total_tokens") or -1):
155
  problems.append(f"audit covered {aud.get('mix_tokens_audited')} tokens but the manifest holds "
156
  f"{man.get('total_tokens')}")
157
+ # The token total alone cannot tell two mixes of the same size apart, and a filtered rebuild can
158
+ # produce exactly that (review finding). Recompute the digest over the shard list the same way the
159
+ # audit did and require equality, so a stale audit.json cannot certify a mix it never scanned.
160
+ want_digest = hashlib.sha256(json.dumps(
161
+ [[s["file"], s.get("tokens"), s.get("docs")] for s in man["shards"]] +
162
+ [["VAL:" + s["file"], s.get("tokens"), s.get("docs")] for s in man.get("val_shards", [])],
163
+ sort_keys=True).encode()).hexdigest()
164
+ if aud.get("mix_bytes_sha256") != want_digest:
165
+ problems.append(f"audit.json is bound to a different mix: its digest is "
166
+ f"{str(aud.get('mix_bytes_sha256'))[:16]}, this manifest is {want_digest[:16]}")
167
+ if int(aud.get("val_documents_audited") or 0) <= 0:
168
+ problems.append("the audit never scanned the held-out validation shards")
169
  if problems:
170
  print("FATAL: contamination gate refuses publication:", flush=True)
171
  for p in problems: