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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AgentDebuggerEnv β Project Handover
|
| 2 |
+
|
| 3 |
+
## What This Project Is
|
| 4 |
+
A GRPO-trained LLM (Qwen2.5-Coder-7B-Instruct) that learns to debug Python code through
|
| 5 |
+
structured hypothesis-driven reasoning. Submitted to the Meta + PyTorch + HuggingFace OpenEnv Hackathon.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## Repo & Remotes
|
| 10 |
+
|
| 11 |
+
| Remote | URL |
|
| 12 |
+
|---|---|
|
| 13 |
+
| GitHub (source of truth) | https://github.com/shasshaank/meta_hackthon.git |
|
| 14 |
+
| HF Training Space | https://huggingface.co/spaces/shashaank0707/AgentDebugger-training-v2 |
|
| 15 |
+
| HF Trained Model | https://huggingface.co/shashaank0707/AgentDebugger-trained |
|
| 16 |
+
|
| 17 |
+
Push to GitHub first, then to HF Space if needed:
|
| 18 |
+
```bash
|
| 19 |
+
git push origin main
|
| 20 |
+
git push space main --force # space remote = HF training space
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
The `space` remote URL includes your HF token:
|
| 24 |
+
```
|
| 25 |
+
https://shashaank0707:YOUR_HF_TOKEN@huggingface.co/spaces/shashaank0707/AgentDebugger-training-v2
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
---
|
| 29 |
+
|
| 30 |
+
## Project Structure
|
| 31 |
+
|
| 32 |
+
```
|
| 33 |
+
meta_hackathon/
|
| 34 |
+
βββ app.py # Gradio training monitor β launched by HF Space SDK
|
| 35 |
+
βββ training/
|
| 36 |
+
β βββ train_grpo.py # Main training script (GRPO via TRL)
|
| 37 |
+
βββ server/
|
| 38 |
+
β βββ reward_calculator.py # Multi-component reward (format, hypothesis, fix, semantic)
|
| 39 |
+
β βββ models.py # parse_agent_output() β parses structured LLM output
|
| 40 |
+
β βββ app.py # FastAPI server (for the inference/env Space, not training)
|
| 41 |
+
βββ data/
|
| 42 |
+
β βββ bugs_tier1.jsonl # 9 easy bugs (used steps 0β150)
|
| 43 |
+
β βββ bugs_tier2.jsonl # 31 medium bugs (added at step 150)
|
| 44 |
+
β βββ bugs_tier3.jsonl # 21 hard bugs (added at step 350 β was 600)
|
| 45 |
+
β βββ generate_bugs.py # Script that generated the bug datasets
|
| 46 |
+
βββ requirements.txt # HF Space deps (gradio[oauth,mcp]==6.13.0, cu121 torch)
|
| 47 |
+
βββ requirements_kaggle.txt # Kaggle/RunPod deps (no torch pin, bitsandbytes==0.45.3)
|
| 48 |
+
βββ inference.py # Inference wrapper for evaluation
|
| 49 |
+
βββ Dockerfile # For the inference/env Space (not the training space)
|
| 50 |
+
βββ README.md # HF Space config header (sdk: gradio, app_file: app.py)
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
---
|
| 54 |
+
|
| 55 |
+
## Dependency Versions (locked β do not change without testing)
|
| 56 |
+
|
| 57 |
+
| Package | Version | Why pinned |
|
| 58 |
+
|---|---|---|
|
| 59 |
+
| `trl` | `0.14.0` | First version with `GRPOTrainer` + `GRPOConfig` |
|
| 60 |
+
| `pydantic` | `2.12.5` | Only version satisfying both gradio base AND gradio[mcp] constraints |
|
| 61 |
+
| `gradio` | `6.13.0[oauth,mcp]` | HF Space builder requires extras in one install pass |
|
| 62 |
+
| `bitsandbytes` | `0.45.3` (Kaggle) / `0.43.3` (HF Space cu121) | 0.45.3 has CUDA 12.x binaries; 0.43.3 works with cu121 |
|
| 63 |
+
| `transformers` | `4.46.3` | Tested with TRL 0.14.0 |
|
| 64 |
+
| `torch` | `2.5.1+cu121` (HF Space) / pre-installed (Kaggle) | |
|
| 65 |
+
|
| 66 |
+
**GRPOConfig param name:** `max_completion_length` (NOT `max_new_tokens` β that's the old name, breaks on 0.14.0)
|
| 67 |
+
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
## Training Script β Key Design Decisions
|
| 71 |
+
|
| 72 |
+
### GPU Auto-Detection (train_grpo.py ~line 260)
|
| 73 |
+
The script detects GPU at runtime and sets all hyperparams automatically:
|
| 74 |
+
|
| 75 |
+
| GPU | dtype | batch | grad_accum | num_gen | max_comp | lora_r |
|
| 76 |
+
|---|---|---|---|---|---|---|
|
| 77 |
+
| A100 40GB+ | bfloat16 | 2 | 4 | 8 | 256 | 16 |
|
| 78 |
+
| V100 32GB | float16 | 1 | 8 | 6 | 220 | 12 |
|
| 79 |
+
| T4 / β€16GB | float16 | 1 | 8 | 4 | 160 | 8 |
|
| 80 |
+
|
| 81 |
+
**Critical:** P100 is NOT supported β PyTorch 2.x dropped sm_60 support. Use T4 instead.
|
| 82 |
+
|
| 83 |
+
### Curriculum
|
| 84 |
+
- Steps 0β150: Tier 1 bugs only (9 bugs)
|
| 85 |
+
- Steps 150β350: Tier 1 + Tier 2 (40 bugs)
|
| 86 |
+
- Steps 350+: All tiers (61 bugs)
|
| 87 |
+
|
| 88 |
+
### Reward Components (server/reward_calculator.py)
|
| 89 |
+
| Component | Weight | What it measures |
|
| 90 |
+
|---|---|---|
|
| 91 |
+
| format_compliance | 0.10 | All 5 fields present (OBSERVATION/HYPOTHESIS/CONFIDENCE/ACTION/DETAIL) |
|
| 92 |
+
| hypothesis_quality | 0.20 | Length + references specific variable names |
|
| 93 |
+
| localization | 0.15 | Correct function/line identified |
|
| 94 |
+
| fix_quality | 0.35 | Tests pass on proposed fix |
|
| 95 |
+
| semantic_similarity | 0.10 | Similarity to canonical fix |
|
| 96 |
+
| efficiency_potential | 0.10 | Potential-based shaping (Ibrahim et al. 2024) |
|
| 97 |
+
|
| 98 |
+
### Required Output Format
|
| 99 |
+
```
|
| 100 |
+
OBSERVATION: [specific observations with line numbers]
|
| 101 |
+
HYPOTHESIS: [2+ sentences explaining root cause with variable names]
|
| 102 |
+
CONFIDENCE: [low | medium | high]
|
| 103 |
+
ACTION: [inspect_lines | run_tests | propose_fix | request_context | give_up]
|
| 104 |
+
DETAIL: [complete fixed function code if propose_fix, else details]
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
## Running Training
|
| 110 |
+
|
| 111 |
+
### On Kaggle (T4 β free):
|
| 112 |
+
```python
|
| 113 |
+
# Cell 1 β install
|
| 114 |
+
!pip install -q wandb==0.18.7 datasets==3.0.2 transformers==4.46.3 \
|
| 115 |
+
accelerate==1.0.1 trl==0.14.0 bitsandbytes==0.45.3 peft==0.13.2
|
| 116 |
+
|
| 117 |
+
# Cell 2 β clone + secrets
|
| 118 |
+
from kaggle_secrets import UserSecretsClient
|
| 119 |
+
import os
|
| 120 |
+
secrets = UserSecretsClient()
|
| 121 |
+
os.environ["WANDB_API_KEY"] = secrets.get_secret("WANDB_API_KEY")
|
| 122 |
+
os.environ["HF_TOKEN"] = secrets.get_secret("HF_TOKEN")
|
| 123 |
+
!git clone https://github.com/shasshaank/meta_hackthon.git /kaggle/working/repo
|
| 124 |
+
%cd /kaggle/working/repo
|
| 125 |
+
|
| 126 |
+
# Cell 3 β train (streams output live)
|
| 127 |
+
import subprocess, sys
|
| 128 |
+
proc = subprocess.Popen(
|
| 129 |
+
[sys.executable, "training/train_grpo.py"],
|
| 130 |
+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
| 131 |
+
text=True, bufsize=1, cwd="/kaggle/working/repo"
|
| 132 |
+
)
|
| 133 |
+
for line in proc.stdout:
|
| 134 |
+
print(line, end="", flush=True)
|
| 135 |
+
proc.wait()
|
| 136 |
+
|
| 137 |
+
# Cell 4 β save outputs after training
|
| 138 |
+
import shutil
|
| 139 |
+
shutil.copytree("/kaggle/working/repo/checkpoints", "/kaggle/working/checkpoints", dirs_exist_ok=True)
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
**Kaggle secrets needed:** `WANDB_API_KEY`, `HF_TOKEN`
|
| 143 |
+
**Kaggle GPU:** T4 x1 (NOT P100 β incompatible with modern PyTorch)
|
| 144 |
+
**Expected time:** ~8β10 hours for 500 steps (default max_steps=500)
|
| 145 |
+
|
| 146 |
+
### On RunPod (A100 β ~$1.09/hr):
|
| 147 |
+
```bash
|
| 148 |
+
git clone https://github.com/shasshaank/meta_hackthon.git && cd meta_hackthon
|
| 149 |
+
pip install -q wandb==0.18.7 datasets==3.0.2 transformers==4.46.3 \
|
| 150 |
+
accelerate==1.0.1 trl==0.14.0 bitsandbytes==0.45.3 peft==0.13.2
|
| 151 |
+
WANDB_API_KEY=xxx HF_TOKEN=xxx python training/train_grpo.py
|
| 152 |
+
```
|
| 153 |
+
**Expected time:** ~3β4 hours for 1000 steps on A100 40GB
|
| 154 |
+
|
| 155 |
+
### Resume from checkpoint:
|
| 156 |
+
```bash
|
| 157 |
+
python training/train_grpo.py --resume ./checkpoints/checkpoint-400
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
### Local sanity check (no GPU):
|
| 161 |
+
```bash
|
| 162 |
+
python training/train_grpo.py --test-local
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
---
|
| 166 |
+
|
| 167 |
+
## HF Space Setup (training monitor)
|
| 168 |
+
|
| 169 |
+
The training Space (`AgentDebugger-training-v2`) is a Gradio app that:
|
| 170 |
+
1. On startup, spawns `training/train_grpo.py` in a background thread
|
| 171 |
+
2. Shows a live training log in the UI, auto-refreshing every 30s
|
| 172 |
+
|
| 173 |
+
**Required Space secrets:**
|
| 174 |
+
- `WANDB_API_KEY`
|
| 175 |
+
- `HF_TOKEN`
|
| 176 |
+
|
| 177 |
+
**Push to Space:**
|
| 178 |
+
```bash
|
| 179 |
+
git remote set-url space https://shashaank0707:YOUR_HF_TOKEN@huggingface.co/spaces/shashaank0707/AgentDebugger-training-v2
|
| 180 |
+
git push space main --force
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
---
|
| 184 |
+
|
| 185 |
+
## Known Issues Fixed (do not revert)
|
| 186 |
+
|
| 187 |
+
| Issue | Fix |
|
| 188 |
+
|---|---|
|
| 189 |
+
| `ImportError: cannot import name 'GRPOTrainer'` | `trl==0.12.2` β `trl==0.14.0` |
|
| 190 |
+
| `TypeError: GRPOConfig got unexpected keyword 'max_new_tokens'` | renamed to `max_completion_length` |
|
| 191 |
+
| `pydantic` conflict with `gradio[mcp]` | `pydantic==2.10.6` β `2.12.5` |
|
| 192 |
+
| `P100 not supported by PyTorch 2.x` | Switch to T4 on Kaggle |
|
| 193 |
+
| `bitsandbytes CUDA binary not found` | `bitsandbytes==0.43.3` β `0.45.3` on Kaggle |
|
| 194 |
+
| `unsloth` CUDA driver crash on HF A100 | Replaced with `bitsandbytes + peft` |
|
| 195 |
+
| `gradio every=` deprecation | Replaced with `gr.Timer(value=30)` |
|
| 196 |
+
|
| 197 |
+
---
|
| 198 |
+
|
| 199 |
+
## W&B Dashboard
|
| 200 |
+
https://wandb.ai/shashaankjain07-keshav-memorial-college-of-law/AgentDebuggerEnv
|
| 201 |
+
|
| 202 |
+
Training runs appear here automatically when `WANDB_API_KEY` is set.
|
| 203 |
+
|
| 204 |
+
---
|
| 205 |
+
|
| 206 |
+
## What's Left To Do
|
| 207 |
+
|
| 208 |
+
- [ ] **Finish training** β 500β1000 steps, model pushes to HF Hub automatically on completion
|
| 209 |
+
- [ ] **Verify trained model** β run `inference.py` against the trained model checkpoint
|
| 210 |
+
- [ ] **Update HF Space README** β change curriculum description to match actual step boundaries (150/350)
|
| 211 |
+
- [ ] **Submission** β ensure the inference/env Space (`AgentDebugger-env`) is live and healthy for judging
|