"""HF GPU Job: 24-seed sweep of the Figure 1 sparse-group panel at full 10,000-update scale. Why a GPU job for a small convex problem: these problems are small (p=60), so a GPU gives no per-run speedup over single-threaded CPU. The genuinely scaled thing a GPU buys here is a LARGE SEED SWEEP. The pinned upstream notebook does not seed Torch, so the HJ arm is stochastic and a single endpoint cannot confirm or refute the printed value. 24 seeds characterise that distribution far better than the 5 already run locally. This arm runs in a DIFFERENT environment from the locked single-threaded CPU arm and is therefore NOT byte-comparable with it. The observed runtime is recorded per seed. """ import json import subprocess import sys from pathlib import Path BUNDLE = "gwainste/hj-splitting-repro-bundle" SEEDS = [1, 2] # deliberately small: a T4 needs ~260 s/seed here, so this completes well inside the cap PRINTED_ANALYTICAL = 447.045 PRINTED_HJ = 447.388 BASE_ARGS = [ "--source-lock", "sources/upstream/dys-sparse-group-lasso.source-lock.json", "--runtime-lock", "environment/sparse-group-canary-runtime-lock.json", "--observations", "300", "--predictors", "60", "--group-size", "10", "--groups", "6", "--group-correlation", "0.75", "--true-nonzero-indices", "2,5,23,26,29,45,53,54,55", "--noise-scale", "0.25", "--l1-base-weight", "0.15", "--group-base-weight", "0.01", "--step-multiplier", "0.0072", "--iterations", "10000", "--num-samples-l1", "10000", "--num-samples-group", "10000", "--delta-numerator", "1500000", "--delta-epsilon", "0.00001", "--source-delta-l1-argument", "0.15", "--source-delta-group-argument", "0.1", "--source-gamma-decay-argument", "1", "--source-gamma-min-multiplier", "0.005", "--analytical-tolerance", "1e-25", "--hj-tolerance", "1e-15", "--max-resamples", "32", "--numpy-fixture-seed", "42", "--hj-dtype", "float32", "--analytical-dtype", "float64", ] def main() -> int: subprocess.run([sys.executable, "-m", "pip", "install", "-q", "huggingface_hub"], check=True) from huggingface_hub import snapshot_download root = Path(snapshot_download(repo_id=BUNDLE, repo_type="dataset")) print(f"bundle: {root}", flush=True) # The experiment script imports provsleuth.pipeline.stage_checkpoint. Outside a # checkpoint-enabled ProvSleuth child the call is a no-op, but the import must resolve. wheel = root / "tooling" / "provsleuth-0.4.0-py3-none-any.whl" subprocess.run([sys.executable, "-m", "pip", "install", "-q", str(wheel)], check=True) import provsleuth # noqa: F401 fail loudly here rather than per-seed print("provsleuth wheel installed", flush=True) import torch device = "cuda" if torch.cuda.is_available() else "cpu" gpu = torch.cuda.get_device_name(0) if torch.cuda.is_available() else "none" print(f"torch {torch.__version__} | device {device} | gpu {gpu}", flush=True) work = Path("/tmp/sweep") work.mkdir(parents=True, exist_ok=True) for rel in ("sources/upstream/dys-sparse-group-lasso.source-lock.json", "environment/sparse-group-canary-runtime-lock.json", "repro/run_sparse_group_full.py"): dst = work / rel dst.parent.mkdir(parents=True, exist_ok=True) dst.write_bytes((root / rel).read_bytes()) rows = [] for seed in SEEDS: out = f"results/full-sparse-group-seed{seed}" cmd = [sys.executable, "-I", "repro/run_sparse_group_full.py", "--output-dir", out, *BASE_ARGS, "--torch-global-seed", str(seed), "--torch-generator-seed", str(seed), "--device", device] r = subprocess.run(cmd, cwd=work, capture_output=True, text=True) if r.returncode != 0: print(f"seed {seed} FAILED rc={r.returncode}\n{r.stderr[-1500:]}", flush=True) continue summary = json.loads((work / out / "summary.json").read_text(encoding="utf-8")) arms = summary["paper_comparison"]["arms"] rows.append({ "seed": seed, "analytical": arms["analytical"]["observed"], "hj": arms["hj"]["observed"], "runtime": summary.get("runtime"), }) vals = sorted(r["hj"] for r in rows) mu = sum(vals) / len(vals) print(f"seed {seed:>3}: analytical={rows[-1]['analytical']:.6f} " f"hj={rows[-1]['hj']:.6f} | running n={len(vals)} " f"mean={mu:.6f} min={vals[0]:.6f} max={vals[-1]:.6f} " f"printed_inside={vals[0] <= PRINTED_HJ <= vals[-1]}", flush=True) if not rows: print("NO SEEDS SUCCEEDED") return 1 hj = sorted(r["hj"] for r in rows) an = sorted(r["analytical"] for r in rows) n = len(hj) mean = sum(hj) / n var = sum((v - mean) ** 2 for v in hj) / n sd = var ** 0.5 inside = hj[0] <= PRINTED_HJ <= hj[-1] result = { "experiment": "figure1-sparse-group-gpu-seed-sweep", "paper": "arXiv:2601.22370v4", "updates": 10000, "seeds": n, "device": device, "gpu": gpu, "torch": torch.__version__, "analytical": { "printed": PRINTED_ANALYTICAL, "min": an[0], "max": an[-1], "deterministic_across_seeds": an[0] == an[-1], "reproduces_at_three_decimals": round(an[0], 3) == round(PRINTED_ANALYTICAL, 3), }, "hj": { "printed": PRINTED_HJ, "mean": mean, "sd": sd, "min": hj[0], "max": hj[-1], "printed_inside_observed_range": inside, }, "rows": rows, "boundary": ( "This GPU arm runs in a different environment from the locked single-threaded CPU " "arm and is not byte-comparable with it. The HJ arm is stochastic because the " "pinned upstream notebook does not seed Torch." ), } Path("/tmp/gpu_sweep_result.json").write_text(json.dumps(result, indent=2), encoding="utf-8") print("\n===== RESULT =====") print(json.dumps({k: v for k, v in result.items() if k != "rows"}, indent=2)) return 0 if __name__ == "__main__": raise SystemExit(main())