walidsobhie-code Claude Opus 4.6 commited on
Commit
e5ae26c
·
1 Parent(s): d083607

Fix colab training notebook for local Mac MPS training

Browse files

- Fix JSON parsing error (extra closing braces)
- Convert from Colab/Google Drive to local training
- Update paths for local data
- Fix training and merge function calls
- Configure for MPS (Apple Silicon GPU)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. colab_train_stack29.ipynb +134 -137
colab_train_stack29.ipynb CHANGED
@@ -4,26 +4,18 @@
4
  "cell_type": "markdown",
5
  "metadata": {},
6
  "source": [
7
- "# 🚀 Stack 2.9 - Colab Training Notebook (Fixed)\n",
8
  "\n",
9
- "**Zero-cost training on Google Colab free tier**\n",
10
  "\n",
11
- "This notebook trains a LoRA adapter for Stack 2.9 Pattern Memory on **Qwen2.5-Coder-7B** using a free T4 GPU.\n",
12
- "\n",
13
- "⏱️ **Expected runtime:** 3-5 hours\n",
14
- "💾 **VRAM needed:** ~12GB (fits in T4's 15GB)\n",
15
- "📦 **Output:** `./model_final/` (merged)\n",
16
  "\n",
17
  "---\n",
18
  "\n",
19
- "**CRITICAL:** All data saved to **Google Drive** to persist through disconnects.\n",
20
- "\n",
21
- "**Instructions:**\n",
22
- "1. Runtime → Change runtime type → **GPU (T4)**\n",
23
- "2. Run all cells in order\n",
24
- "3. **Allow** Drive access when prompted\n",
25
- "\n",
26
- "---"
27
  ]
28
  },
29
  {
@@ -32,46 +24,32 @@
32
  "metadata": {},
33
  "outputs": [],
34
  "source": [
35
- "# Check GPU\n",
36
- "!nvidia-smi"
37
- ]
38
- },
39
- {
40
- "cell_type": "markdown",
41
- "metadata": {},
42
- "source": [
43
- "## 1️⃣ Mount Google Drive (REQUIRED for persistence)\n",
44
- "\n",
45
- "Click the link, allow access, copy the auth code, paste it, and press Enter.\n",
46
  "\n",
47
- "**Without Drive mounting, training will be lost if Colab disconnects!**"
48
- ]
49
- },
50
- {
51
- "cell_type": "code",
52
- "execution_count": null,
53
- "metadata": {},
54
- "outputs": [],
55
- "source": [
56
- "from google.colab import drive\n",
57
- "drive.mount('/content/drive')\n",
58
  "\n",
59
- "# Set up paths on Drive - ALL OUTPUT GOES HERE\n",
60
- "import os\n",
61
- "BASE_PATH = \"/content/drive/MyDrive/stack-2.9\"\n",
62
- "os.makedirs(BASE_PATH, exist_ok=True)\n",
63
- "os.chdir(BASE_PATH)\n",
64
- "print(f\"\\n✅ Working directory: {os.getcwd()}\")\n",
65
- "print(f\"All outputs will be saved to: {BASE_PATH}\")\n",
66
- "print(\"\\nCurrent folder contents:\")\n",
67
- "!ls -la"
68
  ]
69
  },
70
  {
71
  "cell_type": "markdown",
72
  "metadata": {},
73
  "source": [
74
- "## 2️⃣ Clone Stack 2.9 Repository"
75
  ]
76
  },
77
  {
@@ -80,22 +58,35 @@
80
  "metadata": {},
81
  "outputs": [],
82
  "source": [
83
- "# Clone into Drive if not already there\n",
84
- "if not os.path.exists('stack-2.9'):\n",
85
- " !git clone https://github.com/my-ai-stack/stack-2.9.git\n",
86
  "\n",
87
- "os.chdir('stack-2.9')\n",
88
- "print(f\"Now in: {os.getcwd()}\")\n",
89
- "!ls -la"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  ]
91
  },
92
  {
93
  "cell_type": "markdown",
94
  "metadata": {},
95
  "source": [
96
- "## 3️⃣ Install Dependencies\n",
97
- "\n",
98
- "Takes 5-10 minutes."
99
  ]
100
  },
101
  {
@@ -104,9 +95,10 @@
104
  "metadata": {},
105
  "outputs": [],
106
  "source": [
107
- "!pip install --upgrade pip\n",
108
- "!pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118\n",
109
- "!pip install transformers==4.40.0 peft==0.10.0 accelerate bitsandbytes==0.43.0 datasets pyyaml\n",
 
110
  "print(\"\\n✅ Dependencies installed\")"
111
  ]
112
  },
@@ -114,9 +106,7 @@
114
  "cell_type": "markdown",
115
  "metadata": {},
116
  "source": [
117
- "## 4️⃣ Create Mini Dataset (5K examples)\n",
118
- "\n",
119
- "Quick prototyping dataset - takes 1-2 minutes."
120
  ]
121
  },
122
  {
@@ -125,19 +115,41 @@
125
  "metadata": {},
126
  "outputs": [],
127
  "source": [
128
- "!python scripts/create_mini_dataset.py --size 5000 --output data_mini/train_mini.jsonl --source training-data/final/train.jsonl\n",
129
- "\n",
130
- "# Verify\n",
131
- "!ls -lh data_mini/train_mini.jsonl"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  ]
133
  },
134
  {
135
  "cell_type": "markdown",
136
  "metadata": {},
137
  "source": [
138
- "## 5️⃣ Prepare Training Configuration\n",
139
- "\n",
140
- "Use Colab-optimized config and point it to the mini dataset."
141
  ]
142
  },
143
  {
@@ -146,31 +158,36 @@
146
  "metadata": {},
147
  "outputs": [],
148
  "source": [
149
- "# Copy the Colab-optimized config\n",
150
- "!cp stack_2_9_training/train_config_colab.yaml stack_2_9_training/train_config.yaml\n",
151
- "\n",
152
- "# Update config to use mini dataset paths\n",
153
- "!sed -i 's|train_file: \"./training-data/train.jsonl\"|train_file: \"./data_mini/train_mini.jsonl\"|' stack_2_9_training/train_config.yaml\n",
154
- "!sed -i 's|validation_file: \"./training-data/eval.jsonl\"|# validation_file: \"./data_mini/eval_mini.jsonl\" # optional|' stack_2_9_training/train_config.yaml\n",
155
  "\n",
156
- "print(\"✅ Config prepared for mini dataset\")\n",
157
- "print(\"\\nTraining config (data section):\")\n",
158
- "!grep -A3 'data:' stack_2_9_training/train_config.yaml"
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  ]
160
  },
161
  {
162
  "cell_type": "markdown",
163
  "metadata": {},
164
  "source": [
165
- "## 6️⃣ Train LoRA Adapter\n",
166
  "\n",
167
- "⚠️ **This takes 3-5 hours. DO NOT INTERRUPT.**\n",
168
  "\n",
169
- "If Colab disconnects, reconnect and training will resume from checkpoint automatically.\n",
170
- "\n",
171
- "Watch for `Train loss:` decreasing. It should start ~2.0-3.0 and trend downward.\n",
172
- "\n",
173
- "Checkpoints saved every 500 steps to `./adapters_colab/` (on Drive)."
174
  ]
175
  },
176
  {
@@ -178,30 +195,13 @@
178
  "execution_count": null,
179
  "metadata": {},
180
  "outputs": [],
181
- "source": [
182
- "%env PYTHONUNBUFFERED=1\n",
183
- "\n",
184
- "print(\"\\n\" + \"=\"*60)\n",
185
- "print(\"STARTING TRAINING\")\n",
186
- "print(\"=\"*60)\n",
187
- "print(f\"Working directory: {os.getcwd()}\")\n",
188
- "print(f\"Config: stack_2_9_training/train_config.yaml\")\n",
189
- "print(f\"Output will be saved to: ./adapters_colab/\")\n",
190
- "print(\"=\"*60 + \"\\n\")\n",
191
- "\n",
192
- "!cd stack_2_9_training && python -m train_lora --config train_config.yaml\n",
193
- "\n",
194
- "print(\"\\n\" + \"=\"*60)\n",
195
- "print(\"TRAINING FINISHED OR STOPPED\")\n",
196
- "print(\"Check output above for errors or 'Training completed' message\")\n",
197
- "print(\"=\"*60)"
198
- ]
199
  },
200
  {
201
  "cell_type": "markdown",
202
  "metadata": {},
203
  "source": [
204
- "## 7️⃣ Verify Training Output"
205
  ]
206
  },
207
  {
@@ -210,17 +210,24 @@
210
  "metadata": {},
211
  "outputs": [],
212
  "source": [
213
- "!ls -la adapters_colab/ 2>/dev/null || echo \"⚠️ adapters_colab/ not found - training may have failed or not run yet\"\n",
214
- "!find adapters_colab -name \"*.bin\" -o -name \"*.safetensors\" 2>/dev/null | head -5 || echo \"No checkpoint files found\""
 
 
 
 
 
 
 
 
 
215
  ]
216
  },
217
  {
218
  "cell_type": "markdown",
219
  "metadata": {},
220
  "source": [
221
- "## 8️⃣ Merge LoRA Adapter with Base Model\n",
222
- "\n",
223
- "Combines the trained adapter with the base model to produce a standalone fine-tuned model."
224
  ]
225
  },
226
  {
@@ -228,18 +235,13 @@
228
  "execution_count": null,
229
  "metadata": {},
230
  "outputs": [],
231
- "source": [
232
- "!cd stack_2_9_training && python -m merge_adapter --base-model Qwen/Qwen2.5-Coder-7B\n",
233
- "\n",
234
- "print(\"\\n✅ Merged model created in ./model_final/\")\n",
235
- "!ls -lh model_final/"
236
- ]
237
  },
238
  {
239
  "cell_type": "markdown",
240
  "metadata": {},
241
  "source": [
242
- "## 9️⃣ Test Inference (Quick Check)"
243
  ]
244
  },
245
  {
@@ -251,20 +253,20 @@
251
  "from transformers import AutoTokenizer, AutoModelForCausalLM\n",
252
  "import torch\n",
253
  "\n",
254
- "model_path = \"./model_final\"\n",
255
  "print(f\"Loading model from {model_path}...\")\n",
256
  "\n",
257
  "try:\n",
258
  " tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)\n",
259
  " model = AutoModelForCausalLM.from_pretrained(\n",
260
  " model_path,\n",
261
- " torch_dtype=torch.bfloat16,\n",
262
- " device_map=\"auto\",\n",
263
  " trust_remote_code=True\n",
264
  " )\n",
265
  " \n",
266
  " prompt = \"Write a Python function to reverse a string:\\n\\n```python\\n\"\n",
267
- " inputs = tokenizer(prompt, return_tensors=\"pt\").to(model.device)\n",
268
  " \n",
269
  " print(\"Generating...\")\n",
270
  " with torch.no_grad():\n",
@@ -277,13 +279,13 @@
277
  " )\n",
278
  " \n",
279
  " response = tokenizer.decode(outputs[0], skip_special_tokens=True)\n",
280
- " print(\"=\\\"*40)\n",
281
  " print(\"RESPONSE:\")\n",
282
- " print(\"=\\\"*40)\n",
283
  " print(response[len(prompt):])\n",
284
  "except Exception as e:\n",
285
- " print(f\"❌ Error loading or running model: {e}\")\n",
286
- " print(\"\\nThis is expected if training hasn't completed yet or model files are missing.\")"
287
  ]
288
  },
289
  {
@@ -292,25 +294,21 @@
292
  "source": [
293
  "## 🔚 Training Complete!\n",
294
  "\n",
295
- "Your model is ready in `./model_final/` and saved to Google Drive.\n",
 
 
296
  "\n",
297
  "**Next steps:**\n",
298
- "1. **Download** `model_final/` from Drive to your local machine\n",
299
- "2. **Download datasets**: `python scripts/download_benchmark_datasets.py --benchmark both`\n",
300
- "3. **Run evaluation**: `python stack-2.9-eval/run_proper_evaluation.py --benchmark humaneval --provider ollama --model ./model_final --k-samples 100`\n",
301
- "4. **Upload model** to Hugging Face Hub\n",
302
- "5. **Apply to Together AI**\n",
303
- "\n",
304
- "**Note:** This model was trained on 5K mini dataset (code completion only). For better tool capability, consider training on full dataset with synthetic tool data in a future run.\n",
305
- "\n",
306
- "**Need help?** See `COLAB_TRAINING.md` for detailed troubleshooting."
307
  ]
308
  }
309
  ],
310
  "metadata": {
311
  "accelerator": "GPU",
312
  "colab": {
313
- "name": "Stack 2.9 Colab Training (Fixed)",
314
  "provenance": []
315
  },
316
  "kernelspec": {
@@ -323,5 +321,4 @@
323
  },
324
  "nbformat": 4,
325
  "nbformat_minor": 0
326
- }
327
- }
 
4
  "cell_type": "markdown",
5
  "metadata": {},
6
  "source": [
7
+ "# 🚀 Stack 2.9 - Local Training Notebook\n",
8
  "\n",
9
+ "**Training on local Mac with MPS (Apple Silicon GPU)**\n",
10
  "\n",
11
+ "This notebook trains a LoRA adapter for Stack 2.9 on **Qwen2.5-Coder-7B** using your local machine.\n",
 
 
 
 
12
  "\n",
13
  "---\n",
14
  "\n",
15
+ "**Prerequisites:**\n",
16
+ "1. Base model downloaded to `./base_model_qwen7b/`\n",
17
+ "2. Run from the stack-2.9 directory\n",
18
+ "---\n"
 
 
 
 
19
  ]
20
  },
21
  {
 
24
  "metadata": {},
25
  "outputs": [],
26
  "source": [
27
+ "# Check system and GPU\n",
28
+ "import platform\n",
29
+ "import os\n",
 
 
 
 
 
 
 
 
30
  "\n",
31
+ "print(\"=\"*60)\n",
32
+ "print(\"SYSTEM INFO\")\n",
33
+ "print(\"=\"*60)\n",
34
+ "print(f\"Platform: {platform.platform()}\")\n",
35
+ "print(f\"Python: {platform.python_version()}\")\n",
36
+ "print(f\"Working directory: {os.getcwd()}\")\n",
 
 
 
 
 
37
  "\n",
38
+ "try:\n",
39
+ " import torch\n",
40
+ " print(f\"PyTorch: {torch.__version__}\")\n",
41
+ " print(f\"MPS available: {torch.backends.mps.is_available()}\")\n",
42
+ " if torch.backends.mps.is_available():\n",
43
+ " print(f\"MPS device: {torch.backends.mps.is_built()}\")\n",
44
+ "except ImportError:\n",
45
+ " print(\"PyTorch not installed - run: pip install torch\")"
 
46
  ]
47
  },
48
  {
49
  "cell_type": "markdown",
50
  "metadata": {},
51
  "source": [
52
+ "## 1️⃣ Set Working Directory"
53
  ]
54
  },
55
  {
 
58
  "metadata": {},
59
  "outputs": [],
60
  "source": [
61
+ "# Navigate to the stack-2.9 directory\n",
62
+ "import os\n",
 
63
  "\n",
64
+ "STACK_PATH = \"/Users/walidsobhi/.openclaw/workspace/stack-2.9\"\n",
65
+ "os.chdir(STACK_PATH)\n",
66
+ "\n",
67
+ "BASE_MODEL_PATH = \"./base_model_qwen7b\"\n",
68
+ "DATA_PATH = \"./data/final/train.jsonl\"\n",
69
+ "OUTPUT_DIR = \"./training_output\"\n",
70
+ "\n",
71
+ "os.makedirs(OUTPUT_DIR, exist_ok=True)\n",
72
+ "\n",
73
+ "print(f\"✅ Working directory: {os.getcwd()}\")\n",
74
+ "print(f\"Base model path: {BASE_MODEL_PATH}\")\n",
75
+ "print(f\"Data path: {DATA_PATH}\")\n",
76
+ "print(f\"Output dir: {OUTPUT_DIR}\")\n",
77
+ "\n",
78
+ "# Check paths exist\n",
79
+ "print(\"\\n📁 Checking required files:\")\n",
80
+ "print(f\" - Data exists: {os.path.exists(DATA_PATH)}\")\n",
81
+ "if not os.path.exists(DATA_PATH):\n",
82
+ " print(f\" ⚠️ Data not found at {DATA_PATH}\")"
83
  ]
84
  },
85
  {
86
  "cell_type": "markdown",
87
  "metadata": {},
88
  "source": [
89
+ "## 2️⃣ Install Dependencies"
 
 
90
  ]
91
  },
92
  {
 
95
  "metadata": {},
96
  "outputs": [],
97
  "source": [
98
+ "# Install required packages\n",
99
+ "!pip install torch torchvision torchaudio\n",
100
+ "!pip install transformers peft accelerate datasets pyyaml tqdm\n",
101
+ "!pip install scipy\n",
102
  "print(\"\\n✅ Dependencies installed\")"
103
  ]
104
  },
 
106
  "cell_type": "markdown",
107
  "metadata": {},
108
  "source": [
109
+ "## 3️⃣ Prepare Training Configuration"
 
 
110
  ]
111
  },
112
  {
 
115
  "metadata": {},
116
  "outputs": [],
117
  "source": [
118
+ "# Use local training config\n",
119
+ "import yaml\n",
120
+ "\n",
121
+ "config_path = \"./stack/training/train_config_local.yaml\"\n",
122
+ "\n",
123
+ "with open(config_path, 'r') as f:\n",
124
+ " config = yaml.safe_load(f)\n",
125
+ "\n",
126
+ "# Update paths to match our setup\n",
127
+ "config['model']['name'] = BASE_MODEL_PATH\n",
128
+ "config['data']['input_path'] = DATA_PATH\n",
129
+ "config['output']['lora_dir'] = f\"{OUTPUT_DIR}/lora\"\n",
130
+ "config['output']['merged_dir'] = f\"{OUTPUT_DIR}/merged\"\n",
131
+ "config['hardware']['device'] = \"mps\"\n",
132
+ "\n",
133
+ "# Save updated config\n",
134
+ "updated_config_path = f\"{OUTPUT_DIR}/train_config.yaml\"\n",
135
+ "os.makedirs(OUTPUT_DIR, exist_ok=True)\n",
136
+ "\n",
137
+ "with open(updated_config_path, 'w') as f:\n",
138
+ " yaml.dump(config, f)\n",
139
+ "\n",
140
+ "print(f\"✅ Config saved to: {updated_config_path}\")\n",
141
+ "print(\"\\nConfig summary:\")\n",
142
+ "print(f\" - Model: {config['model']['name']}\")\n",
143
+ "print(f\" - Data: {config['data']['input_path']}\")\n",
144
+ "print(f\" - Device: {config['hardware']['device']}\")\n",
145
+ "print(f\" - Epochs: {config['training']['num_epochs']}\")"
146
  ]
147
  },
148
  {
149
  "cell_type": "markdown",
150
  "metadata": {},
151
  "source": [
152
+ "## 4️⃣ Check Base Model"
 
 
153
  ]
154
  },
155
  {
 
158
  "metadata": {},
159
  "outputs": [],
160
  "source": [
161
+ "# Check if base model exists\n",
162
+ "import os\n",
 
 
 
 
163
  "\n",
164
+ "model_path = BASE_MODEL_PATH\n",
165
+ "print(f\"Checking base model at: {model_path}\")\n",
166
+ "\n",
167
+ "if os.path.exists(model_path):\n",
168
+ " files = os.listdir(model_path)\n",
169
+ " print(f\"✅ Base model found! {len(files)} files:\")\n",
170
+ " for f in files[:10]:\n",
171
+ " print(f\" - {f}\")\n",
172
+ " if len(files) > 10:\n",
173
+ " print(f\" ... and {len(files)-10} more\")\n",
174
+ "else:\n",
175
+ " print(\"❌ Base model NOT found!\")\n",
176
+ " print(\"\\nTo download Qwen2.5-Coder-7B:\")\n",
177
+ " print(\" huggingface-cli download Qwen/Qwen2.5-Coder-7B --local-dir ./base_model_qwen7b\")\n",
178
+ " print(\" OR\")\n",
179
+ " print(\" python -c \\\"from transformers import AutoModelForCausalLM; AutoModelForCausalLM.from_pretrained('Qwen/Qwen2.5-Coder-7B', local_dir='./base_model_qwen7b')\\\"\")"
180
  ]
181
  },
182
  {
183
  "cell_type": "markdown",
184
  "metadata": {},
185
  "source": [
186
+ "## 5️⃣ Train LoRA Adapter\n",
187
  "\n",
188
+ "⚠️ **This will take significant time on MPS.**\n",
189
  "\n",
190
+ "MPS is slower than CUDA, so training will take longer. Consider using a smaller dataset for testing."
 
 
 
 
191
  ]
192
  },
193
  {
 
195
  "execution_count": null,
196
  "metadata": {},
197
  "outputs": [],
198
+ "source": "import os\nimport sys\n\n# Add the training module to path\nsys.path.insert(0, './stack/training')\n\nprint(\"=\"*60)\nprint(\"STARTING TRAINING\")\nprint(\"=\"*60)\nprint(f\"Working directory: {os.getcwd()}\")\nprint(f\"Config: {updated_config_path}\")\nprint(f\"Output: {OUTPUT_DIR}/lora\")\nprint(\"=\"*60 + \"\\n\")\n\n# Run training using the correct function\nfrom train_lora import train_lora\n\ntrainer = train_lora(updated_config_path)\n\nprint(\"\\n\" + \"=\"*60)\nprint(\"TRAINING COMPLETED\")\nprint(\"=\"*60)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  },
200
  {
201
  "cell_type": "markdown",
202
  "metadata": {},
203
  "source": [
204
+ "## 6️⃣ Verify Training Output"
205
  ]
206
  },
207
  {
 
210
  "metadata": {},
211
  "outputs": [],
212
  "source": [
213
+ "lora_dir = f\"{OUTPUT_DIR}/lora\"\n",
214
+ "print(f\"Checking LoRA output: {lora_dir}\")\n",
215
+ "\n",
216
+ "if os.path.exists(lora_dir):\n",
217
+ " files = os.listdir(lora_dir)\n",
218
+ " print(f\"✅ LoRA adapter found! {len(files)} files:\")\n",
219
+ " for f in files:\n",
220
+ " size = os.path.getsize(os.path.join(lora_dir, f)) / (1024*1024)\n",
221
+ " print(f\" - {f}: {size:.1f} MB\")\n",
222
+ "else:\n",
223
+ " print(\"⚠️ LoRA directory not found\")"
224
  ]
225
  },
226
  {
227
  "cell_type": "markdown",
228
  "metadata": {},
229
  "source": [
230
+ "## 7️⃣ Merge LoRA Adapter (Optional)"
 
 
231
  ]
232
  },
233
  {
 
235
  "execution_count": null,
236
  "metadata": {},
237
  "outputs": [],
238
+ "source": "# Merge LoRA with base model\nmerged_dir = f\"{OUTPUT_DIR}/merged\"\n\nprint(\"=\"*60)\nprint(\"MERGING LORA ADAPTER\")\nprint(\"=\"*60)\n\nsys.path.insert(0, './stack/training')\nfrom merge_adapter import merge_adapter\n\n# Create a minimal config for merging\nimport yaml\n\nmerge_config = {\n 'model': {'name': BASE_MODEL_PATH, 'trust_remote_code': True},\n 'output': {'lora_dir': f'{OUTPUT_DIR}/lora', 'merged_dir': merged_dir},\n 'quantization': {'enabled': False}\n}\n\n# Save config for merge\nmerge_config_path = f\"{OUTPUT_DIR}/merge_config.yaml\"\nwith open(merge_config_path, 'w') as f:\n yaml.dump(merge_config, f)\n\n# Run merge\nmerge_adapter(\n config_path=merge_config_path,\n lora_path=f\"{OUTPUT_DIR}/lora\",\n output_path=merged_dir\n)\n\nprint(f\"\\n✅ Merged model saved to: {merged_dir}\")\nif os.path.exists(merged_dir):\n print(\"Files:\", os.listdir(merged_dir)[:5])"
 
 
 
 
 
239
  },
240
  {
241
  "cell_type": "markdown",
242
  "metadata": {},
243
  "source": [
244
+ "## 8️⃣ Test Inference"
245
  ]
246
  },
247
  {
 
253
  "from transformers import AutoTokenizer, AutoModelForCausalLM\n",
254
  "import torch\n",
255
  "\n",
256
+ "model_path = f\"{OUTPUT_DIR}/merged\"\n",
257
  "print(f\"Loading model from {model_path}...\")\n",
258
  "\n",
259
  "try:\n",
260
  " tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)\n",
261
  " model = AutoModelForCausalLM.from_pretrained(\n",
262
  " model_path,\n",
263
+ " torch_dtype=torch.float16,\n",
264
+ " device_map=\"mps\",\n",
265
  " trust_remote_code=True\n",
266
  " )\n",
267
  " \n",
268
  " prompt = \"Write a Python function to reverse a string:\\n\\n```python\\n\"\n",
269
+ " inputs = tokenizer(prompt, return_tensors=\"pt\").to(\"mps\")\n",
270
  " \n",
271
  " print(\"Generating...\")\n",
272
  " with torch.no_grad():\n",
 
279
  " )\n",
280
  " \n",
281
  " response = tokenizer.decode(outputs[0], skip_special_tokens=True)\n",
282
+ " print(\"=\"*40)\n",
283
  " print(\"RESPONSE:\")\n",
284
+ " print(\"=\"*40)\n",
285
  " print(response[len(prompt):])\n",
286
  "except Exception as e:\n",
287
+ " print(f\"❌ Error: {e}\")\n",
288
+ " print(\"\\nThis is expected if training hasn't completed yet.\")"
289
  ]
290
  },
291
  {
 
294
  "source": [
295
  "## 🔚 Training Complete!\n",
296
  "\n",
297
+ "Your model is ready in:\n",
298
+ "- LoRA adapter: `{OUTPUT_DIR}/lora/`\n",
299
+ "- Merged model: `{OUTPUT_DIR}/merged/`\n",
300
  "\n",
301
  "**Next steps:**\n",
302
+ "1. Run evaluation on HumanEval/MBPP benchmarks\n",
303
+ "2. Upload to Hugging Face Hub\n",
304
+ "3. Apply to Together AI\n"
 
 
 
 
 
 
305
  ]
306
  }
307
  ],
308
  "metadata": {
309
  "accelerator": "GPU",
310
  "colab": {
311
+ "name": "Stack 2.9 Local Training (Fixed)",
312
  "provenance": []
313
  },
314
  "kernelspec": {
 
321
  },
322
  "nbformat": 4,
323
  "nbformat_minor": 0
324
+ }