mindsofchaos commited on
Commit
d2f892e
·
verified ·
1 Parent(s): 55113eb

Upload codeoptics_v4_training_and_benchmark.ipynb with huggingface_hub

Browse files
codeoptics_v4_training_and_benchmark.ipynb CHANGED
@@ -7,11 +7,14 @@
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
  {
@@ -20,30 +23,38 @@
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
  {
@@ -52,11 +63,13 @@
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",
@@ -79,11 +92,13 @@
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",
@@ -97,7 +112,9 @@
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",
@@ -128,7 +145,7 @@
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
  {
@@ -137,7 +154,9 @@
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",
@@ -152,6 +171,10 @@
152
  }
153
  ],
154
  "metadata": {
 
 
 
 
155
  "language_info": {
156
  "name": "python"
157
  }
 
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
+ "**Hardware Acceleration**: Free Tesla T4 GPU (or Dual T4 / P100) on Kaggle\n",
11
+ "\n",
12
+ "**Pipeline Stages**:\n",
13
+ "1. **Preflight**: Verify GPU, install modern compilation tools (`cmake`, `zstd`, `pciutils`) and unpack benchmark suite\n",
14
+ "2. **SFT Training (v4.0)**: LoRA r=16, alpha=32 on all 7 linear projections with completion-only loss across 350 balanced samples\n",
15
+ "3. **Weight Merge & GGUF Quantization**: Merge LoRA into base weights, build `llama.cpp` via CMake, verify RoPE 1,000,000, quantize to `q4_k_m`\n",
16
+ "4. **Ollama GPU Deployment**: Start Ollama daemon, build Modelfile, register `codeoptic-coder:v4.0`\n",
17
+ "5. **Master 4-Suite Benchmark**: Harvard CS50-10, CEB-15, HumanEval-164, and ClassEval\n"
18
  ]
19
  },
20
  {
 
23
  "metadata": {},
24
  "outputs": [],
25
  "source": [
26
+ "# ==============================================================================\n",
27
  "# Cell 1: Environment Preflight & Dependencies\n",
28
+ "# ==============================================================================\n",
29
  "import os, sys, subprocess, torch\n",
30
  "\n",
31
  "print('=' * 75)\n",
32
  "print('[1/5] Setting up Environment & Verifying GPU Acceleration')\n",
33
  "print('=' * 75)\n",
34
  "\n",
35
+ "assert torch.cuda.is_available(), 'ERROR: GPU is not active! Enable T4 GPU in Kaggle Notebook Settings (right sidebar -> Accelerator -> GPU T4 x2 or GPU T4).'\n",
36
+ "gpu_name = torch.cuda.get_device_name(0)\n",
37
+ "gpu_mem = torch.cuda.get_device_properties(0).total_memory / (1024**3)\n",
38
+ "print(f'[+] GPU Active: {gpu_name} ({gpu_mem:.1f} GB VRAM)')\n",
39
  "\n",
40
+ "# System dependencies (including cmake for llama.cpp compilation)\n",
41
+ "print('[*] Installing system packages (cmake, zstd, pciutils, build-essential)...')\n",
42
+ "subprocess.run('apt-get update -qq && apt-get install -y -qq cmake zstd pciutils git curl make build-essential', shell=True, check=True)\n",
43
+ "\n",
44
+ "print('[*] Installing Python ML dependencies...')\n",
45
+ "subprocess.run([sys.executable, '-m', 'pip', 'install', '-q', '--upgrade', 'transformers', 'peft', 'trl', 'accelerate', 'datasets', 'huggingface_hub', 'gguf'], check=True)\n",
46
  "\n",
47
  "# Authenticate Hugging Face\n",
48
  "hf_token = os.environ.get('HF_TOKEN') or ('hf_' + 'PuuhhOzcLmUwKcBfgCPGdZxUawMQKEAOJk')\n",
49
  "os.environ['HF_TOKEN'] = hf_token\n",
50
  "os.environ['HUGGING_FACE_HUB_TOKEN'] = hf_token\n",
51
  "\n",
52
+ "# Unpack master benchmark suite\n",
53
  "os.chdir('/kaggle/working')\n",
54
+ "print('[*] Pulling CodeOptics master benchmark suite and dataset...')\n",
55
+ "subprocess.run('wget -q -O codeoptics_benchmark_suite.tar.gz https://huggingface.co/mindsofchaos/codeoptics-coder-3b-v4/resolve/main/codeoptics_benchmark_suite.tar.gz', shell=True, check=True)\n",
56
  "subprocess.run('tar -xzf codeoptics_benchmark_suite.tar.gz -C /kaggle/working/', shell=True, check=True)\n",
57
+ "print('[+] Environment ready and CodeOptics suite unpacked successfully!\\n')\n"
58
  ]
59
  },
60
  {
 
63
  "metadata": {},
64
  "outputs": [],
65
  "source": [
66
+ "# ==============================================================================\n",
67
+ "# Cell 2: Execute LoRA Fine-Tuning v4.0 (Dual-Mode SFT)\n",
68
+ "# ==============================================================================\n",
69
  "import subprocess, sys, time\n",
70
  "\n",
71
  "print('=' * 75)\n",
72
+ "print('[2/5] Commencing CodeOptics-Coder v4.0 SFT Training (350 Unified Samples)')\n",
73
  "print('=' * 75)\n",
74
  "\n",
75
  "t0 = time.time()\n",
 
92
  "metadata": {},
93
  "outputs": [],
94
  "source": [
95
+ "# ==============================================================================\n",
96
  "# Cell 3: Weight Merge & GGUF Q4_K_M Quantization\n",
97
+ "# ==============================================================================\n",
98
  "import subprocess, sys, time\n",
99
  "\n",
100
  "print('=' * 75)\n",
101
+ "print('[3/5] Merging Weights, Compiling llama.cpp via CMake & Quantizing to Q4_K_M')\n",
102
  "print('=' * 75)\n",
103
  "\n",
104
  "t0 = time.time()\n",
 
112
  "metadata": {},
113
  "outputs": [],
114
  "source": [
115
+ "# ==============================================================================\n",
116
  "# Cell 4: Ollama GPU Setup & Model Registration\n",
117
+ "# ==============================================================================\n",
118
  "import os, sys, subprocess, time, urllib.request\n",
119
  "\n",
120
  "print('=' * 75)\n",
 
145
  " f.write(modelfile_content)\n",
146
  "\n",
147
  "subprocess.run(['ollama', 'create', 'codeoptic-coder:v4.0', '-f', 'Modelfile.v4'], check=True)\n",
148
+ "print('[+] Model codeoptic-coder:v4.0 registered successfully with Ollama GPU runtime!')\n"
149
  ]
150
  },
151
  {
 
154
  "metadata": {},
155
  "outputs": [],
156
  "source": [
157
+ "# ==============================================================================\n",
158
+ "# Cell 5: Execute the Full Master Benchmark Suite (4 Benchmarks)\n",
159
+ "# ==============================================================================\n",
160
  "import os, sys, time, subprocess\n",
161
  "\n",
162
  "print('=' * 75)\n",
 
171
  }
172
  ],
173
  "metadata": {
174
+ "accelerator": "GPU",
175
+ "colab": {
176
+ "gpuType": "T4"
177
+ },
178
  "language_info": {
179
  "name": "python"
180
  }