File size: 7,009 Bytes
5ce45af 53d687d 5ce45af | 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | """Build the folder that goes to Hugging Face (everything but the weights, which stay on the node until upload).
python tools/make_release.py # writes release/RightNow-Mini/
Copies the model card, the licence and notice, the code (engine, deep mode, demo, evaluation, training, tools, tests)
and the results. Leaves out internal notes (docs/brief.md), one-off scripts of the night on the node, and raw
trajectories. Then scans every text file, this one included, for the names listed in a file that is not released,
and refuses to finish if one is found.
"""
import hashlib
import os
import re
import shutil
import zipfile
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
DEST = ROOT / "release" / "RightNow-Mini"
TOP = ["LICENSE", "NOTICE", "README.md", "config.json"]
DRAFTER = ROOT / "tmp" / "drafter" # the prepared draft model, copied from the node (not in git)
CODE = {
"engine": ["build_drafter.py", "serve.sh"],
"deep": ["__init__.py", "server.py", "select.py", "review.yaml", "make_candidates.py", "merge_review.py"],
"demo": ["__init__.py", "server.py", "index.html"],
"eval": ["make_subset.py", "subset.json", "run_agent.sh", "score.sh", "rescore.sh", "rescore_merge.py", "instance_report.py", "relay_model.py"],
"train": ["make_pool.py", "make_task_states.py", "gen.sh", "grade.sh", "collect_grades.py", "build_sft.py", "sft.py", "graft.py",
"merge_test.py", "expert_usage.py", "prune_experts.py", "pull_pool.sh", "prefetch_branches.sh", "pool/pool.json", "pool/disjoint.json"],
"tools": ["bench.py", "parity.py", "serve.sh", "baseline_speed.sh", "speed_engine.sh", "governor.sh", "docker_wrapper.sh", "or_proxy.py",
"report_baseline.py", "report_speed.py", "report_train.py", "report_deep.py", "report_size.py", "make_release.py", "card.py", "alone_timing.sh",
"selectors_run.sh", "rescore_queue.sh", "variant_attempts.sh", "prune_run.sh", "deep_run.sh", "deep16_worker.sh", "deep16_final.sh",
"ft_eval.sh", "round2.sh", "review_run.sh", "fix_scoring.sh", "demo_live.sh"],
"tests": ["__init__.py", "test_deep.py", "test_demo.py"],
"docs": ["licenses.md"],
}
NAMES = ROOT / "tools" / "private_names.txt" # one regular expression per line; not part of the release
FORBIDDEN = None
if NAMES.exists():
FORBIDDEN = re.compile("|".join(x.strip() for x in NAMES.read_text(encoding="utf-8").splitlines() if x.strip() and not x.startswith("#")), re.I)
TEXT = {".py", ".sh", ".md", ".json", ".txt", ".html", ".jsonl", ".yaml", ".log", ".sha256", ""}
# the host name of the node appears in a few raw logs (a sudo warning): replaced, nothing else is changed
SCRUB = re.compile(rb"unable to resolve host \S+")
def main():
if DEST.exists():
shutil.rmtree(DEST)
DEST.mkdir(parents=True)
for name in TOP:
shutil.copy(ROOT / "release_src" / name, DEST / name)
for pic in sorted((ROOT / "release_src" / "assets").glob("*.png")): # the pictures on the card
(DEST / "assets").mkdir(exist_ok=True)
shutil.copy(pic, DEST / "assets" / pic.name)
sys.path.insert(0, str(ROOT / "tools"))
import card
(DEST / "README.md").write_text(card.fill((DEST / "README.md").read_text(encoding="utf-8"), str(ROOT / "results")), encoding="utf-8", newline="\n")
missing = []
if os.environ.get("INCLUDE_DRAFTER") != "1":
pass # the default: no weights in the release; the engine prepares the drafter itself
elif (DRAFTER / "model.safetensors").exists():
(DEST / "drafter").mkdir()
sha = hashlib.sha256()
with open(DRAFTER / "model.safetensors", "rb") as f:
for block in iter(lambda: f.read(1 << 24), b""):
sha.update(block)
(DEST / "drafter" / "README.md").write_text((ROOT / "release_src" / "drafter_README.md").read_text(encoding="utf-8")
.replace("@@DRAFTER_SHA@@", sha.hexdigest()), encoding="utf-8", newline="\n")
shutil.copy(DRAFTER / "config.json", DEST / "drafter" / "config.json")
try:
os.link(DRAFTER / "model.safetensors", DEST / "drafter" / "model.safetensors") # a hard link, not a second copy
except OSError:
missing.append("drafter/model.safetensors (upload it from tmp/drafter)")
else:
missing.append("drafter/ (tmp/drafter/model.safetensors is not on this machine)")
for folder, names in CODE.items():
for n in names:
src = ROOT / folder / n
if not src.exists():
missing.append(f"{folder}/{n}")
continue
dst = DEST / folder / n
dst.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(src, dst)
# results: the result files as they are; every raw file behind them in one archive, results/data.zip
res = ROOT / "results"
stage = DEST / "results" / "_data"
for p in sorted(res.rglob("*")):
rel = p.relative_to(res)
if not p.is_file() or p.suffix not in (".md", ".json", ".jsonl", ".txt", ".sha256", ".log"):
continue
dst = (DEST / "results" / rel) if (p.suffix == ".md" and len(rel.parts) == 1) else (stage / rel)
dst.parent.mkdir(parents=True, exist_ok=True)
text = p.read_bytes()
text = SCRUB.sub(b"unable to resolve host the-node", text)
dst.write_bytes(text)
hits = []
for p in sorted(DEST.rglob("*")):
if p.is_file() and p.suffix in TEXT:
try:
text = p.read_text(encoding="utf-8")
except UnicodeDecodeError:
continue
for i, line in enumerate(text.splitlines(), 1):
m = FORBIDDEN.search(line) if FORBIDDEN else None
if m: # no file is exempt, this one included
hits.append(f"{p.relative_to(DEST)}:{i}: {m.group(0)}")
if not hits and stage.exists():
with zipfile.ZipFile(DEST / "results" / "data.zip", "w", zipfile.ZIP_DEFLATED) as z:
for p in sorted(stage.rglob("*")):
if p.is_file():
z.write(p, p.relative_to(stage).as_posix())
shutil.rmtree(stage)
files = [p for p in DEST.rglob("*") if p.is_file()]
size = sum(p.stat().st_size for p in files)
left = [m for m in re.findall(r"@@[A-Z0-9_]+@@", (DEST / "README.md").read_text(encoding="utf-8"))]
if left:
print("the card still has unfilled marks:", sorted(set(left)))
if missing:
print("missing (not copied):", missing)
if hits:
print(f"{len(hits)} internal names found, first ones:")
for h in hits[:25]:
print(" ", h)
sys.exit(1)
print(f"{DEST}: {len(files)} files, {size / 1e6:.1f} MB, " + ("no internal names found" if FORBIDDEN else "NAMES NOT CHECKED: tools/private_names.txt is missing"))
if __name__ == "__main__":
main()
|