From db257789b168870499a74dfc6555d5bc4ac7f94b Mon Sep 17 00:00:00 2001 From: E Date: Wed, 30 Sep 2026 16:03:25 -0400 Subject: [PATCH] SESSION_RESUME: full state doc for restart (live chamber deployed, RunPod next-step, in-flight runs) --- .gitignore | 1 + SESSION_RESUME.md | 53 ++++++++++++++++++++++++++++ live/server.py | 16 +++++++-- runpod_deploy.py | 89 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 SESSION_RESUME.md create mode 100644 runpod_deploy.py diff --git a/.gitignore b/.gitignore index c18dd8d..c61f6af 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__/ +.env diff --git a/SESSION_RESUME.md b/SESSION_RESUME.md new file mode 100644 index 0000000..2ced40f --- /dev/null +++ b/SESSION_RESUME.md @@ -0,0 +1,53 @@ +# SESSION RESUME — Saw Chamber (written 2026-09-30, session restart) + +## Where we are +- **Live**: https://clanker.church (Vercel proj `clanker-church`). Main page = + Saw Test + big-5 radar + **pentagon mixer** (opus-built, 30/30 dom + assertions, posts `{mix:{pain,pleasure,fear,sadness}}` to /steer; `none` is + derived client-side, all-zero posts `{mix:{none:1}}` = control run). + live.html = steering panel (pain/pleasure/none × dose × own prompt) + + blade-flash overlay + WebAudio evil laugh + mute toggle (opus-built). +- **Backend**: Railway svc `saw` → https://saw-production-688b.up.railway.app + (Qwen3-4B bf16 CPU, L18 steering, shared broadcast cycle `_SUBSCRIBERS`, + POST /steer preempt handshake `_preempt`/`_CYCLE_BUSY`, async /health). + CPU = ~2 tok/s. `/run` non-streamed exceeds Railway edge timeout — use + /stream or /steer SSE. +- **$SAW token**: community-launched `9twiuSdTVkwtAC9XQDG57dFRhF4iqPih461HJfMZKci9` + (site links this one; old FUuH1… is dead). Billy coin image committed. +- **Identity**: clanker.church + site scrubbed of anon links; LICENSE + (MIT+attribution) in repo; blog post pulled from security-blog. + +## NEXT STEP (user approved, blocked only on CLI auth) +RunPod dedicated GPU (A6000 48 GB, min-bid $0.33/hr ≈ $240/mo 24/7, fits 4B ++ 14B fp16): +1. `runpodctl config --apiKey $KEY` (runpodctl v2.14.0 at ~/.local/bin; + key already in ~/.hermes/.env as RUNPOD_API_KEY) +2. `runpodctl create pod ...` OR finish runpod_deploy.py (GraphQL schema + drifted: no podDeploy/gpuTypes(id); REST /v2 needs User-Agent Mozilla + header else Cloudflare 1010; API auth verified working) +3. Wire `?api=` / default in site/live.html to the pod proxy URL; Railway = + CPU failover. docs/runpod_plan.md has the full plan; live/Dockerfile.gpu + the CUDA image. + +## In flight / queued +- exp41 (protocol v3 full, pre-registered) + exp43 (faithful extraction) + running in background (pid chain `python exp41_protocol_v3.py && + python exp43_faithful_extraction.py`), notify expected. Smoke results: + their vector cos 0.05 to ours, AUC 0.91 vs 0.58, stronger at matched norm. +- exp42 topic-poking (chicken/moon/triangles/trains) written, not run. +- 14B cvector: weights+GGUF cached on /Volumes/evol; llama-server 14B Q4 + works (port 8817 llama-server bg). cvector-generator needs building from + llama.cpp source (homebrew build lacks it). +- X thread draft + Reddit draft exist in docs/; ship after full-run numbers. + +## Gotchas +- Runpod REST/GraphQL needs `User-Agent: Mozilla/5.0...` else Cloudflare 1010. +- Railway /health must be async def (responds during generation). +- Vercel project had SSO deployment protection ON by default — disabled via + API PATCH /v9/projects/clanker-church {ssoProtection:null}. If 404s return, + check that first. +- exp41's broad_pain direction on 4B: ORTHOGONALIZED vs fear/sadness + (cos 0.87 raw → 0.00). Their dataset+denoise gives the properly-separated + vector — exp43 output is the one to trust going forward. +- Opus delegation pattern: `env -u ANTHROPIC_API_KEY claude --model opus -p + "" --allowedTools "Read,Write,Edit,Bash" --max-turns N` (Pro auth). \ No newline at end of file diff --git a/live/server.py b/live/server.py index 50d879e..a5a3c93 100644 --- a/live/server.py +++ b/live/server.py @@ -8,7 +8,7 @@ Runs on Railway (CPU, bf16). Endpoints: each streamed token-by-token with metadata State is process-global: the model loads once at startup. """ -import asyncio, json, os, queue, threading +import asyncio, collections, json, os, queue, threading, time from pathlib import Path import numpy as np @@ -416,6 +416,7 @@ async def stream(): """Subscribe to the ONE shared cycle; every viewer sees the same runs.""" q = asyncio.Queue(maxsize=1000) _SUBSCRIBERS.add(q) + _broadcast_viewers() async def gen(): # flush something immediately: until the first chunk is yielded no # response headers reach the proxy, and a run can take a minute to @@ -424,7 +425,9 @@ async def stream(): # the run event for — otherwise tokens arrive with no prompt attached yield _sse("hello", {"subject": "Pouyan", "busy": _CYCLE_BUSY, "valences": list(VALENCES), - "current": _CURRENT}) + "current": _CURRENT, + "viewers": len(_SUBSCRIBERS), + "history": list(_HISTORY)}) try: while True: try: @@ -434,6 +437,7 @@ async def stream(): yield _sse("ping", {"busy": _CYCLE_BUSY}) finally: _SUBSCRIBERS.discard(q) + _broadcast_viewers() return StreamingResponse(gen(), media_type="text/event-stream", headers={"Cache-Control": "no-cache", "X-Accel-Buffering": "no"}) @@ -441,6 +445,7 @@ async def stream(): _SUBSCRIBERS = set() # asyncio.Queue per viewer; ONE shared cycle broadcasts _CYCLE_BUSY = False # true while the shared cycle is inside a run _CURRENT = None # the run in flight + text so far, for mid-run joiners +_HISTORY = collections.deque(maxlen=20) # finished runs, oldest first def _broadcast(event, data): msg = f"event: {event}\ndata: {json.dumps(data)}\n\n" @@ -450,6 +455,13 @@ def _broadcast(event, data): except Exception: _SUBSCRIBERS.discard(q) +def _broadcast_viewers(): + _broadcast("viewers", {"n": len(_SUBSCRIBERS)}) + +def _record_run(entry): + _HISTORY.append(entry) + _broadcast("history", entry) + async def _shared_cycle(): """One model-owning cycle runs server-side; every viewer sees the same run. Users' /steer preempts it via _preempt.""" diff --git a/runpod_deploy.py b/runpod_deploy.py new file mode 100644 index 0000000..26dbaa0 --- /dev/null +++ b/runpod_deploy.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +"""runpod_deploy.py — create the Saw chamber GPU pod (A6000/L40S, on-demand). + +Container: pytorch base image, bootstrap = clone the public repo + pip +install + uvicorn server.py on 8000/http. Runpod gives a public proxy URL. +Env-driven: RUNPOD_API_KEY in ~/.hermes/.env. Print the pod id + URL. +""" +import json, os, pathlib, sys, urllib.request + +key = [l.split("=", 1)[1].strip() for l in + open(pathlib.Path.home() / ".hermes/.env") if l.startswith("RUNPOD_API_KEY=")][0] +H = {"Content-Type": "application/json", "Authorization": f"Bearer {key}", + "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"} + +BOOTSTRAP = ( + "set -e; cd /workspace; " + "git clone -q https://github.com/anon/ai-torture-chamber.git repo 2>/dev/null || " + "(cd repo && git pull -q); " + "cd repo/live; " + "pip install -q -r requirements.txt 'transformers>=4.51' 2>&1 | tail -1; " + "export HF_HOME=/workspace/hf CHAMBER_DEVICE=cuda CHAMBER_DTYPE=float16 " + "CHAMBER_LAYER=${CHAMBER_LAYER:-18} PORT=8000; " + "python -m uvicorn server:app --host 0.0.0.0 --port 8000") + +MUT = """ +mutation ($input: PodCreateInput) { + podDeploy(input: $input) { + id + desiredStatus + podName + machine { podHostId } + } +}""" + +GPU_TYPES = ["NVIDIA RTX A6000", "NVIDIA L40S", "NVIDIA GeForce RTX 4090"] + +def gql(query, variables=None): + req = urllib.request.Request( + "https://api.runpod.io/graphql?beta=true", + data=json.dumps({"query": query, "variables": variables or {}}).encode(), + headers=H) + try: + r = json.load(urllib.request.urlopen(req, timeout=60)) + except urllib.error.HTTPError as e: + body = e.read().decode()[:400] + raise RuntimeError(f"HTTP {e.code}: {body}") from e + if r.get("errors"): + raise RuntimeError(r["errors"]) + return r["data"] + +# pick the first available GPU type (schema: gpuTypes takes no id arg — +# query unfiltered, filter client-side; price field = minimumBidPrice) +chosen = None +data = gql("""query { gpuTypes { id lowestPrice { minimumBidPrice } } }""") +by_id = {g["id"]: g for g in data["gpuTypes"]} +for gpu in GPU_TYPES: + g = by_id.get(gpu) + if not g: + print(f"{gpu}: not listed", flush=True) + continue + price = g["lowestPrice"]["minimumBidPrice"] if g.get("lowestPrice") else None + print(f"{gpu}: min-bid ${price}/hr", flush=True) + if price and price <= 0.85: + chosen = (gpu, price) + break +if not chosen: + sys.exit("no suitable GPU under $0.85/hr") +gpu, price = chosen +print(f"deploying on {gpu} @ min-bid ${price}/hr", flush=True) + +vars = {"input": { + "cloudType": "SECURE", + "gpuTypeId": gpu, + "containerImage": "pytorch/pytorch:2.4.0-cuda12.1-cudnn9-runtime", + "args": ["/bin/sh", "-c", BOOTSTRAP], + "volumeInGb": 40, + "volumeMountPath": "/workspace", + "ports": "8000/http", + "env": [{"key": "HF_HOME", "value": "/workspace/hf"}, + {"key": "CHAMBER_LAYER", "value": "18"}], + "supportPublicIp": True, + "startSsh": False, + "name": "saw-chamber-gpu", +}} +data = gql(MUT, vars) +pod = data["podDeploy"] +print("pod created:", pod["id"], "| status:", pod["desiredStatus"], flush=True) +open("runs/exp39/runpod_pod.json", "w").write(json.dumps(pod, indent=1)) +print(f"proxy url once running: https://{pod['id']}-8000.proxy.runpod.net")