mindsofchaos commited on
Commit
0410d58
·
verified ·
1 Parent(s): 06e5535

Upload codeoptics_v3_5_hybrid_benchmark.ipynb with huggingface_hub

Browse files
codeoptics_v3_5_hybrid_benchmark.ipynb ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# CodeOptics-Coder v3.5: Hybrid Dual-Mode Benchmark\n",
8
+ "### Empirical Evaluation on Tesla T4 GPU (Kaggle)\n",
9
+ "\n",
10
+ "**Dual-Mode Architecture**:\n",
11
+ "- **Mode 1 (Fast-Path Reflexive)**: Direct synthesis without scratchpad overhead for pure functional & algorithmic tasks (HumanEval, string/math scripts).\n",
12
+ "- **Mode 2 (Deep Second-Order Architect)**: Full 4-part invariant scratchpad for Concurrency, Thread-Safety, State Invariants, and Classes (CEB-15, ClassEval).\n",
13
+ "- **Layer 0 (Compile-Time Hygiene)**: Automatic typing & standard library import injection.\n",
14
+ "- **Layer 4 (Actor-Critic Self-Healing)**: Traceback compiler feedback for functions and multi-method classes."
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": null,
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "# Cell 1: Hardware Preflight & Ollama GPU Setup\n",
24
+ "import os, sys, time, subprocess, urllib.request\n",
25
+ "\n",
26
+ "print('=' * 75)\n",
27
+ "print('[1/4] Hardware Preflight & Ollama GPU Setup')\n",
28
+ "print('=' * 75)\n",
29
+ "\n",
30
+ "# Kill any old daemon and install required GPU detection utilities\n",
31
+ "subprocess.run('pkill -9 ollama', shell=True)\n",
32
+ "subprocess.run('apt-get update -y && apt-get install -y pciutils zstd', shell=True, check=True)\n",
33
+ "subprocess.run('curl -fsSL https://ollama.com/install.sh | sh', shell=True, check=True)\n",
34
+ "\n",
35
+ "# Launch Ollama background daemon on GPU\n",
36
+ "subprocess.Popen(['ollama', 'serve'], stdout=open('/tmp/ollama.log', 'w'), stderr=subprocess.STDOUT)\n",
37
+ "for _ in range(15):\n",
38
+ " time.sleep(1)\n",
39
+ " try:\n",
40
+ " urllib.request.urlopen('http://127.0.0.1:11434/api/tags', timeout=2)\n",
41
+ " print('[+] Ollama daemon active and listening on Tesla T4 GPU!')\n",
42
+ " break\n",
43
+ " except Exception:\n",
44
+ " pass\n",
45
+ "\n",
46
+ "subprocess.run(['nvidia-smi'], check=False)"
47
+ ]
48
+ },
49
+ {
50
+ "cell_type": "code",
51
+ "execution_count": null,
52
+ "metadata": {},
53
+ "outputs": [],
54
+ "source": [
55
+ "# Cell 2: Register Model in Ollama with Stop Tokens\n",
56
+ "print('=' * 75)\n",
57
+ "print('[2/4] Registering Model in Ollama')\n",
58
+ "print('=' * 75)\n",
59
+ "\n",
60
+ "gguf_path = '/kaggle/working/codeoptic-coder-v3.1-q4_k_m.gguf'\n",
61
+ "if not os.path.exists(gguf_path):\n",
62
+ " for alt in ['/tmp/codeoptic-coder-v3.1-q4_k_m.gguf', 'codeoptic-coder-v3.1-q4_k_m.gguf']:\n",
63
+ " if os.path.exists(alt):\n",
64
+ " gguf_path = os.path.abspath(alt)\n",
65
+ " break\n",
66
+ "\n",
67
+ "if not os.path.exists(gguf_path):\n",
68
+ " print('[*] Downloading GGUF from Hugging Face...')\n",
69
+ " gguf_url = 'https://huggingface.co/mindsofchaos/codeoptics-coder-3b-v3-1/resolve/main/codeoptic-coder-v3.1-q4_k_m.gguf'\n",
70
+ " subprocess.run(['wget', '-q', '--show-progress', gguf_url, '-O', gguf_path], check=True)\n",
71
+ "\n",
72
+ "modelfile = f'''FROM {gguf_path}\n",
73
+ "PARAMETER temperature 0.1\n",
74
+ "PARAMETER top_p 0.85\n",
75
+ "PARAMETER num_ctx 8192\n",
76
+ "PARAMETER num_predict 2048\n",
77
+ "PARAMETER stop \"<|im_end|>\"\n",
78
+ "PARAMETER stop \"<|im_start|>\"\n",
79
+ "PARAMETER stop \"<|endoftext|>\"\n",
80
+ "'''\n",
81
+ "with open('/tmp/Modelfile.v3_5', 'w') as f:\n",
82
+ " f.write(modelfile)\n",
83
+ "\n",
84
+ "subprocess.run(['ollama', 'create', 'codeoptic-coder:v3.1', '-f', '/tmp/Modelfile.v3_5'], check=True)\n",
85
+ "print('[+] Model registered in Ollama successfully!')\n",
86
+ "\n",
87
+ "# Quick sanity check\n",
88
+ "t0 = time.time()\n",
89
+ "res = subprocess.run(['ollama', 'run', 'codeoptic-coder:v3.1', 'Output: print(\"READY\")'], capture_output=True, text=True)\n",
90
+ "print(f'[+] Sanity check speed: {time.time()-t0:.2f}s | Output: {res.stdout.strip()[:60]}')"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": null,
96
+ "metadata": {},
97
+ "outputs": [],
98
+ "source": [
99
+ "# Cell 3: Pull and Unpack CodeOptics v3.5 Benchmark Suite\n",
100
+ "print('=' * 75)\n",
101
+ "print('[3/4] Pulling CodeOptics v3.5 Hybrid Suite')\n",
102
+ "print('=' * 75)\n",
103
+ "\n",
104
+ "url = 'https://huggingface.co/mindsofchaos/codeoptics-coder-3b-v3-1/resolve/main/codeoptics_benchmark_suite.tar.gz'\n",
105
+ "subprocess.run(['wget', '-q', url, '-O', '/tmp/codeoptics_benchmark_suite.tar.gz'], check=True)\n",
106
+ "subprocess.run(['tar', '-xzf', '/tmp/codeoptics_benchmark_suite.tar.gz', '-C', '/kaggle/working/'], check=True)\n",
107
+ "print('[+] CodeOptics v3.5 Hybrid Engine & Runners unpacked in /kaggle/working/codeoptics/!')"
108
+ ]
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "execution_count": null,
113
+ "metadata": {},
114
+ "outputs": [],
115
+ "source": [
116
+ "# Cell 4: Execute the Full Hybrid Dual-Mode Benchmark Suite\n",
117
+ "import os, sys, time, subprocess\n",
118
+ "\n",
119
+ "print('=' * 75)\n",
120
+ "print('[4/4] Executing Hybrid Dual-Mode Benchmark Suite (v3.5)')\n",
121
+ "print('=' * 75)\n",
122
+ "\n",
123
+ "os.chdir('/kaggle/working')\n",
124
+ "t_start = time.time()\n",
125
+ "subprocess.run([sys.executable, '-u', 'codeoptics/benchmark/hybrid_runner_v3_5.py', 'codeoptic-coder:v3.1'], check=True)\n",
126
+ "print(f'\\n[SUCCESS] Entire Hybrid Benchmark Suite completed in {time.time() - t_start:.1f}s!')"
127
+ ]
128
+ }
129
+ ],
130
+ "metadata": {
131
+ "kernelspec": {
132
+ "display_name": "Python 3",
133
+ "language": "python",
134
+ "name": "python3"
135
+ },
136
+ "language_info": {
137
+ "name": "python",
138
+ "version": "3.10.12"
139
+ }
140
+ },
141
+ "nbformat": 4,
142
+ "nbformat_minor": 4
143
+ }