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