Download auto-impl/scripts/compose_artifacts.py from Jerry999/RSIChallenge: direct link, hf CLI and curl.
- Browser
- Download file 17.7 kB
-
https://huggingface.co/datasets/Jerry999/RSIChallenge/resolve/main/auto-impl/scripts/compose_artifacts.py
- Command line
-
hf download hf://datasets/Jerry999/RSIChallenge/auto-impl/scripts/compose_artifacts.py
-
curl -L -o compose_artifacts.py https://huggingface.co/datasets/Jerry999/RSIChallenge/resolve/main/auto-impl/scripts/compose_artifacts.py
17.7 kB
| #!/usr/bin/env python3 | |
| """Gather the artifacts worth keeping from auto-impl and RSIChallenge into one | |
| upload-ready tree. | |
| The output is a single self-describing folder that can be pushed to the | |
| HuggingFace dataset repo `Jerry999/RSIChallenge` by | |
| `scripts/upload_artifacts_hf.sh`, and that is also the thing to hand to the | |
| babel server or to a future reader who has neither cluster. | |
| Move or copy -- and why it differs per artifact | |
| ----------------------------------------------- | |
| The instruction was to *move*, not copy, so that we end up with one organised | |
| home for each file rather than a second scattered duplicate. That is right for | |
| run artifacts. It is wrong for anything git tracks, and it is wrong for a file | |
| a live pipeline still opens. So the rule is applied per artifact: | |
| MOVE, no symlink `solve_out_sanitized.txt`, `solve_parsed_sanitized.txt` | |
| These are byte-identical duplicates of the unsanitized | |
| files next to them (verified across every run: 40/40 | |
| identical, and the upstream sanitizer only redacts values | |
| from `.env`, none of which appear). The unsanitized copy | |
| stays where the analysis pipeline reads it, the duplicate | |
| moves here. This genuinely reclaims space and breaks | |
| nothing. | |
| MOVE + symlink `metrics.json`, `prompt.txt`, `time_taken.txt`, | |
| `final_eval_*.txt`, and the RSIChallenge run directories. | |
| Single copies that `analysis/` and the RSIChallenge | |
| scripts still open by path, so the original path is left | |
| pointing into this tree. Nothing is duplicated and | |
| nothing breaks. `--undo` reverses it. | |
| COPY Documents and code under git. Moving them would delete | |
| them from a tracked working tree, which is never what | |
| "tidy up" means. Git already stores them once; the copy | |
| here exists so the dataset stands alone. | |
| Deliberately left out | |
| --------------------- | |
| `final_model/` the trained checkpoints. Hundreds of GB across 168 runs. | |
| `agent_home/`, `task/` | |
| the agent's workspace and the training data it built -- | |
| tens of GB, and `task/` holds benchmark test items that | |
| were deliberately placed there for the contamination | |
| self-check. Publishing it would redistribute test data. | |
| `hf_cache/`, `containers/`, `apptainer/` | |
| third-party weights and images, not ours to publish. | |
| `_aborted_*` preempted stubs with no `metrics.json`. Counted in the | |
| manifest, not shipped. | |
| Nothing is uploaded from here. This machine's sandbox cannot reach | |
| huggingface.co; the upload is a separate script the user runs. | |
| python scripts/compose_artifacts.py --dry-run # plan only, touch nothing | |
| python scripts/compose_artifacts.py # build the tree | |
| python scripts/compose_artifacts.py --undo # put the moved files back | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import hashlib | |
| import json | |
| import os | |
| import re | |
| import shutil | |
| import sys | |
| from datetime import datetime, timezone | |
| from pathlib import Path | |
| LUSTRE = Path("/lustre-storage/fsx_2/user/jiaruiliu/ptb-data") | |
| HOME = Path("/home/jiaruiliu") | |
| REPOS = HOME / "local/git-repos" | |
| # Staging lives on the same filesystem as the bulk of the sources, so the | |
| # moves are renames rather than copies. | |
| DEFAULT_STAGING = Path("/lustre-storage/fsx_2/user/jiaruiliu/hf_upload/RSIChallenge") | |
| # (label, source root, destination under auto-impl/runs/) | |
| PTB_SWEEPS = [ | |
| ("claude_run1", LUSTRE / "results/claude_non_api_claude-opus-5_10h_run1", "claude_opus5_10h_run1"), | |
| ("claude_run2", LUSTRE / "results/claude_non_api_claude-opus-5_10h_run2", "claude_opus5_10h_run2"), | |
| ("codex_run1", LUSTRE / "results_codex_sdk_gpt-5.6-sol_20261006/codex_sdk_gpt-5.6-sol_10h_run1", | |
| "codex_gpt56sol_10h_run1"), | |
| ("direct_baseline", LUSTRE / "results/baseline_direct_inference_zeroshot", "direct_inference_zeroshot"), | |
| ] | |
| # filename in the run dir -> filename in the staged tree. The two `_sanitized` | |
| # entries are the de-duplicating moves; the rest are moved with a symlink left | |
| # behind. `final_eval_*.txt` is handled separately because it is a glob. | |
| MOVE_DEDUP = {"solve_out_sanitized.txt": "trace.txt", | |
| "solve_parsed_sanitized.txt": "trace_parsed.txt"} | |
| MOVE_SYMLINK = {"metrics.json": "metrics.json", | |
| "prompt.txt": "prompt.txt", | |
| "time_taken.txt": "time_taken.txt"} | |
| SECRET_PATTERNS = [ | |
| re.compile(rb"sk-[A-Za-z0-9_-]{20,}"), | |
| re.compile(rb"ghp_[A-Za-z0-9]{20,}"), | |
| re.compile(rb"hf_[A-Za-z0-9]{20,}"), | |
| re.compile(rb"AKIA[0-9A-Z]{12,}"), | |
| re.compile(rb"-----BEGIN [A-Z ]*PRIVATE KEY"), | |
| re.compile(rb"eyJ[A-Za-z0-9_-]{30,}\.[A-Za-z0-9_-]{20,}\."), # JWT | |
| ] | |
| # Filenames that must never be staged whatever else matches. | |
| NEVER = re.compile(r"(^|/)(\.env|oauth_token|api_keys\.json|\.netrc|id_rsa|token)$") | |
| class Plan: | |
| """Collects what will happen so --dry-run and the real run share one path.""" | |
| def __init__(self, dry: bool): | |
| self.dry = dry | |
| self.moved: list[tuple[str, str, bool]] = [] # src, dst, symlink_back | |
| self.copied: list[tuple[str, str]] = [] | |
| self.skipped: dict[str, int] = {} | |
| def skip(self, why: str) -> None: | |
| self.skipped[why] = self.skipped.get(why, 0) + 1 | |
| def move(self, src: Path, dst: Path, symlink_back: bool) -> None: | |
| if NEVER.search(str(src)): | |
| self.skip("credential-shaped filename") | |
| return | |
| self.moved.append((str(src), str(dst), symlink_back)) | |
| if self.dry: | |
| return | |
| dst.parent.mkdir(parents=True, exist_ok=True) | |
| if dst.exists(): # idempotent re-run | |
| if src.is_symlink(): | |
| return | |
| dst.unlink() | |
| shutil.move(str(src), str(dst)) # rename when same fs, copy+unlink otherwise | |
| if symlink_back: | |
| src.symlink_to(dst) | |
| def copy(self, src: Path, dst: Path) -> None: | |
| if NEVER.search(str(src)): | |
| self.skip("credential-shaped filename") | |
| return | |
| self.copied.append((str(src), str(dst))) | |
| if self.dry: | |
| return | |
| dst.parent.mkdir(parents=True, exist_ok=True) | |
| if src.is_dir(): | |
| shutil.copytree(src, dst, dirs_exist_ok=True, | |
| ignore=shutil.ignore_patterns(".git", "__pycache__", "*.pyc", | |
| ".env", "oauth_token", "api_keys.json")) | |
| else: | |
| shutil.copy2(src, dst) | |
| def stage_ptb_runs(plan: Plan, staging: Path) -> dict: | |
| """Per-run artifacts from the four PostTrainBench sweeps.""" | |
| stats = {} | |
| for label, root, destname in PTB_SWEEPS: | |
| if not root.is_dir(): | |
| plan.skip(f"missing sweep root {label}") | |
| continue | |
| kept = aborted = 0 | |
| for run in sorted(p for p in root.iterdir() if p.is_dir()): | |
| if run.name.startswith("_aborted"): | |
| aborted += len(list(run.iterdir())) | |
| continue | |
| # `_extra_completions_*` holds genuine completed repeats; descend. | |
| groups = [run] if not run.name.startswith("_") else sorted( | |
| p for p in run.iterdir() if p.is_dir()) | |
| for d in groups: | |
| if not (d / "metrics.json").is_file(): | |
| plan.skip("run without metrics.json") | |
| continue | |
| tag = d.name if d is run else f"extra/{d.name}" | |
| out = staging / "auto-impl/runs" / destname / tag | |
| for name, newname in MOVE_DEDUP.items(): | |
| if (d / name).is_file() and not (d / name).is_symlink(): | |
| plan.move(d / name, out / newname, symlink_back=False) | |
| for name, newname in MOVE_SYMLINK.items(): | |
| if (d / name).is_file() and not (d / name).is_symlink(): | |
| plan.move(d / name, out / newname, symlink_back=True) | |
| for ev in sorted(d.glob("final_eval_*.txt")): | |
| if not ev.is_symlink(): | |
| plan.move(ev, out / ev.name, symlink_back=True) | |
| kept += 1 | |
| stats[label] = {"runs_staged": kept, "aborted_entries_skipped": aborted} | |
| return stats | |
| def stage_repo(plan: Plan, repo: Path, staging: Path, subdirs: list[str]) -> None: | |
| for sub in subdirs: | |
| src = repo / sub | |
| if src.exists(): | |
| plan.copy(src, staging / repo.name / sub) | |
| def stage_rsi_runs(plan: Plan, staging: Path) -> None: | |
| """RSIChallenge run outputs: moved wholesale, with the original path symlinked.""" | |
| base = HOME / "rsi_runs" | |
| if not base.is_dir(): | |
| plan.skip("no rsi_runs directory") | |
| return | |
| for sub in sorted(p for p in base.iterdir() if p.is_dir()): | |
| if sub.is_symlink(): | |
| continue | |
| plan.move(sub, staging / "RSIChallenge/rsi_runs" / sub.name, symlink_back=True) | |
| def scan_secrets(staging: Path, limit_mb: int = 64) -> list[str]: | |
| """Grep the staged tree for credential-shaped strings. Gate, not decoration.""" | |
| hits = [] | |
| for p in staging.rglob("*"): | |
| if not p.is_file() or p.is_symlink(): | |
| continue | |
| if p.stat().st_size > limit_mb * 1024 * 1024: | |
| hits.append(f"{p} (NOT SCANNED: larger than {limit_mb} MB)") | |
| continue | |
| try: | |
| blob = p.read_bytes() | |
| except OSError: | |
| continue | |
| for pat in SECRET_PATTERNS: | |
| if pat.search(blob): | |
| hits.append(f"{p} matches {pat.pattern.decode(errors='replace')}") | |
| break | |
| return hits | |
| def write_manifest(staging: Path, stats: dict, plan: Plan) -> dict: | |
| files = [p for p in staging.rglob("*") if p.is_file() and not p.is_symlink()] | |
| total = sum(p.stat().st_size for p in files) | |
| by_top: dict[str, dict] = {} | |
| for p in files: | |
| top = p.relative_to(staging).parts[0] | |
| e = by_top.setdefault(top, {"files": 0, "bytes": 0}) | |
| e["files"] += 1 | |
| e["bytes"] += p.stat().st_size | |
| manifest = { | |
| "composed_utc": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"), | |
| "composed_on": "aws server", | |
| "target_repo": "Jerry999/RSIChallenge (HuggingFace dataset)", | |
| "total_files": len(files), | |
| "total_bytes": total, | |
| "total_mb": round(total / 1048576, 1), | |
| "by_section": {k: {**v, "mb": round(v["bytes"] / 1048576, 1)} for k, v in sorted(by_top.items())}, | |
| "ptb_sweeps": stats, | |
| "moved": len(plan.moved), | |
| "copied": len(plan.copied), | |
| "skipped": plan.skipped, | |
| } | |
| (staging / "MANIFEST.json").write_text(json.dumps(manifest, indent=1)) | |
| return manifest | |
| README = """# RSIChallenge — artifacts / 工件集 | |
| **Composed on the aws server.** Source repos: [`auto-impl`](https://github.com/jiarui-liu/auto-impl) | |
| (PostTrainBench agent study) and `RSIChallenge` (recursive self-improvement study). | |
| Built by `scripts/compose_artifacts.py`; inventory in `MANIFEST.json`. | |
| ## 高层要点 / Takeaways | |
| 1. **这是两个项目的"可移植产物"合集** —— 能跨机器、跨时间复用的那部分: | |
| agent trace、逐 run 指标、分析中间产物、全部文档。 | |
| 2. **不含模型权重、agent 工作区和训练数据。** 前者有数百 GB,后者含被刻意放进沙箱的 | |
| benchmark 测试题(发布等于再分发测试集)。详见下面"未收录"。 | |
| 3. **trace 是核心资产**:168 个 run、每个 10 小时的自主研究过程,逐条工具调用与输出。 | |
| 4. 每个 run 目录自带 `metrics.json`(最终分数)与 `prompt.txt`(任务原文),可独立使用。 | |
| > This is the portable subset of two projects: agent traces, per-run metrics, analysis | |
| > intermediates and all documents. It deliberately excludes model weights, agent workspaces and | |
| > the training data the agents built — the last of those contains benchmark test items that were | |
| > placed in the sandbox on purpose for a contamination self-check, so publishing it would | |
| > redistribute test data. The traces are the asset: 168 runs of ten-hour autonomous research, | |
| > tool call by tool call. | |
| ## Layout / 结构 | |
| ``` | |
| auto-impl/ | |
| docs/ 研究文档:结果、综述、总报告(中英双语) | |
| analysis/ trace 分析管线的代码与产物(探针、噪声、泄漏审计) | |
| scripts/ 提交与复现脚本 | |
| runs/ | |
| claude_opus5_10h_run1/<task>_<model>_<timestamp>/ | |
| claude_opus5_10h_run2/... (第二个种子;extra/ 下是同配置重复) | |
| codex_gpt56sol_10h_run1/... | |
| direct_inference_zeroshot/... (不训练的基线) | |
| ├── trace.txt 完整 agent trace(每行一个事件,带 ISO 时间戳) | |
| ├── trace_parsed.txt 解析后的可读版本 | |
| ├── metrics.json 最终分数 | |
| ├── prompt.txt 给 agent 的任务原文 | |
| ├── final_eval_*.txt 评测日志 | |
| └── time_taken.txt | |
| RSIChallenge/ | |
| docs/ 研究文档 | |
| experiments/ 实验代码 | |
| rsi_runs/ run 产物(traces/ 与 substeps/) | |
| ``` | |
| ## 未收录,以及为什么 / What is not here | |
| | 未收录 | 原因 | | |
| |---|---| | |
| | `final_model/` | 168 个 run 的训练后权重,数百 GB | | |
| | `agent_home/`、`task/` | agent 工作区与它自己构建的训练数据;**`task/` 含 benchmark 测试题**(沙箱里刻意放的,供 agent 自查污染),发布等于再分发测试集 | | |
| | `hf_cache/`、容器镜像 | 第三方权重与镜像,不是我们的东西 | | |
| | `_aborted_*` | 被抢占的残缺 run,没有 `metrics.json`;数量记在 `MANIFEST.json` 里 | | |
| ## 可比性警告 / Caveats | |
| - `arenahardwriting` 与 `healthbench` 由**本地 Qwen3.6-27B** 评分,顶替 OpenAI `gpt-5-mini` | |
| (集群连不上)。**绝对值与已发表数字不可比** —— zero-shot 下本地 judge 给 0.034、论文给 0.095。 | |
| 两个 agent 用的是同一个替代 judge,所以**它们之间**可比。 | |
| - agent 沙箱是刻意**禁网**的(`--network=none`),上游官方设定是联网无限制。 | |
| - 逐格比较的 95% 噪声门槛是 **0.125**(跨 sweep)/ **0.084**(同 sweep 内); | |
| 小于它的分差不构成证据。方法见 `auto-impl/docs/results/seed_variance_run1_run2_2026-10.md`。 | |
| """ | |
| def main() -> None: | |
| ap = argparse.ArgumentParser(description=__doc__, | |
| formatter_class=argparse.RawDescriptionHelpFormatter) | |
| ap.add_argument("--staging", type=Path, default=DEFAULT_STAGING) | |
| ap.add_argument("--dry-run", action="store_true", help="print the plan, change nothing") | |
| ap.add_argument("--undo", action="store_true", help="restore files that were moved + symlinked") | |
| args = ap.parse_args() | |
| if args.undo: | |
| return undo(args.staging) | |
| plan = Plan(args.dry_run) | |
| if not args.dry_run: | |
| args.staging.mkdir(parents=True, exist_ok=True) | |
| stats = stage_ptb_runs(plan, args.staging) | |
| stage_repo(plan, REPOS / "auto-impl", args.staging, | |
| ["docs", "analysis", "scripts", "src", "CLAUDE.md"]) | |
| stage_repo(plan, REPOS / "RSIChallenge", args.staging, | |
| ["docs", "experiments", "scripts", "CLAUDE.md"]) | |
| stage_rsi_runs(plan, args.staging) | |
| print(f"{'PLAN (nothing changed)' if args.dry_run else 'COMPOSED'}") | |
| print(f" moved : {len(plan.moved)} ({sum(1 for *_, s in plan.moved if s)} with a symlink left behind)") | |
| print(f" copied : {len(plan.copied)}") | |
| for why, n in sorted(plan.skipped.items()): | |
| print(f" skipped: {n:5d} {why}") | |
| for label, s in stats.items(): | |
| print(f" {label:18s} {s['runs_staged']:3d} runs staged, " | |
| f"{s['aborted_entries_skipped']} aborted entries skipped") | |
| if args.dry_run: | |
| print(f"\nWould write to {args.staging}") | |
| return | |
| (args.staging / "README.md").write_text(README) | |
| manifest = write_manifest(args.staging, stats, plan) | |
| print(f"\n staged total: {manifest['total_files']} files, {manifest['total_mb']} MB") | |
| for k, v in manifest["by_section"].items(): | |
| print(f" {k:16s} {v['files']:6d} files {v['mb']:8.1f} MB") | |
| print("\nScanning the staged tree for credentials ...") | |
| hits = scan_secrets(args.staging) | |
| gate = args.staging / ".secret-scan-passed" | |
| if hits: | |
| gate.unlink(missing_ok=True) | |
| print(f" FAILED -- {len(hits)} suspicious file(s). Upload is blocked:") | |
| for h in hits[:20]: | |
| print(f" {h}") | |
| sys.exit(1) | |
| gate.write_text(manifest["composed_utc"] + "\n") | |
| print(" clean -- no credential-shaped strings found.") | |
| print(f"\nNext: bash scripts/upload_artifacts_hf.sh (run it on a machine that reaches huggingface.co)") | |
| def undo(staging: Path) -> None: | |
| """Walk the original tree and pull every symlink-into-staging back home.""" | |
| restored = 0 | |
| for root in [p for _, p, _ in PTB_SWEEPS] + [HOME / "rsi_runs"]: | |
| if not root.exists(): | |
| continue | |
| for p in root.rglob("*"): | |
| if not p.is_symlink(): | |
| continue | |
| target = Path(os.readlink(p)) | |
| if staging not in target.parents: | |
| continue | |
| p.unlink() | |
| shutil.move(str(target), str(p)) | |
| restored += 1 | |
| print(f"restored {restored} path(s) from {staging}") | |
| print("note: the de-duplicated `*_sanitized.txt` copies are not restored -- " | |
| "their unsanitized twins were never moved and are byte-identical.") | |
| if __name__ == "__main__": | |
| main() | |