broadfield commited on
Commit
cbda011
·
verified ·
1 Parent(s): b5a6209

Update via HuggingBot

Browse files
Files changed (1) hide show
  1. README.md +199 -3
README.md CHANGED
@@ -1,3 +1,199 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # OpenJev — zero-GPU CPU deploy kit
2
+
3
+ Runs the [OpenJev](https://huggingface.co/openjev/openjev) decision API
4
+ ([openjev-server](https://huggingface.co/spaces/openjev/openjev-server))
5
+ **with no GPU at all**. It serves the exact same
6
+ `POST /v1/systemone` contract as the hosted server — a choice / yes-no / score
7
+ per question, with a probability for every option, read off the model's first
8
+ output position — by pointing the **official, unmodified** `openjev-server` at
9
+ [`llama.cpp`](https://github.com/ggml-org/llama.cpp) (CPU, GGUF) instead of vLLM.
10
+
11
+ | | hosted (reference) | this kit (zero GPU) |
12
+ |---|---|---|
13
+ | engine | vLLM + FP8 on 1× H100 | llama.cpp on CPU |
14
+ | weights | `openjev/openjev-FP8` (80 GB) | `openjev/openjev-GGUF` Q4_K_M (16.2 GB) |
15
+ | latency | ~125 ms | seconds (see [Benchmarks](#benchmarks)) |
16
+ | surface | `/v1/systemone` + ops | identical (official server, unchanged) |
17
+
18
+ ## Why this works (no code hacks)
19
+
20
+ `openjev-server`'s `vllm` backend is really *"any OpenAI-compatible server that
21
+ returns logprobs"*:
22
+
23
+ - it sends standard `/chat/completions` JSON (`logprobs`, `top_logprobs`,
24
+ `allowed_token_ids`, `max_tokens: 1`, `temperature: 0`);
25
+ - **exact readout** uses vLLM's `logprob_token_ids = [ids]` extension →
26
+ llama.cpp doesn't have it, so the backend's documented fallback kicks in:
27
+ top-K logprobs are matched **by label text** instead (see
28
+ `openjev_server/backends/vllm.py` → `_scores`, "old protocol").
29
+
30
+ That single fallback is the whole trick: the official code path runs unmodified,
31
+ and `--force` only relaxes the startup probe's letter-mass check if llama.cpp's
32
+ text-matched logprobs ever look borderline for your quant.
33
+
34
+ ## What you get
35
+
36
+ - `POST /v1/systemone` — one request, any mix of `choice` / `noul` / `score`
37
+ - `POST /v1/prewarm`, `POST /v1/chat/completions` (passthrough)
38
+ - `GET /v1/version` · `GET /healthz` · `GET /readyz` ·
39
+ `GET /metrics` (Prometheus) · `GET /docs` (OpenAPI)
40
+ - optional bearer auth via `OPENJEV_TOKEN`
41
+ - Persistent model storage (HF Spaces) — the 16.2 GB download survives restarts
42
+
43
+ ## Deploy on Hugging Face (zero GPU, free)
44
+
45
+ 1. **Duplicate the runtime Space** (needs a free HF account):
46
+ <https://huggingface.co/spaces/broadfield/openjev-cpu-run?duplicate=true>
47
+ - SDK: **Docker** · hardware: **CPU basic (free)** · persistent storage:
48
+ **30 GB** ($0.50/mo, required for `/data`)
49
+ 2. Wait for the build. The Docker image compiles llama.cpp CPU + installs
50
+ openjev-server and, on first boot, downloads the Q4 GGUF (~16.2 GB) into
51
+ `/data`. **Allow ~20–50 min on the first cold boot;** subsequent restarts
52
+ load straight from persistent storage.
53
+ 3. Try the API. By default the Space is public:
54
+
55
+ ```bash
56
+ BASE=https://<your-username>-openjev-cpu-run.hf.space
57
+
58
+ curl -s "$BASE/v1/systemone" -H 'Content-Type: application/json' -d '{
59
+ "state": "Customer message: I was charged twice for my order last week and nobody has replied.",
60
+ "questions": {
61
+ "route": {"type": "choice", "instructions": "Which team should handle this?",
62
+ "criteria": {"billing": null, "shipping": null, "technical": null}},
63
+ "angry": {"type": "noul", "instructions": "Is the customer angry?"},
64
+ "urgency": {"type": "score", "instructions": "How urgent is this?",
65
+ "criteria": ["can wait", "this week", "today", "right now"]}
66
+ }
67
+ }'
68
+ ```
69
+
70
+ ```json
71
+ {
72
+ "answers": {
73
+ "route": {"type": "choice", "choice": "billing",
74
+ "probabilities": {"billing": 0.9996, "shipping": 0.0002, "technical": 0.0002},
75
+ "confidence": 0.9995},
76
+ "angry": {"type": "noul", "noul": 0.56},
77
+ "urgency": {"type": "score", "score": 2.04,
78
+ "legend": {"0": "can wait", "1": "this week", "2": "today", "3": "right now"},
79
+ "probabilities": {"0": 0.02, "1": 0.13, "2": 0.64, "3": 0.21},
80
+ "confidence": 0.71}
81
+ },
82
+ "usage": {"input_tokens": 239, "output_tokens": 0}
83
+ }
84
+ ```
85
+
86
+ > **Latency honesty right up front** — a 27B model on a shared free CPU is *not*
87
+ > 125 ms. Expect **~2–6 s per question** (single reader) on a 16-core Space with
88
+ > the Q4 quant. That's a real API — just not a high-QPS one. The reason this is
89
+ > still interesting: **a decision API only ever generates 1 token**, so the CPU
90
+ > is the *only* slow part, and it stays predictable. Raise `LLAMA_PARALLEL`,
91
+ > lower `LLAMA_CTX`, or use a different quant if your workload wants less of it.
92
+
93
+ ## Deploy locally (or on any VPS)
94
+
95
+ ```bash
96
+ git clone https://huggingface.co/datasets/broadfield/openjev-cpu-deploy-kit
97
+ cd openjev-cpu-deploy-kit
98
+ docker compose up --build -d
99
+ curl -s http://localhost:7860/v1/systemone ... # same payload as above
100
+ ```
101
+
102
+ Or Docker directly:
103
+
104
+ ```bash
105
+ docker build -t openjev-cpu .
106
+ docker run -d -p 7860:7860 -v openjev-data:/data -e MODEL_FILE=OpenJev-Q4_K_M.gguf openjev-cpu
107
+ ```
108
+
109
+ ## Env vars
110
+
111
+ | var | default | what it does |
112
+ |---|---|---|
113
+ | `MODEL_REPO` | `openjev/openjev-GGUF` | GGUF repo |
114
+ | `MODEL_FILE` | `OpenJev-Q4_K_M.gguf` | Q4_K_M · Q5_K_M (18.8 GB) · Q6_K (21.6 GB) · Q8_0 (27.9 GB) |
115
+ | `TOKENIZER_REPO` | `openjev/openjev` | tokenizer + chat template for openjev-server |
116
+ | `LLAMA_CTX` | `8192` | context window |
117
+ | `LLAMA_MAX_LOGPROBS` | `64` | top-K logprobs (must be ≥ number of options) |
118
+ | `LLAMA_PARALLEL` | `1` | concurrent sequences (scales memory) |
119
+ | `LLAMA_THREADS` / `LLAMA_THREADS_BATCH` | auto | pin core count, e.g. `8` / `8` |
120
+ | `OPENJEV_PORT` | `7860` | ingress (HF sets `$PORT`) |
121
+ | `OPENJEV_TOKEN` | empty | bearer token required on `/v1/*` |
122
+ | `OPENJEV_PROFILE` | `openjev` | `openjev` (published constants) or `uncalibrated` |
123
+ | `OPENJEV_SERVED_MODEL_NAME` | `openjev` | model id reported by `/v1/version` |
124
+
125
+ ## Benchmarks
126
+
127
+ Expected on a **free 16 vCPU CPU Space**, `OpenJev-Q4_K_M.gguf`
128
+ (27B, Qwen3-based → ~8-bit KV cache in the llama.cpp fork, 16.2 GB RAM):
129
+
130
+ | quant | file size | SPE (tokens/s, 8 threads) | RAM | 1-question latency* |
131
+ |---|---|---|---|---|
132
+ | Q4_K_M | 16.2 GB | 2–4 | ~17 GB | ~2–6 s |
133
+ | Q5_K_M | 18.8 GB | 1.5–3 | ~20 GB | ~3–8 s |
134
+ | Q6_K | 21.6 GB | 1.5–3 | ~23 GB | ~3–8 s |
135
+
136
+ \* single question ≈ one forward pass: `(prompt_tokens + 1) / SPE`. A 240-token
137
+ state ⇒ ~4 s @ 3 SPE. Latency is directly linear in prompt length.
138
+
139
+ **The decision-API twist:** because `max_tokens: 1`, a *pipeline* of many
140
+ questions on one state shares ~all of the prefill. For batch agents, batch the
141
+ questions into one `/v1/systemone` call — every extra answer after the first is
142
+ nearly free:
143
+
144
+ | questions in one call | est. per-call latency @ 3 SPE |
145
+ |---|---|
146
+ | 1 | ~4 s |
147
+ | 4 | ~4.5 s |
148
+ | 10 | ~5.5 s (10 answers, still one pass) |
149
+
150
+ ## Calling it from code
151
+
152
+ ```python
153
+ import httpx
154
+
155
+ r = httpx.post("http://localhost:7860/v1/systemone", json={
156
+ "state": "Customer message: I was charged twice for my order last week and nobody has replied.",
157
+ "questions": {
158
+ "route": {"type": "choice", "instructions": "Which team should handle this?",
159
+ "criteria": {"billing": None, "shipping": None, "technical": None}},
160
+ "angry": {"type": "noul", "instructions": "Is the customer angry?"},
161
+ },
162
+ }, timeout=60)
163
+ answers = r.json()["answers"]
164
+ print(answers["route"]["choice"], answers["route"]["probabilities"], answers["angry"]["noul"])
165
+ ```
166
+
167
+ ```typescript
168
+ const r = await fetch(`${BASE}/v1/systemone`, {
169
+ method: "POST",
170
+ headers: { "Content-Type": "application/json" },
171
+ body: JSON.stringify({
172
+ state: "Customer message: I was charged twice for my order last week and nobody has replied.",
173
+ questions: {
174
+ route: { type: "choice", instructions: "Which team should handle this?",
175
+ criteria: { billing: null, shipping: null, technical: null } },
176
+ angry: { type: "noul", instructions: "Is the customer angry?" },
177
+ },
178
+ }),
179
+ });
180
+ const { answers } = await r.json();
181
+ ```
182
+
183
+ ## Layout
184
+
185
+ ```
186
+ Dockerfile # multi-stage: llama.cpp CPU + official openjev-server
187
+ entrypoint.sh # GGUF → /data, llama-server, then openjev serve
188
+ docker-compose.yml # local/VPS one-liner
189
+ bench.mjs # throughput + latency smoke bench against a running endpoint
190
+ runtime-baseline.md # the exact Docker Space spec we recommend
191
+ README.md # you are here
192
+ ```
193
+
194
+ ## License & credit
195
+
196
+ - Model weights: **CC BY-NC 4.0** — OpenJev is an independent project, not
197
+ affiliated with TypeSafe (Jev is their product).
198
+ - `openjev-server`: Apache 2.0.
199
+ - This kit: Apache 2.0. llama.cpp: MIT.