Cion-lab commited on
Commit
d3739eb
·
verified ·
1 Parent(s): 0538d57

publish: ship tokenizer.json with the mix, sha-checked against the manifest

Browse files
Files changed (1) hide show
  1. build/publish_mix.py +15 -1
build/publish_mix.py CHANGED
@@ -4,6 +4,7 @@ import argparse
4
  import hashlib
5
  import json
6
  import os
 
7
  import struct
8
  import sys
9
  import urllib.request
@@ -152,7 +153,20 @@ def main():
152
  for grp in ("shards", "val_shards"):
153
  for rec in man.get(grp, []):
154
  to_upload.append((rec["file"], os.path.join(a.root, rec["file"])))
155
- for extra in ("manifest.json", "README.md", "ATTRIBUTION.md", "audit.json",
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  "build_state.json"):
157
  p = os.path.join(a.root, extra)
158
  if os.path.exists(p):
 
4
  import hashlib
5
  import json
6
  import os
7
+ import shutil
8
  import struct
9
  import sys
10
  import urllib.request
 
153
  for grp in ("shards", "val_shards"):
154
  for rec in man.get(grp, []):
155
  to_upload.append((rec["file"], os.path.join(a.root, rec["file"])))
156
+ # Ship the exact tokenizer bytes the mix was cut with, verified against the manifest's recorded
157
+ # sha256. A dataset of token ids is only reproducible alongside the tokenizer that produced them,
158
+ # and "download it from SmolLM2-135M and hope the file never changed" is not reproducibility (§3.12).
159
+ tp = os.path.join(a.root, "tokenizer.json")
160
+ if not os.path.exists(tp):
161
+ from huggingface_hub import hf_hub_download
162
+ shutil.copyfile(hf_hub_download("HuggingFaceTB/SmolLM2-135M", "tokenizer.json"), tp)
163
+ got = hashlib.sha256(open(tp, "rb").read()).hexdigest()
164
+ want_sha = man["tokenizer"]["sha256"]
165
+ if got != want_sha:
166
+ print(f"FATAL: tokenizer.json sha {got[:16]} != manifest {want_sha[:16]} -- the ids in this mix "
167
+ "were not produced by the tokenizer being published with them", flush=True)
168
+ sys.exit(8)
169
+ for extra in ("manifest.json", "README.md", "ATTRIBUTION.md", "audit.json", "tokenizer.json",
170
  "build_state.json"):
171
  p = os.path.join(a.root, extra)
172
  if os.path.exists(p):