| """Smoke-test and train the 5k classifier on one Modal A100 80GB. | |
| modal run --detach --profile rishik00 -m training.modal_app --epochs 1.5 | |
| """ | |
| import json | |
| from datetime import datetime, timezone | |
| from pathlib import Path | |
| import modal | |
| import yaml | |
| app = modal.App("policy-nli-classifier") | |
| volume = modal.Volume.from_name("policy-nli-training", create_if_missing=True) | |
| image = ( | |
| modal.Image.debian_slim(python_version="3.12") | |
| .pip_install("torch==2.8.0", extra_index_url="https://download.pytorch.org/whl/cu128") | |
| .pip_install_from_requirements("training/requirements.txt") | |
| .env( | |
| { | |
| "HF_HOME": "/artifacts/huggingface", | |
| "TOKENIZERS_PARALLELISM": "false", | |
| "WANDB_DIR": "/artifacts/wandb", | |
| "PYTHONUNBUFFERED": "1", | |
| } | |
| ) | |
| .add_local_python_source("training") | |
| .add_local_dir("datasets/policy_5k", "/data/policy_5k", ignore=["rejected.jsonl"]) | |
| ) | |
| def train_remote(config, smoke_only=False): | |
| """Fail closed on smoke failure; the full run loads a fresh base model afterward.""" | |
| import subprocess | |
| import sys | |
| output = Path(config["output_dir"]) | |
| output.mkdir(parents=True, exist_ok=True) | |
| status_path = output / "status.json" | |
| def save_status(stage, **fields): | |
| status_path.write_text(json.dumps({"stage": stage, **fields}, indent=2), encoding="utf-8") | |
| volume.commit() | |
| training_script = ( | |
| "training.train_modernbert" if "modernbert" in config["model_name"].lower() else "training.train_qwen" | |
| ) | |
| config_path = output / "requested.yaml" | |
| config_path.write_text(yaml.safe_dump(config, sort_keys=False), encoding="utf-8") | |
| try: | |
| save_status("smoke") | |
| subprocess.run([sys.executable, "-m", "training.smoke", "--config", str(config_path)], check=True) | |
| summary = json.loads((output / "smoke_summary.json").read_text(encoding="utf-8")) | |
| save_status("smoke_complete" if smoke_only else "training", smoke=summary) | |
| if not smoke_only: | |
| subprocess.run( | |
| [sys.executable, "-m", training_script, "--config", str(output / "resolved.yaml")], | |
| check=True, | |
| ) | |
| save_status("complete", smoke=summary) | |
| return summary | |
| except Exception as error: | |
| save_status("failed", error=str(error)) | |
| raise | |
| finally: | |
| volume.commit() | |
| def main(epochs: float = 1.5, smoke_only: bool = False, config: str = "training/modernbert_large.yaml"): | |
| config = yaml.safe_load(Path(config).read_text(encoding="utf-8")) | |
| model_slug = config["model_name"].split("/")[-1].lower() | |
| run_id = model_slug + "-5k-" + datetime.now(timezone.utc).strftime("%Y%m%d-%H%M%S") | |
| config.update( | |
| data_dir="/data/policy_5k", output_dir="/artifacts/" + run_id, run_name=run_id, epochs=epochs | |
| ) | |
| local = Path("checkpoints") / run_id | |
| local.mkdir(parents=True, exist_ok=True) | |
| (Path("scratch") / "latest_modal_training.txt").write_text(run_id, encoding="utf-8") | |
| (local / "launch.json").write_text( | |
| json.dumps( | |
| { | |
| "profile": "rishik00", | |
| "volume": "policy-nli-training", | |
| "remote_output": config["output_dir"], | |
| "config": config, | |
| }, | |
| indent=2, | |
| ), | |
| encoding="utf-8", | |
| ) | |
| print("Remote artifacts: " + config["output_dir"]) | |
| summary = train_remote.remote(config, smoke_only) | |
| (local / "smoke_summary.json").write_text(json.dumps(summary, indent=2), encoding="utf-8") | |
| print(json.dumps(summary, indent=2)) | |
Xet Storage Details
- Size:
- 3.93 kB
- Xet hash:
- 52cce18ad79921fa39dd926be50a87aaf676d4eaaf3bbc22edfb6536f758ca2e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.