Buckets:

Mercity/policy-classifier / 05-11-progress /scripts /log_checkpoints_wandb.py
Rishik001's picture
download
raw
1.9 kB
"""Upload a finished run's adapter checkpoints, reports and predictions to its own W&B run as artifacts.
python scripts/log_checkpoints_wandb.py checkpoints/<run>
Resumes the run recorded in <run>/wandb_run.json, logs one model artifact per checkpoint
(checkpoint-<k>of4-step<N>, aliased "final" for final/) and one evaluation artifact with the
reports and prediction files.
"""
import json
import sys
from pathlib import Path
import wandb
run_dir = Path(sys.argv[1])
config = __import__("yaml").safe_load((run_dir / "resolved.yaml").read_text()) if (run_dir / "resolved.yaml").exists() else {}
info = json.loads((run_dir / "wandb_run.json").read_text())
parts = info["url"].rstrip("/").split("/")
entity, project = parts[-4], parts[-3]
run = wandb.init(entity=entity, project=project, id=info["id"], resume="must")
slug = run.name.replace("/", "-")
checkpoints = sorted(run_dir.glob("checkpoint-*of*-step*"), key=lambda p: int(p.name.split("of")[0].split("-")[1]))
for path in checkpoints + [run_dir / "final"]:
if not path.is_dir():
continue
artifact = wandb.Artifact(f"{slug}-adapter", type="model", metadata={"checkpoint": path.name, "config": config})
artifact.add_dir(str(path))
aliases = [path.name] + (["final", "latest"] if path.name == "final" else [])
run.log_artifact(artifact, aliases=aliases).wait()
print(f"logged {path.name}", flush=True)
evaluation = wandb.Artifact(f"{slug}-evaluation", type="evaluation")
for name in ("validation_report.json", "test_ood_report.json", "validation_predictions.jsonl",
"test_ood_predictions.jsonl", "hardware_metrics.json", "train_results.json", "trainer_state.json",
"resolved.yaml", "smoke_summary.json"):
if (run_dir / name).exists():
evaluation.add_file(str(run_dir / name))
run.log_artifact(evaluation).wait()
print("logged evaluation", flush=True)
wandb.finish()

Xet Storage Details

Size:
1.9 kB
·
Xet hash:
254c1245efeb0484fd6d021b4cd079a02e2ce55c2bab79e7f8c3d21aa1d83961

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.