| """Claims 2, 3 and 6. |
| |
| Claim 2 (Thm 1 parameter regime). The theorem promises F^tr = o_d(1) under |
| n = Theta~(d^2 K), m = Omega~(d^8 K^4), eta*T = Theta(d^2). |
| m = d^8 K^4 is numerically unreachable (d=32, K=3 -> 8.7e13 neurons), so we |
| test the *asymptotic statement* instead: hold the prescribed n and eta*T |
| scalings, push d up, and check the forgetting decreases towards 0. We use the |
| exact linear-loss solver so that the width can be set large enough for the |
| third (width) term of Thm 1 to be numerically negligible, isolating the |
| d-dependence the theorem predicts. Controls relax each condition in turn. |
| |
| Claim 3 (Thm 2). After KT GD iterations the misclassification *train* error |
| and train loss are o_d(1) uniformly over all K tasks. Checked with the hinge |
| loss the theorem assumes. |
| |
| Claim 6 (decomposition). Test-time forgetting <= train-time forgetting + |
| delayed generalization gap, and the *joint* (not individual) control by n and |
| m: a 2-D grid where neither large n alone nor large m alone drives forgetting |
| down. |
| """ |
|
|
| 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 |
| from exp2_mechanism import exact_linear_run |
|
|
| OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "results") |
| os.makedirs(OUT, exist_ok=True) |
|
|
| DIMS = [12, 16, 24, 32, 48, 64] |
| SEEDS = list(range(5)) |
| M_BIG = 20_000 |
| K = 3 |
| C_N = 1.0 |
| C_T = 0.15 |
|
|
|
|
| def regime_job(job): |
| tag, d, seed = job |
| n = int(round(C_N * d * d * K)) |
| eta = 2.0 |
| T = max(5, int(round(C_T * d * d / eta))) |
| m = M_BIG |
| if tag == "prescribed": |
| pass |
| elif tag == "fixed_n": |
| n = int(round(C_N * 12 * 12 * K)) |
| elif tag == "long_train": |
| T = max(5, int(round(C_T * d ** 3 / (12 * eta)))) |
| elif tag == "small_m": |
| m = 300 |
| r = exact_linear_run(d=d, m=m, K=K, n=n, T=T, eta=eta, sigma_c=0.1, seed=seed) |
| r["sweep"] = "regime" |
| r["variant"] = tag |
| return r |
|
|
|
|
| def claim3_job(job): |
| """Hinge-loss GD; record per-task train loss / misclassification error.""" |
| d, m, n, K3, T, eta, seed = job |
| res = C.continual_run(d=d, m=m, K=K3, n=n, T=T, eta=eta, sigma_c=0.1, |
| loss_name="hinge", seed=seed, n_test=2000) |
| return dict( |
| sweep="claim3", d=d, m=m, n=n, K=K3, T=T, eta=eta, seed=seed, |
| loss_at=res["loss_at"].tolist(), |
| err_at=res["err_at"].tolist(), |
| test_loss_at=res["test_loss_at"].tolist(), |
| test_err_at=res["test_err_at"].tolist(), |
| forget=[C.train_forgetting(res, k) for k in range(K3)], |
| test_forget=[C.test_forgetting(res, k) for k in range(K3)], |
| gen_gap=[C.gen_gap(res, k) for k in range(K3)], |
| dist=list(res["dist"]), |
| ) |
|
|
|
|
| def claim6_job(job): |
| """(n, m) grid: joint control of forgetting.""" |
| n, m, seed = job |
| res = C.continual_run(d=50, m=m, K=3, n=n, T=200, eta=8.0, sigma_c=0.1, |
| loss_name="hinge", seed=seed, n_test=3000) |
| return dict( |
| sweep="claim6", n=n, m=m, seed=seed, d=50, K=3, T=200, eta=8.0, |
| loss_at=res["loss_at"].tolist(), |
| test_loss_at=res["test_loss_at"].tolist(), |
| forget=[C.train_forgetting(res, k) for k in range(3)], |
| test_forget=[C.test_forgetting(res, k) for k in range(3)], |
| gen_gap=[C.gen_gap(res, k) for k in range(3)], |
| err_at=res["err_at"].tolist(), |
| test_err_at=res["test_err_at"].tolist(), |
| ) |
|
|
|
|
| if __name__ == "__main__": |
| t0 = time.time() |
| recs = [] |
|
|
| jobs = [(tag, d, s) |
| for tag in ["prescribed", "fixed_n", "long_train", "small_m"] |
| for d in DIMS for s in SEEDS] |
| with Pool(C.NPROC) as p: |
| recs += list(p.imap_unordered(regime_job, jobs)) |
| print("regime done", f"{time.time()-t0:.0f}s", flush=True) |
|
|
| |
| |
| |
| j3 = [(50, m, n, 6, 200, eta, s) |
| for eta in [8.0, 2.0] |
| for m in [500, 2000] for n in [500, 2000] for s in range(4)] |
| with Pool(C.NPROC) as p: |
| recs += list(p.imap_unordered(claim3_job, j3)) |
| print("claim3 done", f"{time.time()-t0:.0f}s", flush=True) |
|
|
| |
| |
| |
| |
| j6 = [(n, m, s) |
| for n in [125, 500, 2000, 4000] |
| for m in [50, 200, 1000, 5000] |
| for s in range(3)] |
| with Pool(C.NPROC) as p: |
| recs += list(p.imap_unordered(claim6_job, j6)) |
| print("claim6 done", f"{time.time()-t0:.0f}s", flush=True) |
|
|
| with open(os.path.join(OUT, "exp3_regime.json"), "w") as f: |
| json.dump(recs, f) |
| print("wrote exp3_regime.json", f"{time.time()-t0:.0f}s") |
|
|