{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Cipher — Hosted on Colab Pro+ A100\n", "\n", "Spins up Cipher (kin-cipher) on this Colab GPU and exposes it via cloudflared tunnel.\n", "Use the printed URL from your laptop for fast generation.\n", "\n", "**Runtime needed:** A100 (Colab Pro+). At T4 it'll work but slower (~5-10 t/s)." ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "# Cell 1 — install Ollama + cloudflared + curl\n", "import os, subprocess, time\n", "\n", "print('Installing Ollama...')\n", "subprocess.run('curl -fsSL https://ollama.com/install.sh | sh', shell=True, check=True)\n", "\n", "print('Downloading cloudflared...')\n", "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", "\n", "print('Done.')" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "# Cell 2 — start Ollama serve in background\n", "import subprocess, time, os\n", "\n", "# kill any existing\n", "subprocess.run('pkill -f ollama 2>/dev/null', shell=True)\n", "time.sleep(2)\n", "\n", "# start Ollama with GPU support\n", "subprocess.Popen('OLLAMA_FLASH_ATTENTION=1 OLLAMA_KEEP_ALIVE=24h nohup ollama serve > /tmp/ollama.log 2>&1 &', shell=True)\n", "time.sleep(8)\n", "\n", "# verify\n", "import urllib.request\n", "print(urllib.request.urlopen('http://localhost:11434/api/version').read().decode())" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "# Cell 3 — pull Cipher GGUF (public — no auth needed)\n", "import subprocess\n", "print('Pulling Cipher GGUF (~18GB, 5-10 min on Colab fast network)...')\n", "result = subprocess.run('ollama pull hf.co/Auroraventures/cipher-sft-merged-Q4_K_M-GGUF', shell=True, capture_output=True, text=True)\n", "print(result.stdout)\n", "print(result.stderr)\n", "\n", "# Tag as kin-cipher\n", "subprocess.run('ollama cp hf.co/Auroraventures/cipher-sft-merged-Q4_K_M-GGUF kin-cipher', shell=True)\n", "print('---')\n", "subprocess.run('ollama list', shell=True)" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "# Cell 4 — quick test (no tunnel yet, just verify model works on this GPU)\n", "import urllib.request, json, time\n", "\n", "prompt = 'user\\nIn 30 words, describe yourself.\\nmodel\\n'\n", "body = json.dumps({\n", " 'model': 'kin-cipher',\n", " 'prompt': prompt,\n", " 'raw': True,\n", " 'stream': False,\n", " 'options': {'temperature': 0.7, 'num_predict': 100, 'stop': ['']},\n", "}).encode()\n", "\n", "t0 = time.time()\n", "req = urllib.request.Request('http://localhost:11434/api/generate', data=body, headers={'Content-Type': 'application/json'})\n", "data = json.loads(urllib.request.urlopen(req, timeout=300).read())\n", "elapsed = time.time() - t0\n", "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", "print('---')\n", "print(data['response'])" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "# Cell 5 — start cloudflared tunnel and print public URL\n", "import subprocess, time, re, os\n", "\n", "subprocess.run('pkill -f cloudflared 2>/dev/null', shell=True)\n", "time.sleep(2)\n", "\n", "subprocess.Popen('nohup cloudflared tunnel --url http://localhost:11434 > /tmp/tunnel.log 2>&1 &', shell=True)\n", "\n", "# Wait for tunnel URL to appear in log\n", "url = None\n", "for _ in range(30):\n", " time.sleep(2)\n", " try:\n", " log = open('/tmp/tunnel.log').read()\n", " m = re.search(r'https://[a-z0-9-]+\\.trycloudflare\\.com', log)\n", " if m:\n", " url = m.group(0)\n", " break\n", " except: pass\n", "\n", "if url:\n", " print(f'\\n========================================')\n", " print(f'CIPHER PUBLIC URL: {url}')\n", " print(f'========================================')\n", " print(f'\\nTest it:')\n", " print(f'curl {url}/api/version')\n", " print(f'\\nFrom your laptop, set CIPHER_API_URL to use it.')\n", "else:\n", " print('Tunnel URL not found - check /tmp/tunnel.log')\n", " print(open('/tmp/tunnel.log').read())" ] } ], "metadata": { "kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"name": "python", "version": "3.10"}, "accelerator": "GPU", "colab": {"gpuType": "A100"} }, "nbformat": 4, "nbformat_minor": 4 }