Spaces:
Sleeping
Sleeping
Update training/train_agent.py
Browse files- training/train_agent.py +24 -1
training/train_agent.py
CHANGED
|
@@ -13,6 +13,7 @@ FIXES applied:
|
|
| 13 |
import os
|
| 14 |
import re
|
| 15 |
import json
|
|
|
|
| 16 |
import requests
|
| 17 |
from datasets import Dataset
|
| 18 |
from collections import defaultdict
|
|
@@ -34,6 +35,7 @@ ENV_URL = os.getenv("ENV_URL", "https://junaid0600-sql-db-engineer-agent.h
|
|
| 34 |
HF_TOKEN = os.getenv("HF_TOKEN", "")
|
| 35 |
MODEL_NAME = os.getenv("MODEL_NAME", "unsloth/Qwen2.5-7B-Instruct")
|
| 36 |
OUTPUT_DIR = os.getenv("OUTPUT_DIR", "./sdea-trained")
|
|
|
|
| 37 |
|
| 38 |
# Valid Round 2 action types β model must use one of these
|
| 39 |
VALID_ACTION_TYPES = {
|
|
@@ -66,6 +68,22 @@ Examples:
|
|
| 66 |
{"action_type": "submit_report", "payload": {"summary": "Added composite index on orders(user_id, status). Performance improved from 5.0 to 85.0."}}"""
|
| 67 |
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
# βββββββββββββββββββββββββββββββββββββββββββββ
|
| 70 |
# JSON EXTRACTION (FIX 1 β kills PARSE FALLBACK)
|
| 71 |
# βββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -359,6 +377,8 @@ def reward_wrapper(prompts, completions, **kwargs):
|
|
| 359 |
# βββββββββββββββββββββββββββββββββββββββββββββ
|
| 360 |
|
| 361 |
def train():
|
|
|
|
|
|
|
| 362 |
if not UNSLOTH_AVAILABLE:
|
| 363 |
print("Cannot train β Unsloth not installed")
|
| 364 |
print("Run: pip install 'unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git' trl transformers datasets accelerate")
|
|
@@ -401,7 +421,9 @@ def train():
|
|
| 401 |
# GRPO config
|
| 402 |
config = GRPOConfig(
|
| 403 |
output_dir = OUTPUT_DIR,
|
| 404 |
-
|
|
|
|
|
|
|
| 405 |
per_device_train_batch_size = 1, # was 2 β frees memory for 1.5B
|
| 406 |
gradient_accumulation_steps = 2, # was 8 β was hiding steps, now shows them
|
| 407 |
learning_rate = 2e-5, # was 5e-5 β lower = more stable for small model
|
|
@@ -422,6 +444,7 @@ def train():
|
|
| 422 |
)
|
| 423 |
|
| 424 |
print("ποΈ Starting GRPO training...")
|
|
|
|
| 425 |
print(" Expected reward progression:")
|
| 426 |
print(" Steps 10: ~0.05-0.15 (model still outputting free text)")
|
| 427 |
print(" Steps 50: ~0.20-0.35 (learning JSON format)")
|
|
|
|
| 13 |
import os
|
| 14 |
import re
|
| 15 |
import json
|
| 16 |
+
import warnings
|
| 17 |
import requests
|
| 18 |
from datasets import Dataset
|
| 19 |
from collections import defaultdict
|
|
|
|
| 35 |
HF_TOKEN = os.getenv("HF_TOKEN", "")
|
| 36 |
MODEL_NAME = os.getenv("MODEL_NAME", "unsloth/Qwen2.5-7B-Instruct")
|
| 37 |
OUTPUT_DIR = os.getenv("OUTPUT_DIR", "./sdea-trained")
|
| 38 |
+
MAX_STEPS = int(os.getenv("MAX_STEPS", "50"))
|
| 39 |
|
| 40 |
# Valid Round 2 action types β model must use one of these
|
| 41 |
VALID_ACTION_TYPES = {
|
|
|
|
| 68 |
{"action_type": "submit_report", "payload": {"summary": "Added composite index on orders(user_id, status). Performance improved from 5.0 to 85.0."}}"""
|
| 69 |
|
| 70 |
|
| 71 |
+
def _configure_warning_filters() -> None:
|
| 72 |
+
"""
|
| 73 |
+
Suppress noisy upstream deprecation warnings that do not affect training
|
| 74 |
+
correctness right now. Keep real runtime errors visible.
|
| 75 |
+
"""
|
| 76 |
+
filters = [
|
| 77 |
+
r"Passing `generation_config` together with generation-related arguments",
|
| 78 |
+
r"Both `max_new_tokens` \(=.+\) and `max_length`\(.+\) seem to have been set",
|
| 79 |
+
r"The attention mask API under `transformers\.modeling_attn_mask_utils`",
|
| 80 |
+
r"`use_return_dict` is deprecated! Use `return_dict` instead!",
|
| 81 |
+
]
|
| 82 |
+
for message in filters:
|
| 83 |
+
warnings.filterwarnings("ignore", message=message, category=FutureWarning)
|
| 84 |
+
warnings.filterwarnings("ignore", message=message, category=UserWarning)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
# βββββββββββββββββββββββββββββββββββββββββββββ
|
| 88 |
# JSON EXTRACTION (FIX 1 β kills PARSE FALLBACK)
|
| 89 |
# βββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 377 |
# βββββββββββββββββββββββββββββββββββββββββββββ
|
| 378 |
|
| 379 |
def train():
|
| 380 |
+
_configure_warning_filters()
|
| 381 |
+
|
| 382 |
if not UNSLOTH_AVAILABLE:
|
| 383 |
print("Cannot train β Unsloth not installed")
|
| 384 |
print("Run: pip install 'unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git' trl transformers datasets accelerate")
|
|
|
|
| 421 |
# GRPO config
|
| 422 |
config = GRPOConfig(
|
| 423 |
output_dir = OUTPUT_DIR,
|
| 424 |
+
# Set explicit optimizer steps so "Total steps" is predictable.
|
| 425 |
+
max_steps = MAX_STEPS,
|
| 426 |
+
num_train_epochs = 100, # ignored when max_steps is reached first
|
| 427 |
per_device_train_batch_size = 1, # was 2 β frees memory for 1.5B
|
| 428 |
gradient_accumulation_steps = 2, # was 8 β was hiding steps, now shows them
|
| 429 |
learning_rate = 2e-5, # was 5e-5 β lower = more stable for small model
|
|
|
|
| 444 |
)
|
| 445 |
|
| 446 |
print("ποΈ Starting GRPO training...")
|
| 447 |
+
print(f" Target optimizer steps: {MAX_STEPS}")
|
| 448 |
print(" Expected reward progression:")
|
| 449 |
print(" Steps 10: ~0.05-0.15 (model still outputting free text)")
|
| 450 |
print(" Steps 50: ~0.20-0.35 (learning JSON format)")
|