|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Submit constraint-tracker LoRA training job to HF Jobs by cloning the repo. |
| 4 | +This approach ensures all dependencies are available. |
| 5 | +""" |
| 6 | + |
| 7 | +import os |
| 8 | +import json |
| 9 | +from pathlib import Path |
| 10 | +from huggingface_hub import HfApi |
| 11 | + |
| 12 | +HF_TOKEN = os.environ.get("HF_TOKEN") |
| 13 | +if not HF_TOKEN: |
| 14 | + print("ERROR: HF_TOKEN environment variable not set") |
| 15 | + exit(1) |
| 16 | + |
| 17 | +print("=" * 70) |
| 18 | +print("Codette Constraint-Tracker LoRA - HF Jobs Submission (Git Clone)") |
| 19 | +print("=" * 70) |
| 20 | + |
| 21 | +# Configuration |
| 22 | +MODEL_REPO = "Raiff1982/codette-llama-3.1-8b-merged" |
| 23 | +DATASET_REPO = "Raiff1982/codette-training-data" |
| 24 | +OUTPUT_REPO = "Raiff1982/codette-lora-adapters" |
| 25 | + |
| 26 | +print(f"\nJob Configuration:") |
| 27 | +print(f" Base Model: {MODEL_REPO}") |
| 28 | +print(f" Dataset: constraint_tracking.jsonl") |
| 29 | +print(f" Adapter: constraint_tracker") |
| 30 | +print(f" Epochs: 3") |
| 31 | +print(f" Learning Rate: 1e-4") |
| 32 | +print(f" Output Repo: {OUTPUT_REPO}") |
| 33 | + |
| 34 | +print(f"\n" + "=" * 70) |
| 35 | +print("Submitting job to HF Jobs (cloning repo method)...") |
| 36 | +print("=" * 70) |
| 37 | + |
| 38 | +api = HfApi(token=HF_TOKEN) |
| 39 | + |
| 40 | +# Create job script that will: |
| 41 | +# 1. Install dependencies |
| 42 | +# 2. Clone the codette repo |
| 43 | +# 3. Run training |
| 44 | +job_script = """#!/bin/bash |
| 45 | +set -e |
| 46 | +
|
| 47 | +echo "==========================================" |
| 48 | +echo "HF Jobs Training Setup" |
| 49 | +echo "==========================================" |
| 50 | +
|
| 51 | +# Install dependencies |
| 52 | +echo "Installing dependencies..." |
| 53 | +pip install -q torch transformers datasets peft trl huggingface-hub bitsandbytes numpy |
| 54 | +
|
| 55 | +# Verify imports |
| 56 | +python -c "import torch; import transformers; import peft; print('Dependencies OK')" |
| 57 | +
|
| 58 | +# Clone the codette repo |
| 59 | +echo "Cloning Codette repo..." |
| 60 | +cd /tmp |
| 61 | +git clone https://huggingface.co/Raiff1982/codette-clean.git |
| 62 | +cd codette-clean |
| 63 | +
|
| 64 | +# Run training |
| 65 | +echo "" |
| 66 | +echo "==========================================" |
| 67 | +echo "Starting Constraint-Tracker LoRA Training" |
| 68 | +echo "==========================================" |
| 69 | +echo "" |
| 70 | +
|
| 71 | +export HF_TOKEN=$HF_TOKEN |
| 72 | +python training/train_hf_job.py |
| 73 | +""" |
| 74 | + |
| 75 | +print(f"\nJob script:") |
| 76 | +print(f" 1. Install all dependencies (torch, transformers, peft, trl, etc.)") |
| 77 | +print(f" 2. Clone codette repo from HF Hub") |
| 78 | +print(f" 3. Run training/train_hf_job.py with constraint_tracker adapter") |
| 79 | + |
| 80 | +try: |
| 81 | + # Submit the job using run_job with a simple Python image |
| 82 | + job = api.run_job( |
| 83 | + image="python:3.10", |
| 84 | + command=["/bin/bash", "-c", job_script], |
| 85 | + env={ |
| 86 | + "HF_TOKEN": HF_TOKEN, |
| 87 | + }, |
| 88 | + token=HF_TOKEN, |
| 89 | + ) |
| 90 | + |
| 91 | + print(f"\n{'=' * 70}") |
| 92 | + print("[SUCCESS] Job submitted successfully!") |
| 93 | + print(f"{'=' * 70}") |
| 94 | + |
| 95 | + print(f"\nJob Details:") |
| 96 | + print(f" Job ID: {job.id}") |
| 97 | + print(f" Status: {job.status}") |
| 98 | + print(f" URL: {job.url}") |
| 99 | + print(f" Repo: {OUTPUT_REPO}") |
| 100 | + |
| 101 | + # Save job info (convert status to string) |
| 102 | + job_info = { |
| 103 | + "job_id": job.id, |
| 104 | + "status": str(job.status), |
| 105 | + "url": job.url, |
| 106 | + "repo": OUTPUT_REPO, |
| 107 | + "base_model": MODEL_REPO, |
| 108 | + "dataset": "constraint_tracking.jsonl", |
| 109 | + "adapter": "constraint_tracker", |
| 110 | + "epochs": 3, |
| 111 | + "learning_rate": "1e-4", |
| 112 | + "method": "git-clone", |
| 113 | + } |
| 114 | + |
| 115 | + job_info_path = Path("hf_job_info.json") |
| 116 | + with open(job_info_path, "w") as f: |
| 117 | + json.dump(job_info, f, indent=2) |
| 118 | + |
| 119 | + print(f"\nJob info saved to: {job_info_path}") |
| 120 | + print(f"\n" + "=" * 70) |
| 121 | + print("TRAINING JOB SUBMITTED") |
| 122 | + print("=" * 70) |
| 123 | + print(f"\nMonitor at: {job.url}") |
| 124 | + print(f"Job will:") |
| 125 | + print(f" 1. Install dependencies") |
| 126 | + print(f" 2. Clone full Codette repo (with training script)") |
| 127 | + print(f" 3. Train constraint_tracker LoRA (3 epochs)") |
| 128 | + print(f" 4. Upload results to {OUTPUT_REPO}") |
| 129 | + print(f"\nEstimated time: 4-6 hours on A10G GPU") |
| 130 | + |
| 131 | +except Exception as e: |
| 132 | + print(f"\n{'=' * 70}") |
| 133 | + print("[ERROR] Job submission failed") |
| 134 | + print(f"{'=' * 70}") |
| 135 | + print(f"\nError: {e}") |
| 136 | + |
| 137 | + import traceback |
| 138 | + traceback.print_exc() |
| 139 | + |
| 140 | + exit(1) |
| 141 | + |
| 142 | +print(f"\n{'=' * 70}") |
| 143 | +print("[OK] Training Job Submitted!") |
| 144 | +print("=" * 70 + "\n") |
0 commit comments