#!/usr/bin/env python3 """Upload all reproduction artifacts to Hugging Face. Model repos (MediumCNN, eta=0.4 lineage): t=0 teacher -> evalstate/cifar10-selftrain-teacher t=2 best iterate -> evalstate/cifar10-selftrain-best-iterate t=9 degraded iterate -> evalstate/cifar10-selftrain-degraded-iterate Dataset repo (all linear + CIFAR artifacts): -> evalstate/denoising-forgetting-linear-repro """ import os, json, glob from huggingface_hub import HfApi BASE = "/workspace/scratch/research" MDL = f"{BASE}/models" TRAJ = f"{BASE}/trajectories" CFG = f"{BASE}/configs" FIG = f"{BASE}/figures" api = HfApi() with open(f"{TRAJ}/cifar_trajectory.json") as f: traj = json.load(f) records = traj["records"] primary = [r for r in records if abs(r["eta"] - 0.4) < 1e-9] K = max(r["t"] for r in primary) tstar = min(primary, key=lambda r: r["test_error"])["t"] print(f"primary eta=0.4: K={K}, t*={tstar}") repos = { "teacher": ("evalstate/cifar10-selftrain-teacher", 0), "best": ("evalstate/cifar10-selftrain-best-iterate", tstar), "degraded": ("evalstate/cifar10-selftrain-degraded-iterate", K), } cards = { "teacher": """--- license: apache-2.0 tags: [self-training, self-distillation, cifar-10, denoising-forgetting] library_name: pytorch --- # CIFAR-10 Self-Training Teacher (iterate t=0) Small CNN (MediumCNN, ~1.56M params; **not** ResNet-50) trained as the **initial teacher** in a self-distillation trajectory reproducing the denoising-vs-forgetting trade-off from Wu, Yang & Sun, *Why Self-Training Helps and Hurts* (arXiv:2602.14029). ## Training config - Dataset: CIFAR-10 (via HF `uoft-cs/cifar10`), subset n=5000 - Label noise: symmetric, fraction eta=0.4 corrupted (injects initial stochastic error) - Optimizer: SGD (lr=0.1, momentum=0.9, wd=5e-4, nesterov) + cosine, 50 epochs, batch 256 - Augmentation: random crop (pad4, reflect) + horizontal flip + normalize ## Role This is the t=0 iterate (the weak teacher). Students t>=1 are trained from scratch on hard pseudo-labels from the previous iterate on disjoint subsets. The trajectory exhibits a U-shaped test-error curve (denoise then forget). See the report for full details. """, "best": """--- license: apache-2.0 tags: [self-training, self-distillation, cifar-10, denoising-forgetting] library_name: pytorch --- # CIFAR-10 Self-Training Best Iterate (generation t={t}) MediumCNN (~1.56M params): the **best-performing self-trained iterate** in a self-distillation trajectory reproducing the denoising-vs-forgetting trade-off (Wu, Yang & Sun, arXiv:2602.14029). This iterate is the minimum of the U-shaped test-error curve (the denoising-dominant optimum before signal forgetting dominates). Trained from scratch on hard pseudo-labels from iterate {tprev} on a disjoint CIFAR-10 subset (n=5000, eta=0.4 lineage). ## Metrics (test set) - test accuracy: {acc:.2f}% (teacher t=0: {acc0:.2f}%) - test error: {err:.2f}% - mean top-1 confidence: {conf:.3f} """, "degraded": """--- license: apache-2.0 tags: [self-training, self-distillation, cifar-10, denoising-forgetting] library_name: pytorch --- # CIFAR-10 Self-Training Final Degraded Iterate (generation t={t}) MediumCNN (~1.56M params): the **final degraded iterate** (last generation t=K={t}) in a self-distillation trajectory reproducing the denoising-vs-forgetting trade-off (Wu, Yang & Sun, arXiv:2602.14029). Illustrates the signal-forgetting regime: after the optimal stopping point (t*={tstar}), continued self-training on pseudo-labels progressively erodes signal and degrades test accuracy, while confidence keeps rising (miscalibration). ## Metrics (test set) - test accuracy: {acc:.2f}% (best t={tstar}: {accbest:.2f}%) - test error: {err:.2f}% - mean top-1 confidence: {conf:.3f} """, } rec0 = next(r for r in primary if r["t"] == 0) recbest = next(r for r in primary if r["t"] == tstar) for role, (repo, t) in repos.items(): src = f"{MDL}/iter_medium_eta0p4_t{t}.pth" assert os.path.exists(src), f"missing {src}" rec = next(r for r in primary if r["t"] == t) cfg = {"role": role, "iterate": t, "eta": rec["eta"], "n": rec["n"], "K": rec["K"], "epochs": rec["epochs"], "arch": rec["arch"], "seed": rec["seed"], "label_source": rec["label_source"], "test_acc": rec["test_acc"], "test_error": rec["test_error"], "mean_conf": rec["mean_conf"], "agreement_with_prev": rec["agreement_with_prev"], "architecture": "MediumCNN(4 conv blocks 64/128/256/512 + GAP, ~1.56M params)", "is_best_iterate": role == "best", "is_final_iterate": role == "degraded", "lineage": "eta=0.4 weak-teacher trajectory", "best_iterate_t": tstar} with open(f"/tmp/{role}_config.json", "w") as f: json.dump(cfg, f, indent=2) card_text = cards[role].format( t=t, tprev=t - 1, tstar=tstar, acc=rec["test_acc"], err=rec["test_error"], conf=rec["mean_conf"], acc0=rec0["test_acc"], accbest=recbest["test_acc"]) with open(f"/tmp/{role}_card.md", "w") as f: f.write(card_text) api.upload_file(path_or_fileobj=src, path_in_repo="model.pth", repo_id=repo, repo_type="model") api.upload_file(path_or_fileobj=f"/tmp/{role}_config.json", path_in_repo="config.json", repo_id=repo, repo_type="model") api.upload_file(path_or_fileobj=f"/tmp/{role}_card.md", path_in_repo="README.md", repo_id=repo, repo_type="model") print(f" uploaded {role} (t={t}) -> {repo} acc={rec['test_acc']:.2f}%") # ---- dataset repo: all linear + CIFAR artifacts ---- DS = "evalstate/denoising-forgetting-linear-repro" upload_files = [] upload_files += [(p, p.replace(BASE + "/", "")) for p in glob.glob(f"{TRAJ}/*.csv")] upload_files += [(p, p.replace(BASE + "/", "")) for p in glob.glob(f"{TRAJ}/*.json")] upload_files += [(p, p.replace(BASE + "/", "")) for p in glob.glob(f"{CFG}/*.json")] upload_files += [(p, p.replace(BASE + "/", "")) for p in glob.glob(f"{BASE}/*.py")] upload_files += [(p, p.replace(BASE + "/", "")) for p in glob.glob(f"{FIG}/*.png")] upload_files += [(f"{BASE}/part1_log.txt", "part1_log.txt")] upload_files += [(f"{BASE}/part1_summary.txt", "part1_summary.txt")] upload_files += [(f"{TRAJ}/cifar_trajectory_ep15.csv", "trajectories/cifar_trajectory_ep15.csv")] upload_files += [(f"{TRAJ}/cifar_trajectory_ep15.json", "trajectories/cifar_trajectory_ep15.json")] upload_files += [(f"{BASE}/cifar_ep15_log.txt", "cifar_ep15_log.txt")] for fpath, arc in upload_files: if os.path.exists(fpath): api.upload_file(path_or_fileobj=fpath, path_in_repo=arc, repo_id=DS, repo_type="dataset") print(f"uploaded {len(upload_files)} files to dataset {DS}") print("UPLOAD_DONE")