| """Claim 2, internal-consistency check: how large must eta*T actually be? |
| |
| Theorem 1/2 prescribe *simultaneously* |
| eta*T = Theta(d^2) and m = Omega~(d^8 K^4). |
| Those two are only compatible if the eta*T needed for the network to actually |
| fit a task does not grow with m. In this model gradient descent moves the |
| first layer multiplicatively, w_i <- (I + (eta a_i/sqrt(m)) A) w_i, so the |
| *effective* horizon is eta*T/sqrt(m): naively one expects the eta*T needed for |
| interpolation to grow like sqrt(m), which would contradict eta*T = Theta(d^2) |
| once m is pushed to d^8 K^4. |
| |
| This script measures it directly. For a *single* task we find the smallest |
| eta*T (scanning eta at fixed T) that drives the hinge training loss below a |
| threshold, as a function of d and m, and fits eta*T_needed ~ d^alpha m^beta. |
| Theorem 1's regime is self-consistent only if beta ~ 0 and alpha ~ 2. |
| """ |
|
|
| import json |
| import os |
| import sys |
| import time |
| from multiprocessing import Pool |
|
|
| import numpy as np |
|
|
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| import clcore as C |
|
|
| OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "results") |
| os.makedirs(OUT, exist_ok=True) |
|
|
| THRESH = 0.05 |
| T_FIXED = 50 |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| N_COARSE = 7 |
| N_BISECT = 4 |
| ETA_LO, ETA_HI = 0.05, 4000.0 |
|
|
|
|
| def _train_loss(d, m, n, eta, seed): |
| r = C.continual_run(d=d, m=m, K=1, n=n, T=T_FIXED, eta=float(eta), |
| sigma_c=0.1, loss_name="hinge", seed=seed, n_test=200) |
| L = float(r["loss_at"][0, 0]) |
| return L if np.isfinite(L) else np.inf |
|
|
|
|
| def probe(job): |
| """Smallest eta*T (scanning eta at fixed T) that gets hinge loss < THRESH. |
| |
| Coarse geometric bracket, then bisection in log(eta). Returns None if even |
| the largest eta in the grid fails to interpolate. |
| """ |
| d, m, seed = job |
| n = int(d * d) |
| rec = [] |
|
|
| lo_eta, hi_eta = None, None |
| for eta in np.geomspace(ETA_LO, ETA_HI, N_COARSE): |
| L = _train_loss(d, m, n, eta, seed) |
| rec.append((float(eta * T_FIXED), L if np.isfinite(L) else None)) |
| if L < THRESH: |
| hi_eta = float(eta) |
| break |
| lo_eta = float(eta) |
|
|
| if hi_eta is None: |
| return dict(sweep="etaT_needed", d=d, m=m, n=n, T=T_FIXED, seed=seed, |
| etaT_needed=None, curve=rec) |
|
|
| if lo_eta is not None: |
| for _ in range(N_BISECT): |
| mid = float(np.sqrt(lo_eta * hi_eta)) |
| L = _train_loss(d, m, n, mid, seed) |
| rec.append((float(mid * T_FIXED), L if np.isfinite(L) else None)) |
| if L < THRESH: |
| hi_eta = mid |
| else: |
| lo_eta = mid |
|
|
| return dict(sweep="etaT_needed", d=d, m=m, n=n, T=T_FIXED, seed=seed, |
| etaT_needed=float(hi_eta * T_FIXED), curve=rec) |
|
|
|
|
| if __name__ == "__main__": |
| jobs = [(d, m, s) |
| for d in [16, 24, 32, 48] |
| for m in [250, 1000, 4000, 16000] |
| for s in range(2)] |
| print(len(jobs), "probes", flush=True) |
| t0 = time.time() |
| with Pool(C.NPROC) as p: |
| recs = [] |
| for i, r in enumerate(p.imap_unordered(probe, jobs)): |
| recs.append(r) |
| print(f" {i+1}/{len(jobs)} d={r['d']} m={r['m']} " |
| f"etaT={r['etaT_needed']} {time.time()-t0:.0f}s", flush=True) |
| with open(os.path.join(OUT, "exp5_etaT.json"), "w") as f: |
| json.dump(recs, f) |
| print("done", f"{time.time()-t0:.0f}s") |
|
|