Madhav189 Claude Opus 4.7 (1M context) commited on
Commit
c0ea16e
Β·
1 Parent(s): 215c8ad

notebook: broaden Cell 10 SFT-only load except clause

Browse files

User hit ImportError loading SFT-only adapter via FastLanguageModel.from_pretrained:
cannot import name 'EmbeddingParallel' from transformers.integrations.tensor_parallel

Root cause: peft (latest, pulled by uv) tries to use tensor-parallel sharding
when torch.distributed.is_initialized() is True (Accelerate sets this up
during training). The shard helper imports EmbeddingParallel which only
exists in transformers >=4.57, but Unsloth pins us to transformers==4.56.2.

Previous except clause caught only (RuntimeError, OOMError) β€” let
ImportError bubble up and crash Cell 10. Broadened to Exception so any
load failure (peft mismatch, adapter format, OOM) falls back gracefully
to running eval with 4 policies instead of 5.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

notebooks/01_triage_train_grpo.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "markdown",
5
- "id": "3396f4be",
6
  "metadata": {},
7
  "source": [
8
  "# sre-gym Triage β€” Qwen2.5-3B SFT β†’ GRPO training notebook\n",
@@ -46,7 +46,7 @@
46
  },
47
  {
48
  "cell_type": "markdown",
49
- "id": "d72032e7",
50
  "metadata": {},
51
  "source": [
52
  "## Cell 0 β€” Bootstrap (RUN ME FIRST after every kernel restart)\n",
@@ -67,7 +67,7 @@
67
  {
68
  "cell_type": "code",
69
  "execution_count": null,
70
- "id": "2e95fe82",
71
  "metadata": {},
72
  "outputs": [],
73
  "source": [
@@ -184,7 +184,7 @@
184
  },
185
  {
186
  "cell_type": "markdown",
187
- "id": "22ca4050",
188
  "metadata": {},
189
  "source": [
190
  "## Cell 1 β€” Verify PyTorch sees the GPU\n",
@@ -196,7 +196,7 @@
196
  {
197
  "cell_type": "code",
198
  "execution_count": null,
199
- "id": "bff2260c",
200
  "metadata": {},
201
  "outputs": [],
202
  "source": [
@@ -238,7 +238,7 @@
238
  },
239
  {
240
  "cell_type": "markdown",
241
- "id": "e27848b8",
242
  "metadata": {},
243
  "source": [
244
  "## Cell 2 β€” Build the SFT corpus\n",
@@ -250,7 +250,7 @@
250
  {
251
  "cell_type": "code",
252
  "execution_count": null,
253
- "id": "cc011328",
254
  "metadata": {},
255
  "outputs": [],
256
  "source": [
@@ -278,7 +278,7 @@
278
  },
279
  {
280
  "cell_type": "markdown",
281
- "id": "d6424b89",
282
  "metadata": {},
283
  "source": [
284
  "## Cell 3 β€” Sanity-check the corpus\n",
@@ -290,7 +290,7 @@
290
  {
291
  "cell_type": "code",
292
  "execution_count": null,
293
- "id": "c256cf4b",
294
  "metadata": {},
295
  "outputs": [],
296
  "source": [
@@ -335,7 +335,7 @@
335
  },
336
  {
337
  "cell_type": "markdown",
338
- "id": "7e307d37",
339
  "metadata": {},
340
  "source": [
341
  "## Cell 4 β€” Convert each step into a (prompt, completion) ChatML pair\n",
@@ -346,7 +346,7 @@
346
  {
347
  "cell_type": "code",
348
  "execution_count": null,
349
- "id": "e9100f77",
350
  "metadata": {},
351
  "outputs": [],
352
  "source": [
@@ -421,7 +421,7 @@
421
  },
422
  {
423
  "cell_type": "markdown",
424
- "id": "f3904eb1",
425
  "metadata": {},
426
  "source": [
427
  "## Cell 5 β€” Load Qwen2.5-3B-Instruct (4-bit + LoRA r=32)\n",
@@ -434,7 +434,7 @@
434
  {
435
  "cell_type": "code",
436
  "execution_count": null,
437
- "id": "6f91338c",
438
  "metadata": {},
439
  "outputs": [],
440
  "source": [
@@ -469,7 +469,7 @@
469
  },
470
  {
471
  "cell_type": "markdown",
472
- "id": "35751fb0",
473
  "metadata": {},
474
  "source": [
475
  "## Cell 6 β€” SFT cold-start (50 steps) + perplexity gate\n",
@@ -494,7 +494,7 @@
494
  {
495
  "cell_type": "code",
496
  "execution_count": null,
497
- "id": "3c6044fa",
498
  "metadata": {},
499
  "outputs": [],
500
  "source": [
@@ -579,7 +579,7 @@
579
  },
580
  {
581
  "cell_type": "markdown",
582
- "id": "562aaaf9",
583
  "metadata": {},
584
  "source": [
585
  "## Cell 7 β€” Build the GRPO prompt dataset\n",
@@ -592,7 +592,7 @@
592
  {
593
  "cell_type": "code",
594
  "execution_count": null,
595
- "id": "44e06dc9",
596
  "metadata": {},
597
  "outputs": [],
598
  "source": [
@@ -684,7 +684,7 @@
684
  },
685
  {
686
  "cell_type": "markdown",
687
- "id": "b421cc98",
688
  "metadata": {},
689
  "source": [
690
  "## Cell 8 β€” Per-turn proxy reward function\n",
@@ -699,7 +699,7 @@
699
  {
700
  "cell_type": "code",
701
  "execution_count": null,
702
- "id": "e5787ac3",
703
  "metadata": {},
704
  "outputs": [],
705
  "source": [
@@ -771,7 +771,7 @@
771
  },
772
  {
773
  "cell_type": "markdown",
774
- "id": "6f08cd4b",
775
  "metadata": {},
776
  "source": [
777
  "## Cell 9 β€” GRPO online training (50 steps Γ— K=4)\n",
@@ -795,7 +795,7 @@
795
  {
796
  "cell_type": "code",
797
  "execution_count": null,
798
- "id": "17223592",
799
  "metadata": {},
800
  "outputs": [],
801
  "source": [
@@ -873,7 +873,7 @@
873
  },
874
  {
875
  "cell_type": "markdown",
876
- "id": "56a59f8d",
877
  "metadata": {},
878
  "source": [
879
  "## Cell 10 β€” Eval comparison sweep\n",
@@ -891,7 +891,7 @@
891
  {
892
  "cell_type": "code",
893
  "execution_count": null,
894
- "id": "f4009004",
895
  "metadata": {},
896
  "outputs": [],
897
  "source": [
@@ -964,8 +964,12 @@
964
  " )\n",
965
  " FastLanguageModel.for_inference(sft_only_model)\n",
966
  " print(\"βœ“ Loaded SFT-only adapter for comparison\")\n",
967
- " except (RuntimeError, torch.cuda.OutOfMemoryError) as exc:\n",
968
- " print(f\"⚠ Could not load SFT-only model ({exc}) β€” skipping that comparison row\")\n",
 
 
 
 
969
  " sft_only_model = None\n",
970
  " torch.cuda.empty_cache()\n",
971
  "\n",
@@ -1082,7 +1086,7 @@
1082
  },
1083
  {
1084
  "cell_type": "markdown",
1085
- "id": "af6e0d43",
1086
  "metadata": {},
1087
  "source": [
1088
  "## Cell 11 β€” Summary table + hero plot"
@@ -1091,7 +1095,7 @@
1091
  {
1092
  "cell_type": "code",
1093
  "execution_count": null,
1094
- "id": "8ae96e2e",
1095
  "metadata": {},
1096
  "outputs": [],
1097
  "source": [
@@ -1155,7 +1159,7 @@
1155
  },
1156
  {
1157
  "cell_type": "markdown",
1158
- "id": "d0d0c3e9",
1159
  "metadata": {},
1160
  "source": [
1161
  "## Cell 12 β€” Package artifacts for download\n",
@@ -1167,7 +1171,7 @@
1167
  {
1168
  "cell_type": "code",
1169
  "execution_count": null,
1170
- "id": "f432e809",
1171
  "metadata": {},
1172
  "outputs": [],
1173
  "source": [
 
2
  "cells": [
3
  {
4
  "cell_type": "markdown",
5
+ "id": "3110f07b",
6
  "metadata": {},
7
  "source": [
8
  "# sre-gym Triage β€” Qwen2.5-3B SFT β†’ GRPO training notebook\n",
 
46
  },
47
  {
48
  "cell_type": "markdown",
49
+ "id": "cac960fb",
50
  "metadata": {},
51
  "source": [
52
  "## Cell 0 β€” Bootstrap (RUN ME FIRST after every kernel restart)\n",
 
67
  {
68
  "cell_type": "code",
69
  "execution_count": null,
70
+ "id": "8145ea78",
71
  "metadata": {},
72
  "outputs": [],
73
  "source": [
 
184
  },
185
  {
186
  "cell_type": "markdown",
187
+ "id": "df9b71c6",
188
  "metadata": {},
189
  "source": [
190
  "## Cell 1 β€” Verify PyTorch sees the GPU\n",
 
196
  {
197
  "cell_type": "code",
198
  "execution_count": null,
199
+ "id": "e383b274",
200
  "metadata": {},
201
  "outputs": [],
202
  "source": [
 
238
  },
239
  {
240
  "cell_type": "markdown",
241
+ "id": "f27ec1aa",
242
  "metadata": {},
243
  "source": [
244
  "## Cell 2 β€” Build the SFT corpus\n",
 
250
  {
251
  "cell_type": "code",
252
  "execution_count": null,
253
+ "id": "8742f436",
254
  "metadata": {},
255
  "outputs": [],
256
  "source": [
 
278
  },
279
  {
280
  "cell_type": "markdown",
281
+ "id": "c108d785",
282
  "metadata": {},
283
  "source": [
284
  "## Cell 3 β€” Sanity-check the corpus\n",
 
290
  {
291
  "cell_type": "code",
292
  "execution_count": null,
293
+ "id": "5ec1513d",
294
  "metadata": {},
295
  "outputs": [],
296
  "source": [
 
335
  },
336
  {
337
  "cell_type": "markdown",
338
+ "id": "ed6f3e29",
339
  "metadata": {},
340
  "source": [
341
  "## Cell 4 β€” Convert each step into a (prompt, completion) ChatML pair\n",
 
346
  {
347
  "cell_type": "code",
348
  "execution_count": null,
349
+ "id": "b246edc9",
350
  "metadata": {},
351
  "outputs": [],
352
  "source": [
 
421
  },
422
  {
423
  "cell_type": "markdown",
424
+ "id": "7f1000b9",
425
  "metadata": {},
426
  "source": [
427
  "## Cell 5 β€” Load Qwen2.5-3B-Instruct (4-bit + LoRA r=32)\n",
 
434
  {
435
  "cell_type": "code",
436
  "execution_count": null,
437
+ "id": "4b80d94e",
438
  "metadata": {},
439
  "outputs": [],
440
  "source": [
 
469
  },
470
  {
471
  "cell_type": "markdown",
472
+ "id": "ebf483de",
473
  "metadata": {},
474
  "source": [
475
  "## Cell 6 β€” SFT cold-start (50 steps) + perplexity gate\n",
 
494
  {
495
  "cell_type": "code",
496
  "execution_count": null,
497
+ "id": "32a3b834",
498
  "metadata": {},
499
  "outputs": [],
500
  "source": [
 
579
  },
580
  {
581
  "cell_type": "markdown",
582
+ "id": "2aae3787",
583
  "metadata": {},
584
  "source": [
585
  "## Cell 7 β€” Build the GRPO prompt dataset\n",
 
592
  {
593
  "cell_type": "code",
594
  "execution_count": null,
595
+ "id": "c2b24827",
596
  "metadata": {},
597
  "outputs": [],
598
  "source": [
 
684
  },
685
  {
686
  "cell_type": "markdown",
687
+ "id": "95b38397",
688
  "metadata": {},
689
  "source": [
690
  "## Cell 8 β€” Per-turn proxy reward function\n",
 
699
  {
700
  "cell_type": "code",
701
  "execution_count": null,
702
+ "id": "424ac3dd",
703
  "metadata": {},
704
  "outputs": [],
705
  "source": [
 
771
  },
772
  {
773
  "cell_type": "markdown",
774
+ "id": "aa0ac0c8",
775
  "metadata": {},
776
  "source": [
777
  "## Cell 9 β€” GRPO online training (50 steps Γ— K=4)\n",
 
795
  {
796
  "cell_type": "code",
797
  "execution_count": null,
798
+ "id": "6563dbb7",
799
  "metadata": {},
800
  "outputs": [],
801
  "source": [
 
873
  },
874
  {
875
  "cell_type": "markdown",
876
+ "id": "3fa723d4",
877
  "metadata": {},
878
  "source": [
879
  "## Cell 10 β€” Eval comparison sweep\n",
 
891
  {
892
  "cell_type": "code",
893
  "execution_count": null,
894
+ "id": "ef385ec4",
895
  "metadata": {},
896
  "outputs": [],
897
  "source": [
 
964
  " )\n",
965
  " FastLanguageModel.for_inference(sft_only_model)\n",
966
  " print(\"βœ“ Loaded SFT-only adapter for comparison\")\n",
967
+ " except Exception as exc:\n",
968
+ " # Catches OOM, ImportError (peft/transformers mismatch on tensor-parallel\n",
969
+ " # imports), AttributeError (Unsloth + adapter mismatch), etc. Eval still\n",
970
+ " # runs with 4 policies (random, heuristic, scripted, GRPO) instead of 5.\n",
971
+ " print(f\"⚠ Could not load SFT-only model ({type(exc).__name__}: {exc})\")\n",
972
+ " print(\" Skipping SFT-vs-GRPO comparison row; eval proceeds with 4 policies.\")\n",
973
  " sft_only_model = None\n",
974
  " torch.cuda.empty_cache()\n",
975
  "\n",
 
1086
  },
1087
  {
1088
  "cell_type": "markdown",
1089
+ "id": "6b83f8c5",
1090
  "metadata": {},
1091
  "source": [
1092
  "## Cell 11 β€” Summary table + hero plot"
 
1095
  {
1096
  "cell_type": "code",
1097
  "execution_count": null,
1098
+ "id": "a569541c",
1099
  "metadata": {},
1100
  "outputs": [],
1101
  "source": [
 
1159
  },
1160
  {
1161
  "cell_type": "markdown",
1162
+ "id": "bd5c375f",
1163
  "metadata": {},
1164
  "source": [
1165
  "## Cell 12 β€” Package artifacts for download\n",
 
1171
  {
1172
  "cell_type": "code",
1173
  "execution_count": null,
1174
+ "id": "2823981e",
1175
  "metadata": {},
1176
  "outputs": [],
1177
  "source": [
notebooks/01_triage_train_grpo.py CHANGED
@@ -839,8 +839,12 @@ else:
839
  )
840
  FastLanguageModel.for_inference(sft_only_model)
841
  print("βœ“ Loaded SFT-only adapter for comparison")
842
- except (RuntimeError, torch.cuda.OutOfMemoryError) as exc:
843
- print(f"⚠ Could not load SFT-only model ({exc}) β€” skipping that comparison row")
 
 
 
 
844
  sft_only_model = None
845
  torch.cuda.empty_cache()
846
 
 
839
  )
840
  FastLanguageModel.for_inference(sft_only_model)
841
  print("βœ“ Loaded SFT-only adapter for comparison")
842
+ except Exception as exc:
843
+ # Catches OOM, ImportError (peft/transformers mismatch on tensor-parallel
844
+ # imports), AttributeError (Unsloth + adapter mismatch), etc. Eval still
845
+ # runs with 4 policies (random, heuristic, scripted, GRPO) instead of 5.
846
+ print(f"⚠ Could not load SFT-only model ({type(exc).__name__}: {exc})")
847
+ print(" Skipping SFT-vs-GRPO comparison row; eval proceeds with 4 policies.")
848
  sft_only_model = None
849
  torch.cuda.empty_cache()
850