Instructions to use Yogi016/datapilot-v6-tiny-aya-sql-grpo-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Yogi016/datapilot-v6-tiny-aya-sql-grpo-lora with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("CohereLabs/tiny-aya-global") model = PeftModel.from_pretrained(base_model, "Yogi016/datapilot-v6-tiny-aya-sql-grpo-lora") - Notebooks
- Google Colab
- Kaggle
Download code/common.py from Yogi016/datapilot-v6-tiny-aya-sql-grpo-lora: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/Yogi016/datapilot-v6-tiny-aya-sql-grpo-lora/resolve/main/code/common.py
- Command line
-
hf download hf://Yogi016/datapilot-v6-tiny-aya-sql-grpo-lora/code/common.py
-
curl -L -o common.py https://huggingface.co/Yogi016/datapilot-v6-tiny-aya-sql-grpo-lora/resolve/main/code/common.py
1.62 kB
| """Shared by train_grpo.py and eval.py so reward and evaluation use identical logic.""" | |
| import json | |
| import os | |
| import re | |
| import sqlite3 | |
| import time | |
| DB = os.environ.get("DB_PATH", "data/business.db") | |
| def load_jsonl(path): | |
| with open(path) as f: | |
| return [json.loads(line) for line in f if line.strip()] | |
| def to_messages(prompt: str): | |
| return [{"role": "user", "content": prompt}] | |
| def extract_sql(text: str) -> str: | |
| """First ```sql block if present, else the raw text (stripped of a trailing ;).""" | |
| m = re.search(r"```sql\s*(.*?)```", text, re.S | re.I) | |
| sql = m.group(1) if m else text | |
| return sql.strip().rstrip(";").strip() | |
| def run_readonly(sql: str, timeout_s: float = 2.0): | |
| """Execute a single SELECT on a read-only connection. Returns sorted rows or None.""" | |
| if not re.match(r"^\s*select\b", sql, re.I) or ";" in sql: | |
| return None | |
| try: | |
| con = sqlite3.connect(f"file:{DB}?mode=ro", uri=True) | |
| deadline = time.time() + timeout_s | |
| con.set_progress_handler(lambda: 1 if time.time() > deadline else 0, 10000) | |
| rows = con.execute(sql).fetchall() | |
| con.close() | |
| return sorted(repr(r) for r in rows) # order-insensitive comparison | |
| except Exception: | |
| return None | |
| def score(completion_text: str, gold_sql: str): | |
| """Returns (reward, valid, correct). 1.0 correct, 0.1 valid-but-wrong, 0.0 invalid.""" | |
| got = run_readonly(extract_sql(completion_text)) | |
| want = run_readonly(gold_sql) | |
| if got is None: | |
| return 0.0, False, False | |
| if got == want: | |
| return 1.0, True, True | |
| return 0.1, True, False | |