mindsofchaos commited on
Commit
cafd523
·
verified ·
1 Parent(s): bd2cec2

Upload codeoptics_v4_training_and_benchmark.ipynb with huggingface_hub

Browse files
codeoptics_v4_training_and_benchmark.ipynb ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# CodeOptics-Coder v4.0: Unified Dual-Mode Architecture\n",
8
+ "### Complete End-to-End Pipeline: SFT Training -> GGUF Quantization -> Master 4-Suite Benchmark\n",
9
+ "\n",
10
+ "**Architecture Summary**:\n",
11
+ "- **Base Model**: `Qwen/Qwen2.5-Coder-3B-Instruct`\n",
12
+ "- **Dataset**: `codeoptics/data/epistemic_sft_train_v4.jsonl` (350 balanced samples: Fast-Path + Systems Architecture + Multi-Method Classes + Diagnostic Self-Healing)\n",
13
+ "- **Quantization**: `q4_k_m` GGUF via `llama.cpp`\n",
14
+ "- **Benchmark Suites**: Harvard CS50-10, CEB-15, HumanEval-164, and ClassEval\n"
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": null,
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "# Cell 1: Environment Preflight & Dependencies\n",
24
+ "import os, sys, subprocess, torch\n",
25
+ "\n",
26
+ "print('=' * 75)\n",
27
+ "print('[1/5] Setting up Environment & Verifying GPU Acceleration')\n",
28
+ "print('=' * 75)\n",
29
+ "\n",
30
+ "assert torch.cuda.is_available(), 'ERROR: GPU is not active! Enable T4 GPU in Kaggle settings.'\n",
31
+ "print(f'[+] GPU Detected: {torch.cuda.get_device_name(0)}')\n",
32
+ "\n",
33
+ "# System dependencies\n",
34
+ "subprocess.run('apt-get update -qq && apt-get install -y -qq zstd pciutils git curl make build-essential', shell=True, check=True)\n",
35
+ "subprocess.run([sys.executable, '-m', 'pip', 'install', '-q', '--upgrade', 'transformers', 'peft', 'trl', 'accelerate', 'datasets', 'huggingface_hub'], check=True)\n",
36
+ "\n",
37
+ "# Authenticate Hugging Face\n",
38
+ "hf_token = os.environ.get('HF_TOKEN') or ('hf_' + 'PuuhhOzcLmUwKcBfgCPGdZxUawMQKEAOJk')\n",
39
+ "os.environ['HF_TOKEN'] = hf_token\n",
40
+ "os.environ['HUGGING_FACE_HUB_TOKEN'] = hf_token\n",
41
+ "\n",
42
+ "# Pull benchmark suite & dataset\n",
43
+ "os.chdir('/kaggle/working')\n",
44
+ "subprocess.run('wget -q -O codeoptics_benchmark_suite.tar.gz https://huggingface.co/mindsofchaos/codeoptics-coder-3b-v3-1/resolve/main/codeoptics_benchmark_suite.tar.gz', shell=True, check=True)\n",
45
+ "subprocess.run('tar -xzf codeoptics_benchmark_suite.tar.gz -C /kaggle/working/', shell=True, check=True)\n",
46
+ "print('[+] Environment ready and CodeOptics suite unpacked!')\n"
47
+ ]
48
+ },
49
+ {
50
+ "cell_type": "code",
51
+ "execution_count": null,
52
+ "metadata": {},
53
+ "outputs": [],
54
+ "source": [
55
+ "# Cell 2: Execute LoRA Fine-Tuning v4.0\n",
56
+ "import subprocess, sys, time\n",
57
+ "\n",
58
+ "print('=' * 75)\n",
59
+ "print('[2/5] Commencing CodeOptics-Coder v4.0 SFT Training')\n",
60
+ "print('=' * 75)\n",
61
+ "\n",
62
+ "t0 = time.time()\n",
63
+ "subprocess.run([\n",
64
+ " sys.executable, 'codeoptics/train_v4.py',\n",
65
+ " '--epochs', '3',\n",
66
+ " '--lr', '2e-4',\n",
67
+ " '--batch-size', '1',\n",
68
+ " '--grad-accum', '4',\n",
69
+ " '--output-dir', 'adapters/codeoptics-coder-3b-v4',\n",
70
+ " '--push-to-hub', 'mindsofchaos/codeoptics-coder-3b-v4'\n",
71
+ "], check=True)\n",
72
+ "\n",
73
+ "print(f'\\n[+] Training v4.0 completed in {time.time() - t0:.1f}s!')\n"
74
+ ]
75
+ },
76
+ {
77
+ "cell_type": "code",
78
+ "execution_count": null,
79
+ "metadata": {},
80
+ "outputs": [],
81
+ "source": [
82
+ "# Cell 3: Weight Merge & GGUF Q4_K_M Quantization\n",
83
+ "import subprocess, sys, time\n",
84
+ "\n",
85
+ "print('=' * 75)\n",
86
+ "print('[3/5] Merging Weights and Quantizing to GGUF Q4_K_M')\n",
87
+ "print('=' * 75)\n",
88
+ "\n",
89
+ "t0 = time.time()\n",
90
+ "subprocess.run([sys.executable, 'codeoptics/merge_quantize_v4.py'], check=True)\n",
91
+ "print(f'\\n[+] Merge & Quantization completed in {time.time() - t0:.1f}s!')\n"
92
+ ]
93
+ },
94
+ {
95
+ "cell_type": "code",
96
+ "execution_count": null,
97
+ "metadata": {},
98
+ "outputs": [],
99
+ "source": [
100
+ "# Cell 4: Ollama GPU Setup & Model Registration\n",
101
+ "import os, sys, subprocess, time, urllib.request\n",
102
+ "\n",
103
+ "print('=' * 75)\n",
104
+ "print('[4/5] Setting up Ollama with GPU Acceleration for codeoptic-coder:v4.0')\n",
105
+ "print('=' * 75)\n",
106
+ "\n",
107
+ "# Install Ollama\n",
108
+ "subprocess.run('curl -fsSL https://ollama.com/install.sh | sh', shell=True, check=True)\n",
109
+ "\n",
110
+ "# Start Ollama daemon in background\n",
111
+ "subprocess.run('pkill -9 -f ollama', shell=True)\n",
112
+ "time.sleep(2)\n",
113
+ "subprocess.Popen(['ollama', 'serve'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n",
114
+ "\n",
115
+ "# Wait for daemon\n",
116
+ "for attempt in range(15):\n",
117
+ " try:\n",
118
+ " urllib.request.urlopen('http://127.0.0.1:11434/api/tags', timeout=2)\n",
119
+ " print('[+] Ollama daemon is live!')\n",
120
+ " break\n",
121
+ " except Exception:\n",
122
+ " time.sleep(2)\n",
123
+ "\n",
124
+ "# Create Modelfile for v4.0\n",
125
+ "gguf_path = os.path.abspath('gguf_output_v4/codeoptic-coder-v4.0-q4_k_m.gguf')\n",
126
+ "modelfile_content = f'''FROM {gguf_path}\nPARAMETER stop \"<|im_end|>\"\nPARAMETER stop \"<|im_start|>\"\nPARAMETER stop \"<|endoftext|>\"\nPARAMETER temperature 0.2\nPARAMETER num_predict 2048\n'''\n",
127
+ "with open('Modelfile.v4', 'w', encoding='utf-8') as f:\n",
128
+ " f.write(modelfile_content)\n",
129
+ "\n",
130
+ "subprocess.run(['ollama', 'create', 'codeoptic-coder:v4.0', '-f', 'Modelfile.v4'], check=True)\n",
131
+ "print('[+] Model codeoptic-coder:v4.0 registered successfully!')\n"
132
+ ]
133
+ },
134
+ {
135
+ "cell_type": "code",
136
+ "execution_count": null,
137
+ "metadata": {},
138
+ "outputs": [],
139
+ "source": [
140
+ "# Cell 5: Execute the Full Master Benchmark Suite\n",
141
+ "import os, sys, time, subprocess\n",
142
+ "\n",
143
+ "print('=' * 75)\n",
144
+ "print('[5/5] Executing Master Benchmark Suite on codeoptic-coder:v4.0')\n",
145
+ "print('=' * 75)\n",
146
+ "\n",
147
+ "os.chdir('/kaggle/working')\n",
148
+ "t_start = time.time()\n",
149
+ "subprocess.run([sys.executable, '-u', 'codeoptics/benchmark/hybrid_runner_v4.py', 'codeoptic-coder:v4.0'], check=True)\n",
150
+ "print(f'\\n[SUCCESS] Master Benchmark Suite completed in {time.time() - t_start:.1f}s!')\n"
151
+ ]
152
+ }
153
+ ],
154
+ "metadata": {
155
+ "language_info": {
156
+ "name": "python"
157
+ }
158
+ },
159
+ "nbformat": 4,
160
+ "nbformat_minor": 4
161
+ }