Remove nested directory: BitTransformerLM/review_cli.py
Browse files
BitTransformerLM/review_cli.py
DELETED
|
@@ -1,49 +0,0 @@
|
|
| 1 |
-
import argparse
|
| 2 |
-
import json
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
|
| 5 |
-
import torch
|
| 6 |
-
from bit_transformer import BitTransformerLM
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def list_candidates(path: Path):
|
| 10 |
-
models = sorted(path.glob("*.pt"))
|
| 11 |
-
for m in models:
|
| 12 |
-
metrics_file = m.with_suffix(m.suffix + ".json")
|
| 13 |
-
metrics = {}
|
| 14 |
-
if metrics_file.exists():
|
| 15 |
-
with open(metrics_file) as f:
|
| 16 |
-
metrics = json.load(f)
|
| 17 |
-
yield m, metrics
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
def main():
|
| 21 |
-
parser = argparse.ArgumentParser(description="Review distilled submodels")
|
| 22 |
-
parser.add_argument("directory", type=Path, help="Directory with candidate models")
|
| 23 |
-
parser.add_argument("--approve-dir", type=Path, default=Path("approved"), help="Directory to store approved models")
|
| 24 |
-
args = parser.parse_args()
|
| 25 |
-
|
| 26 |
-
args.approve_dir.mkdir(exist_ok=True)
|
| 27 |
-
log_file = args.approve_dir / "review_log.jsonl"
|
| 28 |
-
|
| 29 |
-
for model_path, metrics in list_candidates(args.directory):
|
| 30 |
-
print("Candidate:", model_path.name)
|
| 31 |
-
for k, v in metrics.items():
|
| 32 |
-
print(f" {k}: {v}")
|
| 33 |
-
ans = input("Approve this model? [y/N] ").strip().lower()
|
| 34 |
-
if ans == "y":
|
| 35 |
-
approved_path = args.approve_dir / model_path.name
|
| 36 |
-
torch.save(torch.load(model_path), approved_path)
|
| 37 |
-
entry = {"model": approved_path.name, "metrics": metrics, "approved": True}
|
| 38 |
-
with open(log_file, "a") as lf:
|
| 39 |
-
lf.write(json.dumps(entry) + "\n")
|
| 40 |
-
print("Approved and saved to", approved_path)
|
| 41 |
-
else:
|
| 42 |
-
entry = {"model": model_path.name, "metrics": metrics, "approved": False}
|
| 43 |
-
with open(log_file, "a") as lf:
|
| 44 |
-
lf.write(json.dumps(entry) + "\n")
|
| 45 |
-
print("Rejected", model_path.name)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
if __name__ == "__main__":
|
| 49 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|