Auroraventures commited on
Commit
faea26e
·
verified ·
1 Parent(s): b1489f9

Upload cipher-host-colab.ipynb with huggingface_hub

Browse files
Files changed (1) hide show
  1. cipher-host-colab.ipynb +148 -0
cipher-host-colab.ipynb ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# Cipher — Hosted on Colab Pro+ A100\n",
8
+ "\n",
9
+ "Spins up Cipher (kin-cipher) on this Colab GPU and exposes it via cloudflared tunnel.\n",
10
+ "Use the printed URL from your laptop for fast generation.\n",
11
+ "\n",
12
+ "**Runtime needed:** A100 (Colab Pro+). At T4 it'll work but slower (~5-10 t/s)."
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "code",
17
+ "metadata": {},
18
+ "execution_count": null,
19
+ "outputs": [],
20
+ "source": [
21
+ "# Cell 1 — install Ollama + cloudflared + curl\n",
22
+ "import os, subprocess, time\n",
23
+ "\n",
24
+ "print('Installing Ollama...')\n",
25
+ "subprocess.run('curl -fsSL https://ollama.com/install.sh | sh', shell=True, check=True)\n",
26
+ "\n",
27
+ "print('Downloading cloudflared...')\n",
28
+ "subprocess.run('wget -qq https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -O /usr/local/bin/cloudflared && chmod +x /usr/local/bin/cloudflared', shell=True, check=True)\n",
29
+ "\n",
30
+ "print('Done.')"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "metadata": {},
36
+ "execution_count": null,
37
+ "outputs": [],
38
+ "source": [
39
+ "# Cell 2 — start Ollama serve in background\n",
40
+ "import subprocess, time, os\n",
41
+ "\n",
42
+ "# kill any existing\n",
43
+ "subprocess.run('pkill -f ollama 2>/dev/null', shell=True)\n",
44
+ "time.sleep(2)\n",
45
+ "\n",
46
+ "# start Ollama with GPU support\n",
47
+ "subprocess.Popen('OLLAMA_FLASH_ATTENTION=1 OLLAMA_KEEP_ALIVE=24h nohup ollama serve > /tmp/ollama.log 2>&1 &', shell=True)\n",
48
+ "time.sleep(8)\n",
49
+ "\n",
50
+ "# verify\n",
51
+ "import urllib.request\n",
52
+ "print(urllib.request.urlopen('http://localhost:11434/api/version').read().decode())"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "metadata": {},
58
+ "execution_count": null,
59
+ "outputs": [],
60
+ "source": [
61
+ "# Cell 3 — pull Cipher GGUF (public — no auth needed)\n",
62
+ "import subprocess\n",
63
+ "print('Pulling Cipher GGUF (~18GB, 5-10 min on Colab fast network)...')\n",
64
+ "result = subprocess.run('ollama pull hf.co/Auroraventures/cipher-sft-merged-Q4_K_M-GGUF', shell=True, capture_output=True, text=True)\n",
65
+ "print(result.stdout)\n",
66
+ "print(result.stderr)\n",
67
+ "\n",
68
+ "# Tag as kin-cipher\n",
69
+ "subprocess.run('ollama cp hf.co/Auroraventures/cipher-sft-merged-Q4_K_M-GGUF kin-cipher', shell=True)\n",
70
+ "print('---')\n",
71
+ "subprocess.run('ollama list', shell=True)"
72
+ ]
73
+ },
74
+ {
75
+ "cell_type": "code",
76
+ "metadata": {},
77
+ "execution_count": null,
78
+ "outputs": [],
79
+ "source": [
80
+ "# Cell 4 — quick test (no tunnel yet, just verify model works on this GPU)\n",
81
+ "import urllib.request, json, time\n",
82
+ "\n",
83
+ "prompt = '<start_of_turn>user\\nIn 30 words, describe yourself.<end_of_turn>\\n<start_of_turn>model\\n'\n",
84
+ "body = json.dumps({\n",
85
+ " 'model': 'kin-cipher',\n",
86
+ " 'prompt': prompt,\n",
87
+ " 'raw': True,\n",
88
+ " 'stream': False,\n",
89
+ " 'options': {'temperature': 0.7, 'num_predict': 100, 'stop': ['<end_of_turn>']},\n",
90
+ "}).encode()\n",
91
+ "\n",
92
+ "t0 = time.time()\n",
93
+ "req = urllib.request.Request('http://localhost:11434/api/generate', data=body, headers={'Content-Type': 'application/json'})\n",
94
+ "data = json.loads(urllib.request.urlopen(req, timeout=300).read())\n",
95
+ "elapsed = time.time() - t0\n",
96
+ "print(f'Time: {elapsed:.1f}s | tokens: {data.get(\"eval_count\")} | speed: {data.get(\"eval_count\",0)/(data.get(\"eval_duration\",1)/1e9):.1f} t/s')\n",
97
+ "print('---')\n",
98
+ "print(data['response'])"
99
+ ]
100
+ },
101
+ {
102
+ "cell_type": "code",
103
+ "metadata": {},
104
+ "execution_count": null,
105
+ "outputs": [],
106
+ "source": [
107
+ "# Cell 5 — start cloudflared tunnel and print public URL\n",
108
+ "import subprocess, time, re, os\n",
109
+ "\n",
110
+ "subprocess.run('pkill -f cloudflared 2>/dev/null', shell=True)\n",
111
+ "time.sleep(2)\n",
112
+ "\n",
113
+ "subprocess.Popen('nohup cloudflared tunnel --url http://localhost:11434 > /tmp/tunnel.log 2>&1 &', shell=True)\n",
114
+ "\n",
115
+ "# Wait for tunnel URL to appear in log\n",
116
+ "url = None\n",
117
+ "for _ in range(30):\n",
118
+ " time.sleep(2)\n",
119
+ " try:\n",
120
+ " log = open('/tmp/tunnel.log').read()\n",
121
+ " m = re.search(r'https://[a-z0-9-]+\\.trycloudflare\\.com', log)\n",
122
+ " if m:\n",
123
+ " url = m.group(0)\n",
124
+ " break\n",
125
+ " except: pass\n",
126
+ "\n",
127
+ "if url:\n",
128
+ " print(f'\\n========================================')\n",
129
+ " print(f'CIPHER PUBLIC URL: {url}')\n",
130
+ " print(f'========================================')\n",
131
+ " print(f'\\nTest it:')\n",
132
+ " print(f'curl {url}/api/version')\n",
133
+ " print(f'\\nFrom your laptop, set CIPHER_API_URL to use it.')\n",
134
+ "else:\n",
135
+ " print('Tunnel URL not found - check /tmp/tunnel.log')\n",
136
+ " print(open('/tmp/tunnel.log').read())"
137
+ ]
138
+ }
139
+ ],
140
+ "metadata": {
141
+ "kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"},
142
+ "language_info": {"name": "python", "version": "3.10"},
143
+ "accelerator": "GPU",
144
+ "colab": {"gpuType": "A100"}
145
+ },
146
+ "nbformat": 4,
147
+ "nbformat_minor": 4
148
+ }