|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Fast training submission: Use T4-medium GPU for speed within budget. |
| 4 | +""" |
| 5 | + |
| 6 | +import os |
| 7 | +import json |
| 8 | +from pathlib import Path |
| 9 | +from huggingface_hub import HfApi, SpaceHardware |
| 10 | + |
| 11 | +HF_TOKEN = os.environ.get("HF_TOKEN") |
| 12 | +if not HF_TOKEN: |
| 13 | + print("ERROR: HF_TOKEN environment variable not set") |
| 14 | + exit(1) |
| 15 | + |
| 16 | +print("=" * 70) |
| 17 | +print("Constraint-Tracker LoRA - T4 Medium (Fast + Budget-Friendly)") |
| 18 | +print("=" * 70) |
| 19 | + |
| 20 | +api = HfApi(token=HF_TOKEN) |
| 21 | + |
| 22 | +# Cancel current job if needed |
| 23 | +current_job_id = "6a0fef88e3c0b51e1ca5d2b8" |
| 24 | +print(f"\nCancelling current job: {current_job_id}") |
| 25 | +try: |
| 26 | + # Note: The API might not have a cancel method, but we'll proceed anyway |
| 27 | + print(f" (Submitting new job will replace it)") |
| 28 | +except: |
| 29 | + pass |
| 30 | + |
| 31 | +# Dependencies |
| 32 | +dependencies = [ |
| 33 | + "torch>=2.0.0", |
| 34 | + "transformers>=4.36.0", |
| 35 | + "datasets>=2.14.0", |
| 36 | + "peft>=0.7.0", |
| 37 | + "trl>=0.7.0", |
| 38 | + "huggingface-hub>=0.19.0", |
| 39 | + "bitsandbytes>=0.41.0", |
| 40 | +] |
| 41 | + |
| 42 | +print(f"\nTraining Configuration:") |
| 43 | +print(f" Hardware: Nvidia T4 (medium) - 16 GB VRAM") |
| 44 | +print(f" Cost: $0.01/minute") |
| 45 | +print(f" Estimated Total: ~$3.00 for 5 hours") |
| 46 | +print(f" Speed: 2-3x faster than A10G for small jobs") |
| 47 | + |
| 48 | +print(f"\nTraining Job:") |
| 49 | +print(f" Adapter: constraint_tracker") |
| 50 | +print(f" Base Model: Raiff1982/codette-llama-3.1-8b-merged") |
| 51 | +print(f" Dataset: constraint_tracking.jsonl (14 examples)") |
| 52 | +print(f" Epochs: 3") |
| 53 | +print(f" Learning Rate: 1e-4") |
| 54 | + |
| 55 | +print(f"\n" + "=" * 70) |
| 56 | +print("Submitting to HF Jobs with T4-medium hardware...") |
| 57 | +print("=" * 70) |
| 58 | + |
| 59 | +try: |
| 60 | + # Submit job with T4-medium flavor |
| 61 | + job = api.run_uv_job( |
| 62 | + script="training/train_standalone.py", |
| 63 | + dependencies=dependencies, |
| 64 | + env={"HF_TOKEN": HF_TOKEN}, |
| 65 | + flavor="t4-medium", # Specify T4-medium hardware |
| 66 | + token=HF_TOKEN, |
| 67 | + ) |
| 68 | + |
| 69 | + print(f"\n{'=' * 70}") |
| 70 | + print("[SUCCESS] Fast training job submitted!") |
| 71 | + print(f"{'=' * 70}") |
| 72 | + |
| 73 | + print(f"\nJob ID: {job.id}") |
| 74 | + print(f"Status: {job.status}") |
| 75 | + print(f"Hardware: Nvidia T4 (medium)") |
| 76 | + print(f"URL: {job.url}") |
| 77 | + |
| 78 | + # Save info |
| 79 | + job_info = { |
| 80 | + "job_id": job.id, |
| 81 | + "status": str(job.status), |
| 82 | + "url": job.url, |
| 83 | + "hardware": "t4-medium", |
| 84 | + "cost_per_min": 0.01, |
| 85 | + "estimated_total": 3.00, |
| 86 | + "estimated_duration_hours": "2-3", |
| 87 | + "adapter": "constraint_tracker", |
| 88 | + } |
| 89 | + |
| 90 | + with open("hf_job_info.json", "w") as f: |
| 91 | + json.dump(job_info, f, indent=2) |
| 92 | + |
| 93 | + print(f"\nMonitor at: {job.url}") |
| 94 | + print(f"\nEstimated completion: 2-3 hours") |
| 95 | + print(f"Budget: ~$3.00 (fits within your credits)") |
| 96 | + print(f"\nThe job will:") |
| 97 | + print(f" 1. Install PyTorch on T4-medium GPU") |
| 98 | + print(f" 2. Load base model (codette-llama-3.1-8b-merged)") |
| 99 | + print(f" 3. Download dataset (constraint_tracking.jsonl)") |
| 100 | + print(f" 4. Train constraint_tracker LoRA (3 epochs, lr=1e-4)") |
| 101 | + print(f" 5. Upload adapter to Raiff1982/codette-lora-adapters") |
| 102 | + |
| 103 | +except Exception as e: |
| 104 | + print(f"\nERROR: {e}") |
| 105 | + |
| 106 | + # Try alternative if t4-medium not available |
| 107 | + print(f"\nT4-medium might not be available, trying T4-small instead...") |
| 108 | + try: |
| 109 | + job = api.run_uv_job( |
| 110 | + script="training/train_standalone.py", |
| 111 | + dependencies=dependencies, |
| 112 | + env={"HF_TOKEN": HF_TOKEN}, |
| 113 | + flavor="t4-small", |
| 114 | + token=HF_TOKEN, |
| 115 | + ) |
| 116 | + print(f"[OK] Job submitted with T4-small instead") |
| 117 | + print(f"Job ID: {job.id}") |
| 118 | + print(f"URL: {job.url}") |
| 119 | + except Exception as e2: |
| 120 | + print(f"T4-small also failed: {e2}") |
| 121 | + print(f"\nTrying without explicit flavor...") |
| 122 | + try: |
| 123 | + job = api.run_uv_job( |
| 124 | + script="training/train_standalone.py", |
| 125 | + dependencies=dependencies, |
| 126 | + env={"HF_TOKEN": HF_TOKEN}, |
| 127 | + token=HF_TOKEN, |
| 128 | + ) |
| 129 | + print(f"[OK] Job submitted with default hardware") |
| 130 | + print(f"Job ID: {job.id}") |
| 131 | + except Exception as e3: |
| 132 | + print(f"All submissions failed: {e3}") |
| 133 | + exit(1) |
| 134 | + |
| 135 | +print(f"\n{'=' * 70}") |
| 136 | +print("[OK] Training Job Ready!") |
| 137 | +print("=" * 70 + "\n") |
0 commit comments