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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Quick launcher for Pear1.5 hardware-agnostic training.
|
| 3 |
+
|
| 4 |
+
Usage:
|
| 5 |
+
python launch.py --platform colab
|
| 6 |
+
python launch.py --platform kaggle-t4
|
| 7 |
+
python launch.py --platform kaggle-tpu
|
| 8 |
+
python launch.py --platform local
|
| 9 |
+
python launch.py --platform all
|
| 10 |
+
"""
|
| 11 |
+
import argparse
|
| 12 |
+
import asyncio
|
| 13 |
+
import os
|
| 14 |
+
import sys
|
| 15 |
+
import subprocess
|
| 16 |
+
from pathlib import Path
|
| 17 |
+
|
| 18 |
+
# Add scripts to path
|
| 19 |
+
sys.path.insert(0, str(Path(__file__).parent))
|
| 20 |
+
|
| 21 |
+
from hardware import get_hardware_info, get_training_config, print_hardware_summary
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def launch_colab(notebook_path: str = None):
|
| 25 |
+
"""Launch on Colab via browser."""
|
| 26 |
+
url = "https://colab.research.google.com/drive/1BCLulJMl1xEErqRPbzn9caxH4wk56wBB"
|
| 27 |
+
print(f"Opening Colab: {url}")
|
| 28 |
+
print("1. Connect to runtime (Runtime -> Connect)")
|
| 29 |
+
print("2. Run the first cell to install dependencies")
|
| 30 |
+
print("3. Run the training cell")
|
| 31 |
+
|
| 32 |
+
if sys.platform == "win32":
|
| 33 |
+
os.system(f'start "" "{url}"')
|
| 34 |
+
elif sys.platform == "darwin":
|
| 35 |
+
os.system(f'open "{url}"')
|
| 36 |
+
else:
|
| 37 |
+
os.system(f'xdg-open "{url}"')
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def launch_kaggle(gpu_type: str = "t4"):
|
| 41 |
+
"""Launch on Kaggle."""
|
| 42 |
+
url = "https://www.kaggle.com/code/new"
|
| 43 |
+
print(f"Opening Kaggle: {url}")
|
| 44 |
+
print(f"1. Set accelerator to: {'TPU v5e-8' if gpu_type == 'tpu' else 'GPU T4 x2'}")
|
| 45 |
+
print("2. Add dataset: pear15-expanded-data")
|
| 46 |
+
print("3. Add HF_TOKEN secret")
|
| 47 |
+
print("4. Paste train_agnostic.py content into a cell and run")
|
| 48 |
+
|
| 49 |
+
if sys.platform == "win32":
|
| 50 |
+
os.system(f'start "" "{url}"')
|
| 51 |
+
elif sys.platform == "darwin":
|
| 52 |
+
os.system(f'open "{url}"')
|
| 53 |
+
else:
|
| 54 |
+
os.system(f'xdg-open "{url}"')
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def launch_lightning():
|
| 58 |
+
"""Launch on Lightning AI."""
|
| 59 |
+
url = "https://lightning.ai/tk8679a/studios"
|
| 60 |
+
print(f"Opening Lightning AI: {url}")
|
| 61 |
+
print("1. Create new Studio with A100")
|
| 62 |
+
print("2. Open terminal")
|
| 63 |
+
print("3. Run: pip install -r requirements.txt")
|
| 64 |
+
print("4. Run: python train_agnostic.py --data-path /data --output-dir /checkpoints")
|
| 65 |
+
|
| 66 |
+
if sys.platform == "win32":
|
| 67 |
+
os.system(f'start "" "{url}"')
|
| 68 |
+
elif sys.platform == "darwin":
|
| 69 |
+
os.system(f'open "{url}"')
|
| 70 |
+
else:
|
| 71 |
+
os.system(f'xdg-open "{url}"')
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def launch_local(args):
|
| 75 |
+
"""Launch training locally."""
|
| 76 |
+
print("Launching local training...")
|
| 77 |
+
|
| 78 |
+
cmd = [
|
| 79 |
+
sys.executable, "scripts/train_agnostic.py",
|
| 80 |
+
"--data-path", args.data_path,
|
| 81 |
+
"--output-dir", args.output_dir,
|
| 82 |
+
"--resume-from", args.resume_from,
|
| 83 |
+
]
|
| 84 |
+
|
| 85 |
+
if args.max_steps:
|
| 86 |
+
cmd.extend(["--max-steps", str(args.max_steps)])
|
| 87 |
+
if args.hf_model_path:
|
| 88 |
+
cmd.extend(["--hf-model-path", args.hf_model_path])
|
| 89 |
+
if args.seed:
|
| 90 |
+
cmd.extend(["--seed", str(args.seed)])
|
| 91 |
+
|
| 92 |
+
print(f"Running: {' '.join(cmd)}")
|
| 93 |
+
subprocess.run(cmd, cwd=Path(__file__).parent.parent)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def launch_all():
|
| 97 |
+
"""Launch on all available platforms."""
|
| 98 |
+
print("=" * 60)
|
| 99 |
+
print("LAUNCHING ON ALL PLATFORMS")
|
| 100 |
+
print("=" * 60)
|
| 101 |
+
|
| 102 |
+
# Detect local hardware
|
| 103 |
+
hw = get_hardware_info()
|
| 104 |
+
config = get_training_config(hw)
|
| 105 |
+
print_hardware_summary(hw, config)
|
| 106 |
+
|
| 107 |
+
# Launch local in background
|
| 108 |
+
print("\n1. Starting local training...")
|
| 109 |
+
import subprocess
|
| 110 |
+
local_proc = subprocess.Popen([
|
| 111 |
+
sys.executable, "scripts/train_agnostic.py",
|
| 112 |
+
"--data-path", "/content/pear15-expanded-data",
|
| 113 |
+
"--output-dir", "/content/checkpoints/local",
|
| 114 |
+
"--resume-from", "latest",
|
| 115 |
+
], cwd=Path(__file__).parent.parent)
|
| 116 |
+
|
| 117 |
+
# Open Colab
|
| 118 |
+
print("\n2. Opening Colab A100...")
|
| 119 |
+
launch_colab()
|
| 120 |
+
|
| 121 |
+
# Open Kaggle T4
|
| 122 |
+
print("\n3. Opening Kaggle T4...")
|
| 123 |
+
launch_kaggle("t4")
|
| 124 |
+
|
| 125 |
+
# Open Kaggle TPU
|
| 126 |
+
print("\n4. Opening Kaggle TPU v5e-8...")
|
| 127 |
+
launch_kaggle("tpu")
|
| 128 |
+
|
| 129 |
+
# Open Lightning
|
| 130 |
+
print("\n5. Opening Lightning AI...")
|
| 131 |
+
launch_lightning()
|
| 132 |
+
|
| 133 |
+
print("\n" + "=" * 60)
|
| 134 |
+
print("ALL PLATFORMS LAUNCHED")
|
| 135 |
+
print("=" * 60)
|
| 136 |
+
print("Monitor progress:")
|
| 137 |
+
print(" - Colab: Check notebook output")
|
| 138 |
+
print(" - Kaggle: Check notebook output")
|
| 139 |
+
print(" - Local: Check terminal output")
|
| 140 |
+
print(" - Checkpoints saved to respective output dirs")
|
| 141 |
+
print("\nPress Ctrl+C to stop local training")
|
| 142 |
+
|
| 143 |
+
try:
|
| 144 |
+
local_proc.wait()
|
| 145 |
+
except KeyboardInterrupt:
|
| 146 |
+
local_proc.terminate()
|
| 147 |
+
print("Stopped local training")
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def main():
|
| 151 |
+
parser = argparse.ArgumentParser(description="Pear1.5 Hardware-Agnostic Training Launcher")
|
| 152 |
+
parser.add_argument("--platform", choices=["colab", "kaggle-t4", "kaggle-tpu", "lightning", "local", "all"],
|
| 153 |
+
default="local", help="Platform to launch on")
|
| 154 |
+
parser.add_argument("--data-path", default="/content/pear15-expanded-data",
|
| 155 |
+
help="Path to expanded dataset")
|
| 156 |
+
parser.add_argument("--output-dir", default="/content/checkpoints",
|
| 157 |
+
help="Output directory for checkpoints")
|
| 158 |
+
parser.add_argument("--resume-from", default="latest",
|
| 159 |
+
help="Resume from checkpoint (step, 'latest', or path)")
|
| 160 |
+
parser.add_argument("--max-steps", type=int, default=None,
|
| 161 |
+
help="Maximum steps to run")
|
| 162 |
+
parser.add_argument("--hf-model-path", default=None,
|
| 163 |
+
help="HF model path for fresh init")
|
| 164 |
+
parser.add_argument("--seed", type=int, default=0)
|
| 165 |
+
args = parser.parse_args()
|
| 166 |
+
|
| 167 |
+
if args.platform == "colab":
|
| 168 |
+
launch_colab()
|
| 169 |
+
elif args.platform == "kaggle-t4":
|
| 170 |
+
launch_kaggle("t4")
|
| 171 |
+
elif args.platform == "kaggle-tpu":
|
| 172 |
+
launch_kaggle("tpu")
|
| 173 |
+
elif args.platform == "lightning":
|
| 174 |
+
launch_lightning()
|
| 175 |
+
elif args.platform == "local":
|
| 176 |
+
launch_local(args)
|
| 177 |
+
elif args.platform == "all":
|
| 178 |
+
launch_all()
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
if __name__ == "__main__":
|
| 182 |
+
main()
|