Download code/scripts/smoke_test.py from eduzrh/LNPBench: direct link, hf CLI and curl.
- Browser
- Download file 1.78 kB
-
https://huggingface.co/datasets/eduzrh/LNPBench/resolve/4168d53fc6eb5ca3fc229a71f6501bdffe77af08/code/scripts/smoke_test.py
- Command line
-
hf download hf://datasets/eduzrh/LNPBench@4168d53fc6eb5ca3fc229a71f6501bdffe77af08/code/scripts/smoke_test.py
-
curl -L -o smoke_test.py https://huggingface.co/datasets/eduzrh/LNPBench/resolve/4168d53fc6eb5ca3fc229a71f6501bdffe77af08/code/scripts/smoke_test.py
1.78 kB
| """Fast end-to-end smoke test: every model must train and predict on a tiny task.""" | |
| from __future__ import annotations | |
| import argparse | |
| import traceback | |
| import numpy as np | |
| import torch | |
| from lnpbench import data, metrics, paths | |
| from lnpbench.registry import REGISTRY, build_model | |
| from lnpbench.store import FeatureStore | |
| from lnpbench.trainer import TrainConfig | |
| def main() -> None: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--models", nargs="+", default=None) | |
| ap.add_argument("--n-train", type=int, default=1500) | |
| ap.add_argument("--epochs", type=int, default=2) | |
| ap.add_argument("--device", default="cpu") | |
| args = ap.parse_args() | |
| store = FeatureStore() | |
| tasks = data.load_tasks(paths.CACHE_DIR / "tasks.pkl") | |
| task = [t for t in tasks if t.name == "BL_2023_fold0"][0] | |
| rng = np.random.default_rng(0) | |
| train_idx = np.sort(rng.choice(task.train_idx, size=min(args.n_train, len(task.train_idx)), replace=False)) | |
| test_idx = task.test_idx[:200] | |
| models = args.models or list(REGISTRY) | |
| failures = [] | |
| for name in models: | |
| try: | |
| model = build_model(name) | |
| cfg = TrainConfig(epochs=args.epochs, batch_size=128, device=args.device, seed=0, patience=99) | |
| model.fit(store, train_idx, val_idx=test_idx, cfg=cfg) | |
| pred = model.predict(store, test_idx) | |
| rho = metrics.spearman(store.y[test_idx], pred) | |
| print(f"OK {name:24s} rho={rho:.4f} pred_mean={pred.mean():.3f} n={len(pred)}", flush=True) | |
| except Exception as exc: # noqa: BLE001 | |
| failures.append(name) | |
| print(f"FAIL {name}: {exc}") | |
| traceback.print_exc() | |
| print("\nfailures:", failures if failures else "none") | |
| if __name__ == "__main__": | |
| main() |