|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# GRPO SQL Optimizer — Colab Quickstart\n", |
| 8 | + "\n", |
| 9 | + "This notebook runs a **small, reproducible GRPO training run** on the **SQL Query Optimization Environment** (DuckDB-verifiable rewards).\n", |
| 10 | + "\n", |
| 11 | + "- Repo: `OfficialAbhinavSingh/SQL-Query-Optimization-Environment-`\n", |
| 12 | + "- Goal: give judges a one-click way to rerun training and see reward/loss curves.\n", |
| 13 | + "\n", |
| 14 | + "> Tip: For a quick demo run, keep episodes small (e.g. 40–80). For a longer run, increase episodes and/or group size." |
| 15 | + ] |
| 16 | + }, |
| 17 | + { |
| 18 | + "cell_type": "code", |
| 19 | + "execution_count": null, |
| 20 | + "metadata": {}, |
| 21 | + "outputs": [], |
| 22 | + "source": [ |
| 23 | + "# --- 1) Clone repo ---\n", |
| 24 | + "%cd /content\n", |
| 25 | + "!rm -rf /content/SQL-Query-Optimization-Environment-\n", |
| 26 | + "!git clone https://github.com/OfficialAbhinavSingh/SQL-Query-Optimization-Environment-.git\n", |
| 27 | + "%cd /content/SQL-Query-Optimization-Environment-" |
| 28 | + ] |
| 29 | + }, |
| 30 | + { |
| 31 | + "cell_type": "code", |
| 32 | + "execution_count": null, |
| 33 | + "metadata": {}, |
| 34 | + "outputs": [], |
| 35 | + "source": [ |
| 36 | + "# --- 2) Install deps ---\n", |
| 37 | + "!pip -q install -r requirements.txt\n", |
| 38 | + "\n", |
| 39 | + "# sanity (optional)\n", |
| 40 | + "!openenv validate ." |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "code", |
| 45 | + "execution_count": null, |
| 46 | + "metadata": {}, |
| 47 | + "outputs": [], |
| 48 | + "source": [ |
| 49 | + "# --- 3) Run a SHORT training run (judge-friendly) ---\n", |
| 50 | + "# We run train.py via import so we can override config without editing the repo.\n", |
| 51 | + "\n", |
| 52 | + "import os\n", |
| 53 | + "import train\n", |
| 54 | + "\n", |
| 55 | + "# Tune these for speed / quality\n", |
| 56 | + "train.cfg.num_episodes = 60\n", |
| 57 | + "train.cfg.group_size = 4\n", |
| 58 | + "train.cfg.output_dir = \"./checkpoints_colab\"\n", |
| 59 | + "\n", |
| 60 | + "# Optional: reduce tokens for faster iterations\n", |
| 61 | + "train.cfg.max_new_tokens = 768\n", |
| 62 | + "\n", |
| 63 | + "history = train.train()\n", |
| 64 | + "history[\"best_reward\"], len(history[\"episode_rewards\"])" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "code", |
| 69 | + "execution_count": null, |
| 70 | + "metadata": {}, |
| 71 | + "outputs": [], |
| 72 | + "source": [ |
| 73 | + "# --- 4) View curves and key outputs ---\n", |
| 74 | + "from pathlib import Path\n", |
| 75 | + "\n", |
| 76 | + "out = Path(\"./checkpoints_colab\")\n", |
| 77 | + "print(\"Outputs:\")\n", |
| 78 | + "for p in [out / \"training_curves.png\", out / \"training_history.json\"]:\n", |
| 79 | + " print(\" -\", p, \"exists=\", p.exists())\n", |
| 80 | + "\n", |
| 81 | + "display(Image(filename=str(out / \"training_curves.png\")))" |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | + "cell_type": "code", |
| 86 | + "execution_count": null, |
| 87 | + "metadata": {}, |
| 88 | + "outputs": [], |
| 89 | + "source": [ |
| 90 | + "# --- 5) Optional: generate the environment-only before/after artifact ---\n", |
| 91 | + "!python training/eval_before_after.py --save-dir results\n", |
| 92 | + "from PIL import Image\n", |
| 93 | + "display(Image.open(\"results/before_after_chart.png\"))" |
| 94 | + ] |
| 95 | + } |
| 96 | + ], |
| 97 | + "metadata": { |
| 98 | + "kernelspec": { |
| 99 | + "display_name": "Python 3", |
| 100 | + "language": "python", |
| 101 | + "name": "python3" |
| 102 | + }, |
| 103 | + "language_info": { |
| 104 | + "name": "python", |
| 105 | + "version": "3.10" |
| 106 | + } |
| 107 | + }, |
| 108 | + "nbformat": 4, |
| 109 | + "nbformat_minor": 5 |
| 110 | +} |
| 111 | + |
0 commit comments