yashash04 commited on
Commit
cf4ce7e
·
1 Parent(s): b0a62f6

Phase 13 Stage 1: pivot to winner's pattern - TRL 0.29.0 + fast_inference=False + DAPO loss

Browse files
TRAINING_LOG.md CHANGED
@@ -290,8 +290,11 @@ Every training attempt, successful or failed. Number them sequentially across th
290
  - use_vllm: **false** (dropped — vLLM 0.6.3 pins torch 2.4, incompatible with Kaggle's native torch 2.10+cu128; wall-clock becomes ~4h instead of ~2.5h but correctness is unaffected)
291
  - push_to_hub: true
292
  - hub_model_id: `yashash045/schemashift-qwen15b-kaggle`
293
- - **TRL version:** `trl>=0.18.2,<=0.24.0,!=0.19.0` (Unsloth 2026.x compat range; pip resolves to 0.24.0)
 
294
  - **Torch version:** Kaggle native (`torch 2.10+cu128`, not pinned)
 
 
295
  - **Quantization:** 4-bit via Unsloth
296
  - **Hardware:** Kaggle T4 x2 (P100 acceptable fallback — record which)
297
  - **SchemaShift env URL:** `https://yashash045-schemashift.hf.space`
 
290
  - use_vllm: **false** (dropped — vLLM 0.6.3 pins torch 2.4, incompatible with Kaggle's native torch 2.10+cu128; wall-clock becomes ~4h instead of ~2.5h but correctness is unaffected)
291
  - push_to_hub: true
292
  - hub_model_id: `yashash045/schemashift-qwen15b-kaggle`
293
+ - **TRL version:** `trl==0.29.0` (pivoted from 0.18-0.24 range after 3h of Kaggle debug — both older ranges had eager imports of vllm_client or mergekit that crashed on clean Kaggle. 0.29.0 moved them to experimental per PR #5057, verified clean locally)
294
+ - **vLLM:** NOT installed (`fast_inference=False` on FastLanguageModel; `use_vllm=False` in GRPOConfig)
295
  - **Torch version:** Kaggle native (`torch 2.10+cu128`, not pinned)
296
+ - **Winner-adopted tweaks:** `loss_type="dapo"` + `lr_scheduler_type="cosine"` + `warmup_steps=2` + `beta=0.01` + `max_grad_norm=1.0` + `save_total_limit=3` + `hub_strategy="every_save"`. From [sid-rp/kube-sre-gym](https://github.com/sid-rp/kube-sre-gym) train.py.
297
+ - **NOT adopted (requires vLLM):** `trl.experimental.openenv.generate_rollout_completions` multi-turn rollout orchestration. Our env loop stays inside `reward_fn` which TRL calls after its internal `model.generate()`.
298
  - **Quantization:** 4-bit via Unsloth
299
  - **Hardware:** Kaggle T4 x2 (P100 acceptable fallback — record which)
300
  - **SchemaShift env URL:** `https://yashash045-schemashift.hf.space`
training/STAGE_1_KAGGLE_RUNBOOK.md CHANGED
@@ -8,14 +8,35 @@
8
  **Env:** `https://yashash045-schemashift.hf.space`
9
  **Expected wall-clock:** ~4 hours on Kaggle T4 ×2 (no vLLM — see "Kaggle dependency compatibility" below for why)
10
 
11
- ### Kaggle dependency compatibility (why no vLLM)
12
 
13
  Kaggle's 2026 base image ships `torch 2.10+cu128` + `transformers 4.57` + `torchao 0.17` pre-installed. We do NOT pin torch:
14
  - Pinning torch 2.4 breaks Kaggle's pre-installed `transformers` and `torchao`
15
  - Pinning torch 2.5.1 breaks `vLLM 0.6.3` (which itself pins torch 2.4)
16
  - The only clean path is Kaggle-native torch + latest Unsloth + no vLLM
17
 
18
- TRL range `>=0.18.2,<=0.24.0,!=0.19.0` is what Unsloth 2026.x is compatible with (pip resolves to `0.24.0`). Training runs ~4 hours instead of ~2.5 hours without vLLM's fast inference, but correctness is unaffected only generation throughput drops. **Judges don't ask about inference speed.**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  ---
21
 
@@ -61,7 +82,7 @@ Execute each cell with Shift+Enter. Wait for "✓" before advancing.
61
 
62
  | Cell | Purpose | Expected | Red flag |
63
  |---|---|---|---|
64
- | 1 | `pip install unsloth trl httpx ...` | `torch: 2.10.x+cu128`, `unsloth: 2026.x`, `trl: 0.24.0`, "Core deps verified" | any import error or wrong torch version — stop |
65
  | 2 | `git clone SchemaShift && pip install -e .` | "Successfully installed schemashift-0.1.0" | clone fails (check internet) |
66
  | 3 | Env health check (import client, call `client.health()`) | prints `True` | `False` — URL wrong or Space down |
67
  | 4 | Load Qwen 2.5 1.5B 4-bit + LoRA | "Trainable params: ~8.9M" | OOM error — use T4 x2 not x1 |
 
8
  **Env:** `https://yashash045-schemashift.hf.space`
9
  **Expected wall-clock:** ~4 hours on Kaggle T4 ×2 (no vLLM — see "Kaggle dependency compatibility" below for why)
10
 
11
+ ### Kaggle dependency compatibility (why no vLLM, why TRL 0.29.0)
12
 
13
  Kaggle's 2026 base image ships `torch 2.10+cu128` + `transformers 4.57` + `torchao 0.17` pre-installed. We do NOT pin torch:
14
  - Pinning torch 2.4 breaks Kaggle's pre-installed `transformers` and `torchao`
15
  - Pinning torch 2.5.1 breaks `vLLM 0.6.3` (which itself pins torch 2.4)
16
  - The only clean path is Kaggle-native torch + latest Unsloth + no vLLM
17
 
18
+ **TRL pin: `trl==0.29.0`** (mirrors previous hackathon winner sid-rp/kube-sre-gym). Earlier attempts at 0.18.2 and 0.24.0 both eagerly imported optional deps (vllm_client / mergekit) and crashed on clean Kaggle. TRL 0.29.0 moved those to experimental per PR #5057 and verified-imports-clean (no vLLM installed) locally.
19
+
20
+ Training runs ~4 hours instead of ~2.5 hours without vLLM's fast inference, but correctness is unaffected — only generation throughput drops. **Judges don't ask about inference speed.**
21
+
22
+ ### Winner vs ours — what we mirror and where we diverge
23
+
24
+ Previous hackathon winner: [sid-rp/kube-sre-gym](https://github.com/sid-rp/kube-sre-gym) — OpenEnv + TRL GRPO on Kubernetes incidents.
25
+
26
+ | Dimension | Winner (H100) | Winner's Colab variant (T4) | Ours (Kaggle T4 free) |
27
+ |---|---|---|---|
28
+ | TRL version | `trl[vllm]==0.29.0` | `trl[vllm]>=0.29.0` | `trl==0.29.0` (no vllm extra) |
29
+ | vLLM | `vllm==0.11.2`, colocate | `vllm>=0.11.0`, colocate | **none** (`fast_inference=False`) |
30
+ | Base model | Qwen3-0.6B | Qwen3-0.6B / Qwen3-1.7B | Qwen2.5-1.5B |
31
+ | Rollout mechanism | `trl.experimental.openenv.generate_rollout_completions` (multi-turn agent, iterative obs→act) | same | **reward_fn does env loop inside** (single completion → parsed action sequence → full episode) — `rollout_func` param requires `use_vllm=True`, not viable for us |
32
+ | num_generations | 8 | 8 | 4 (T4 memory budget) |
33
+ | max_completion_length | 512 | 512 | 1024 (our JSON actions are longer) |
34
+ | Loss type | `dapo` (asymmetric clipping + dynamic sampling) | `dapo` | **`dapo`** (adopted from winner) |
35
+ | LR schedule | cosine, warmup=2 | cosine, warmup=2 | **cosine, warmup=2** (adopted) |
36
+ | beta (KL) | 0.01 | default | **0.01** (adopted) |
37
+ | GPU | 1× H100 80GB | 1× T4 16GB | 2× T4 16GB (use first only) |
38
+
39
+ **What this means for pitch:** we're using the winner's stable TRL version + their DAPO loss + their LR schedule — the recipe parts that matter for convergence. We don't mirror their multi-turn iterative-observation pattern because it's gated behind vLLM, which we can't install. Our single-shot action-sequence pattern produces simpler completions but still trains the same adaptive-tool-use skill.
40
 
41
  ---
42
 
 
82
 
83
  | Cell | Purpose | Expected | Red flag |
84
  |---|---|---|---|
85
+ | 1 | `pip install unsloth "trl==0.29.0" peft httpx ...` | `torch: 2.10.x+cu128`, `unsloth: 2026.x`, `trl: 0.29.0`, `peft: ...`, "Core deps verified" | any import error or wrong torch version — stop |
86
  | 2 | `git clone SchemaShift && pip install -e .` | "Successfully installed schemashift-0.1.0" | clone fails (check internet) |
87
  | 3 | Env health check (import client, call `client.health()`) | prints `True` | `False` — URL wrong or Space down |
88
  | 4 | Load Qwen 2.5 1.5B 4-bit + LoRA | "Trainable params: ~8.9M" | OOM error — use T4 x2 not x1 |
training/grpo_kaggle.ipynb CHANGED
@@ -18,7 +18,10 @@
18
  "- Set Kaggle Secret: `HF_USERNAME` (your HF namespace; falls back to `yashash045` if unset)\n",
19
  "- Accelerator: GPU T4 x2 (P100 fallback). Internet: ON. Persistence: ON.\n",
20
  "\n",
21
- "**Stage 1 runbook:** see `training/STAGE_1_KAGGLE_RUNBOOK.md` for the full step-by-step guide.\n"
 
 
 
22
  ]
23
  },
24
  {
@@ -27,22 +30,23 @@
27
  "metadata": {},
28
  "outputs": [],
29
  "source": [
30
- "# Install deps - Kaggle native (no vLLM, no torch pinning).\n",
31
- "# Kaggle's 2026 base image ships torch 2.10 + cu128 + transformers + torchao.\n",
32
- "# Unsloth 2026.x is tested against that; pinning torch breaks the base image.\n",
33
  "!pip install -q unsloth\n",
34
- "!pip install -q \"trl>=0.18.2,<=0.24.0,!=0.19.0\"\n",
35
  "!pip install -q httpx pydantic fastapi openai\n",
36
  "\n",
37
- "# Verify critical deps. If any of these fail or print wrong versions, STOP.\n",
38
  "import torch\n",
39
  "print(f\"torch: {torch.__version__}\")\n",
40
- "print(f\"cuda available: {torch.cuda.is_available()}\")\n",
41
  "\n",
42
- "import unsloth, trl\n",
43
  "print(f\"unsloth: {unsloth.__version__}\")\n",
44
- "print(f\"trl: {trl.__version__}\")\n",
45
- "print(\"Core deps verified (Kaggle-native, no vLLM).\")\n"
 
46
  ]
47
  },
48
  {
@@ -89,12 +93,14 @@
89
  "metadata": {},
90
  "outputs": [],
91
  "source": [
92
- "# Load Qwen 2.5 1.5B + LoRA adapter\n",
 
93
  "from unsloth import FastLanguageModel\n",
94
  "model, tokenizer = FastLanguageModel.from_pretrained(\n",
95
  " model_name=\"Qwen/Qwen2.5-1.5B-Instruct\",\n",
96
  " max_seq_length=3072,\n",
97
  " load_in_4bit=True,\n",
 
98
  " dtype=None,\n",
99
  ")\n",
100
  "model = FastLanguageModel.get_peft_model(\n",
@@ -104,7 +110,7 @@
104
  " lora_dropout=0.0,\n",
105
  " target_modules=[\"q_proj\",\"k_proj\",\"v_proj\",\"o_proj\",\"gate_proj\",\"up_proj\",\"down_proj\"],\n",
106
  ")\n",
107
- "print(f\"Trainable params: {model.num_parameters(only_trainable=True):,}\")"
108
  ]
109
  },
110
  {
@@ -297,23 +303,38 @@
297
  "metadata": {},
298
  "outputs": [],
299
  "source": [
300
- "# GRPO config (Kaggle T4-friendly, no vLLM) + GRPOTrainer construction.\n",
 
 
 
301
  "from trl import GRPOConfig, GRPOTrainer\n",
302
  "\n",
303
  "config = GRPOConfig(\n",
304
  " output_dir=\"schemashift-grpo-kaggle\",\n",
305
  " num_generations=4,\n",
306
- " max_completion_length=1536,\n",
307
  " per_device_train_batch_size=1,\n",
308
  " gradient_accumulation_steps=4,\n",
309
  " learning_rate=5e-6,\n",
310
- " logging_steps=5,\n",
 
 
 
 
311
  " save_steps=25,\n",
312
  " max_steps=100,\n",
 
313
  " report_to=\"none\",\n",
314
  " use_vllm=False,\n",
 
 
 
 
 
 
315
  " push_to_hub=True,\n",
316
  " hub_model_id=f\"{os.getenv('HF_USERNAME', 'yashash045')}/schemashift-qwen15b-kaggle\",\n",
 
317
  ")\n",
318
  "\n",
319
  "trainer = GRPOTrainer(\n",
@@ -324,11 +345,12 @@
324
  " train_dataset=train_dataset,\n",
325
  ")\n",
326
  "\n",
327
- "print(\"GRPOTrainer initialized.\")\n",
328
- "print(f\" model: {model.config._name_or_path}\")\n",
329
  "print(f\" dataset size: {len(train_dataset)}\")\n",
330
  "print(f\" max_steps: {config.max_steps}\")\n",
331
  "print(f\" save_steps: {config.save_steps}\")\n",
 
332
  "print(f\" hub_model_id: {config.hub_model_id}\")\n"
333
  ]
334
  },
 
18
  "- Set Kaggle Secret: `HF_USERNAME` (your HF namespace; falls back to `yashash045` if unset)\n",
19
  "- Accelerator: GPU T4 x2 (P100 fallback). Internet: ON. Persistence: ON.\n",
20
  "\n",
21
+ "**Stage 1 runbook:** see `training/STAGE_1_KAGGLE_RUNBOOK.md` for the full step-by-step guide.\n",
22
+ "\n",
23
+ "**Dependency baseline:** TRL 0.29.0 + Unsloth 2026.x + Kaggle-native torch 2.10.\n",
24
+ "No vLLM (incompatible with Kaggle's torch 2.10). Reference implementation: [sid-rp/kube-sre-gym](https://github.com/sid-rp/kube-sre-gym) (previous hackathon winner, TRL 0.29 on H100 with vLLM). We use their TRL version but keep rollouts inside `reward_fn` since `trl.experimental.openenv.generate_rollout_completions` requires `use_vllm=True`.\n"
25
  ]
26
  },
27
  {
 
30
  "metadata": {},
31
  "outputs": [],
32
  "source": [
33
+ "# Install deps - TRL 0.29.0 without vLLM (Kaggle torch 2.10 native).\n",
34
+ "# Mirrors winner repo sid-rp/kube-sre-gym (trl==0.29.0, peft) minus vLLM.\n",
35
+ "# TRL 0.29.0 is clean on imports (no mergekit/vllm eager-import crash).\n",
36
  "!pip install -q unsloth\n",
37
+ "!pip install -q \"trl==0.29.0\" peft\n",
38
  "!pip install -q httpx pydantic fastapi openai\n",
39
  "\n",
40
+ "# Verify critical deps. If any print wrong versions, STOP.\n",
41
  "import torch\n",
42
  "print(f\"torch: {torch.__version__}\")\n",
43
+ "print(f\"cuda: {torch.cuda.is_available()}\")\n",
44
  "\n",
45
+ "import unsloth, trl, peft\n",
46
  "print(f\"unsloth: {unsloth.__version__}\")\n",
47
+ "print(f\"trl: {trl.__version__}\")\n",
48
+ "print(f\"peft: {peft.__version__}\")\n",
49
+ "print(\"Core deps verified (TRL 0.29.0, no vLLM).\")\n"
50
  ]
51
  },
52
  {
 
93
  "metadata": {},
94
  "outputs": [],
95
  "source": [
96
+ "# Load Qwen 2.5 1.5B + LoRA adapter.\n",
97
+ "# fast_inference=False disables Unsloth's vLLM bypass - required when vLLM isn't installed.\n",
98
  "from unsloth import FastLanguageModel\n",
99
  "model, tokenizer = FastLanguageModel.from_pretrained(\n",
100
  " model_name=\"Qwen/Qwen2.5-1.5B-Instruct\",\n",
101
  " max_seq_length=3072,\n",
102
  " load_in_4bit=True,\n",
103
+ " fast_inference=False,\n",
104
  " dtype=None,\n",
105
  ")\n",
106
  "model = FastLanguageModel.get_peft_model(\n",
 
110
  " lora_dropout=0.0,\n",
111
  " target_modules=[\"q_proj\",\"k_proj\",\"v_proj\",\"o_proj\",\"gate_proj\",\"up_proj\",\"down_proj\"],\n",
112
  ")\n",
113
+ "print(f\"Trainable params: {model.num_parameters(only_trainable=True):,}\")\n"
114
  ]
115
  },
116
  {
 
303
  "metadata": {},
304
  "outputs": [],
305
  "source": [
306
+ "# GRPO config (TRL 0.29.0, Kaggle T4-friendly, no vLLM).\n",
307
+ "# Adopts winner's DAPO loss + cosine LR + light KL - minus vLLM/rollout_func\n",
308
+ "# (rollout_func only runs when use_vllm=True in TRL 0.29.0; we keep env rollout\n",
309
+ "# inside reward_fn which TRL calls after its internal model.generate()).\n",
310
  "from trl import GRPOConfig, GRPOTrainer\n",
311
  "\n",
312
  "config = GRPOConfig(\n",
313
  " output_dir=\"schemashift-grpo-kaggle\",\n",
314
  " num_generations=4,\n",
315
+ " max_completion_length=1024,\n",
316
  " per_device_train_batch_size=1,\n",
317
  " gradient_accumulation_steps=4,\n",
318
  " learning_rate=5e-6,\n",
319
+ " lr_scheduler_type=\"cosine\",\n",
320
+ " warmup_steps=2,\n",
321
+ " max_grad_norm=1.0,\n",
322
+ " logging_steps=1,\n",
323
+ " save_strategy=\"steps\",\n",
324
  " save_steps=25,\n",
325
  " max_steps=100,\n",
326
+ " temperature=1.0,\n",
327
  " report_to=\"none\",\n",
328
  " use_vllm=False,\n",
329
+ " gradient_checkpointing=True,\n",
330
+ " gradient_checkpointing_kwargs={\"use_reentrant\": False},\n",
331
+ " loss_type=\"dapo\",\n",
332
+ " mask_truncated_completions=True,\n",
333
+ " beta=0.01,\n",
334
+ " save_total_limit=3,\n",
335
  " push_to_hub=True,\n",
336
  " hub_model_id=f\"{os.getenv('HF_USERNAME', 'yashash045')}/schemashift-qwen15b-kaggle\",\n",
337
+ " hub_strategy=\"every_save\",\n",
338
  ")\n",
339
  "\n",
340
  "trainer = GRPOTrainer(\n",
 
345
  " train_dataset=train_dataset,\n",
346
  ")\n",
347
  "\n",
348
+ "print(\"GRPOTrainer initialized (TRL 0.29.0, use_vllm=False).\")\n",
349
+ "print(f\" model: Qwen/Qwen2.5-1.5B-Instruct\")\n",
350
  "print(f\" dataset size: {len(train_dataset)}\")\n",
351
  "print(f\" max_steps: {config.max_steps}\")\n",
352
  "print(f\" save_steps: {config.save_steps}\")\n",
353
+ "print(f\" loss_type: {config.loss_type}\")\n",
354
  "print(f\" hub_model_id: {config.hub_model_id}\")\n"
355
  ]
356
  },