#46 spike report part 1: /v1/systemone and decision model families
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99d14fa parent: 601aaa2 modified
.memory/handoffs/2026-11-26-v0-3-systemone-spike.md +10 -0 | @@ -18,3 +18,13 @@ | ||
| 18 | 18 | ## Traps |
| 19 | 19 | - mlx-swift-lm's reranker/classifier scoring is `package` scope: cannot be called from razorbill. |
| 20 | 20 | - `logprobs` is currently refused with 400 on /v1/completions (CompletionsRoute.swift). |
| 21 | + | |
| 22 | +## Update (same session, later) | |
| 23 | +- Definition agreed: razorbill implements llama-server's `POST /v1/systemone` (PR #29818). Full | |
| 24 | + API, scoring formulas and the 3 model families are in comment 1 of #46 (tasks 1–2 closed). | |
| 25 | +- The PR's patches were saved in the session scratchpad (lost later); re-fetch with | |
| 26 | + `gh api repos/ggml-org/llama.cpp/pulls/29818/files` if needed (`patch` field per file). | |
| 27 | +- Open questions (the user wanted to clarify before answering): which family first (label readout | |
| 28 | + recommended), Mac RAM (OpenJev is 27B). | |
| 29 | +- Next: task 3 of #46 — propose v0.3 tickets: API layer on FakeEngine (Linux-testable), then one | |
| 30 | + family per ticket, images later; compare with llama.cpp's reference values in the PR. | |
| @@ -18,3 +18,13 @@ | |||
| 18 | ## Traps | 18 | ## Traps |
| 19 | - mlx-swift-lm's reranker/classifier scoring is `package` scope: cannot be called from razorbill. | 19 | - mlx-swift-lm's reranker/classifier scoring is `package` scope: cannot be called from razorbill. |
| 20 | - `logprobs` is currently refused with 400 on /v1/completions (CompletionsRoute.swift). | 20 | - `logprobs` is currently refused with 400 on /v1/completions (CompletionsRoute.swift). |
| 21 | + | ||
| 22 | +## Update (same session, later) | ||
| 23 | +- Definition agreed: razorbill implements llama-server's `POST /v1/systemone` (PR #29818). Full | ||
| 24 | + API, scoring formulas and the 3 model families are in comment 1 of #46 (tasks 1–2 closed). | ||
| 25 | +- The PR's patches were saved in the session scratchpad (lost later); re-fetch with | ||
| 26 | + `gh api repos/ggml-org/llama.cpp/pulls/29818/files` if needed (`patch` field per file). | ||
| 27 | +- Open questions (the user wanted to clarify before answering): which family first (label readout | ||
| 28 | + recommended), Mac RAM (OpenJev is 27B). | ||
| 29 | +- Next: task 3 of #46 — propose v0.3 tickets: API layer on FakeEngine (Linux-testable), then one | ||
| 30 | + family per ticket, images later; compare with llama.cpp's reference values in the PR. | ||
modified
.memory/history.md +8 -0 | @@ -451,3 +451,11 @@ sequence classification exists only as BERT/XLM-R rerankers in MLXEmbedders, its | ||
| 451 | 451 | `package` (not usable from razorbill); guard models (Llama Guard 3, Qwen3Guard-Gen) are generative |
| 452 | 452 | LLMs; no logprobs API, but a LogitProcessor sees the logits. Proposed mechanism: score each closed |
| 453 | 453 | option by log P(option | prompt) in one prefill. Nothing written in the tickets yet. |
| 454 | + | |
| 455 | +Then: user pasted llama.cpp's `/v1/systemone` (TypeSafe System One API) as the definition, plus a | |
| 456 | +list of MLX decision models. Read PR ggml-org/llama.cpp#29818 (README, server-decision.cpp/.h, | |
| 457 | +conversion code): no generation, one forward pass per question; 3 families (label readout: | |
| 458 | +OpenJev/lev on Qwen3.5; Kev: hidden states at markers + cls_out head; Laya/Julia-1: ModernBERT | |
| 459 | +encoders). Hub check: MLX conversions are fragmented (own runtimes); kev-4b ships head.pt (pickle). | |
| 460 | +Report written as comment 1 on #46, tasks 1–2 closed. Asked which family first and the Mac's RAM: | |
| 461 | +the user wants to clarify before answering. | |
| @@ -451,3 +451,11 @@ sequence classification exists only as BERT/XLM-R rerankers in MLXEmbedders, its | |||
| 451 | `package` (not usable from razorbill); guard models (Llama Guard 3, Qwen3Guard-Gen) are generative | 451 | `package` (not usable from razorbill); guard models (Llama Guard 3, Qwen3Guard-Gen) are generative |
| 452 | LLMs; no logprobs API, but a LogitProcessor sees the logits. Proposed mechanism: score each closed | 452 | LLMs; no logprobs API, but a LogitProcessor sees the logits. Proposed mechanism: score each closed |
| 453 | option by log P(option | prompt) in one prefill. Nothing written in the tickets yet. | 453 | option by log P(option | prompt) in one prefill. Nothing written in the tickets yet. |
| 454 | + | ||
| 455 | +Then: user pasted llama.cpp's `/v1/systemone` (TypeSafe System One API) as the definition, plus a | ||
| 456 | +list of MLX decision models. Read PR ggml-org/llama.cpp#29818 (README, server-decision.cpp/.h, | ||
| 457 | +conversion code): no generation, one forward pass per question; 3 families (label readout: | ||
| 458 | +OpenJev/lev on Qwen3.5; Kev: hidden states at markers + cls_out head; Laya/Julia-1: ModernBERT | ||
| 459 | +encoders). Hub check: MLX conversions are fragmented (own runtimes); kev-4b ships head.pt (pickle). | ||
| 460 | +Report written as comment 1 on #46, tasks 1–2 closed. Asked which family first and the Mac's RAM: | ||
| 461 | +the user wants to clarify before answering. | ||
modified
.tickets/issues/0046-spike-what-are-decision-models-for-razorbill-and.yaml +41 -4 | @@ -6,7 +6,7 @@ author: | ||
| 6 | 6 | name: k33g |
| 7 | 7 | email: ph.charriere@gmail.com |
| 8 | 8 | createdAt: 2026-11-24T21:17:08.000Z |
| 9 | -updatedAt: 2026-11-24T21:17:08.000Z | |
| 9 | +updatedAt: 2026-11-26T19:30:00.000Z | |
| 10 | 10 | labels: |
| 11 | 11 | - "spike" |
| 12 | 12 | - "needs-decision" |
| @@ -30,7 +30,7 @@ body: | | ||
| 30 | 30 | tasks: |
| 31 | 31 | - id: 1 |
| 32 | 32 | title: "Clarify the meaning with the user" |
| 33 | - state: open | |
| 33 | + state: closed | |
| 34 | 34 | priority: high |
| 35 | 35 | author: |
| 36 | 36 | name: k33g |
| @@ -38,7 +38,7 @@ tasks: | ||
| 38 | 38 | createdAt: 2026-11-24T21:17:08.000Z |
| 39 | 39 | - id: 2 |
| 40 | 40 | title: "Check MLXRerankers and classification support in mlx-swift-lm" |
| 41 | - state: open | |
| 41 | + state: closed | |
| 42 | 42 | priority: medium |
| 43 | 43 | author: |
| 44 | 44 | name: k33g |
| @@ -52,4 +52,41 @@ tasks: | ||
| 52 | 52 | name: k33g |
| 53 | 53 | email: ph.charriere@gmail.com |
| 54 | 54 | createdAt: 2026-11-24T21:17:08.000Z |
| 55 | -comments: [] | |
| 55 | +comments: | |
| 56 | + - id: 1 | |
| 57 | + author: | |
| 58 | + name: k33g | |
| 59 | + email: ph.charriere@gmail.com | |
| 60 | + createdAt: 2026-11-26T19:30:00.000Z | |
| 61 | + body: | | |
| 62 | + ## Report, part 1: what decision models are and how llama.cpp serves them (tasks 1 and 2) | |
| 63 | + | |
| 64 | + ### Definition (agreed with the user, 2026-11-26) | |
| 65 | + "Decision models" = the models served by llama-server's **`POST /v1/systemone`** (ggml-org/llama.cpp PR #29818, merged 2026-10-02; follows the TypeSafe System One API). razorbill implements the same endpoint. Rerankers are not in scope. | |
| 66 | + | |
| 67 | + ### API (from tools/server/README.md of the PR) | |
| 68 | + - Request: `state` (string, object or array; non-strings shown as JSON; chat messages allowed, their `image_url` parts become images), optional `images` (data URLs, max 8), `questions` = object id → `{type, instructions, criteria}`; optional `model`. | |
| 69 | + - `choice`: `criteria` = object option → description (or null). | |
| 70 | + - `score`: `criteria` = array of 2 to 10 levels, lowest first. | |
| 71 | + - `noul` (yes/no): `criteria` optional `{true, false}` descriptions. | |
| 72 | + - Response: `{model, answers: {id: ...}, usage: {input_tokens, output_tokens: 0}}`. | |
| 73 | + - choice: `type, choice, probabilities (sum 1), confidence = max(0, (p_max - 1/n) / (1 - 1/n))`. | |
| 74 | + - score: `type, score (expected level index), legend {"0": label...}, probabilities {"0": p...}, confidence = max(0, 1 - E|i - mode| / uniform distance)`. | |
| 75 | + - noul: `type, noul` (probability of true). | |
| 76 | + - Errors: 400 invalid request, 501 not a decision model / images unsupported. No streaming. Questions are answered independently. | |
| 77 | + | |
| 78 | + ### How the answers are computed (server-decision.cpp) | |
| 79 | + No generation. Each question (and variant) is one prompt, rendered by a family-specific "systemone" Jinja template injected at conversion time; one forward pass; scores → softmax with a temperature stored in the model (per type, sometimes per option-count bucket) → probabilities. Four families: | |
| 80 | + 1. **OpenJev** (Qwen3.5 27B, vision, CC BY-NC) and **lev** (Qwen3.5-4B + LoRA adapter merged at conversion): **label readout** = logits of the label tokens (A, B, C... / A..ZZ) at the last prompt position. lev: choice evaluated twice (options reversed) and averaged; noul read as a 9-level rating (expected value); keys sorted. | |
| 81 | + 2. **Kev** (Qwen3.5-4B-Base + LoRA + `head.pt` projection `cls_out`): hidden states read at each option's `<|box_end|>` marker and at the last token; score = dot(pointer half of the last token, option half of the marker) / sqrt(d/2). | |
| 82 | + 3. **Laya** (ModernBERT-large) and **Julia-1** (mmBERT-small): encoder; `[cls] question [sep] ([mask] option)* [sep] state [sep]`, options/question truncated to `max_head_tokens`; score = column `question type` of the head output at each mask marker. | |
| 83 | + - Causal families share the common prompt prefix between the questions of a request. | |
| 84 | + | |
| 85 | + ### What it means for razorbill (mlx-swift-lm 3.32.3) | |
| 86 | + - Qwen3.5 is supported by MLXLLM (`Qwen35.swift`): label readout (family 1) only needs the last-position logits of one prefill: feasible with the current stack. LoRA merge at load is needed for lev. | |
| 87 | + - Kev needs hidden states + the `cls_out` projection; `head.pt` is a PyTorch pickle (cannot be read from Swift) — needs a conversion to safetensors. | |
| 88 | + - ModernBERT is not in MLXEmbedders (Bert, NomicBert, Qwen3, Gemma3, LFM2 only): Laya/Julia need a port. | |
| 89 | + - Encoder sequence classification in MLXEmbedders exists only as rerankers, with `package` scoring API (unusable). | |
| 90 | + - The MLX conversions on the Hub are fragmented, each with its own runtime (`laya-mlx`, `jev-style`, `mlx-serve`, `Jakevin/kev-4b-ternary-mlx`...). Originals: `jaredpalmer/kev-4b` (peft + head.pt), `convaiinnovations/laya`, `SupersonicLabs/Julia-1`, `openjev/openjev` (has `helper/shim_mlx.py`). No GGUF-style `decision.type` metadata in MLX repos: the family must be detected from repo files or declared in the server config; templates and temperatures must be hard-coded per family (taken from llama.cpp's conversion code). | |
| 91 | + - Shared prefix: Qwen3.5 is hybrid, its cache cannot be trimmed: sharing needs a snapshot of the state at the end of the prefix. | |
| 92 | + | |
| @@ -6,7 +6,7 @@ author: | |||
| 6 | name: k33g | 6 | name: k33g |
| 7 | email: ph.charriere@gmail.com | 7 | email: ph.charriere@gmail.com |
| 8 | createdAt: 2026-11-24T21:17:08.000Z | 8 | createdAt: 2026-11-24T21:17:08.000Z |
| 9 | -updatedAt: 2026-11-24T21:17:08.000Z | 9 | +updatedAt: 2026-11-26T19:30:00.000Z |
| 10 | labels: | 10 | labels: |
| 11 | - "spike" | 11 | - "spike" |
| 12 | - "needs-decision" | 12 | - "needs-decision" |
| @@ -30,7 +30,7 @@ body: | | |||
| 30 | tasks: | 30 | tasks: |
| 31 | - id: 1 | 31 | - id: 1 |
| 32 | title: "Clarify the meaning with the user" | 32 | title: "Clarify the meaning with the user" |
| 33 | - state: open | 33 | + state: closed |
| 34 | priority: high | 34 | priority: high |
| 35 | author: | 35 | author: |
| 36 | name: k33g | 36 | name: k33g |
| @@ -38,7 +38,7 @@ tasks: | |||
| 38 | createdAt: 2026-11-24T21:17:08.000Z | 38 | createdAt: 2026-11-24T21:17:08.000Z |
| 39 | - id: 2 | 39 | - id: 2 |
| 40 | title: "Check MLXRerankers and classification support in mlx-swift-lm" | 40 | title: "Check MLXRerankers and classification support in mlx-swift-lm" |
| 41 | - state: open | 41 | + state: closed |
| 42 | priority: medium | 42 | priority: medium |
| 43 | author: | 43 | author: |
| 44 | name: k33g | 44 | name: k33g |
| @@ -52,4 +52,41 @@ tasks: | |||
| 52 | name: k33g | 52 | name: k33g |
| 53 | email: ph.charriere@gmail.com | 53 | email: ph.charriere@gmail.com |
| 54 | createdAt: 2026-11-24T21:17:08.000Z | 54 | createdAt: 2026-11-24T21:17:08.000Z |
| 55 | -comments: [] | 55 | +comments: |
| 56 | + - id: 1 | ||
| 57 | + author: | ||
| 58 | + name: k33g | ||
| 59 | + email: ph.charriere@gmail.com | ||
| 60 | + createdAt: 2026-11-26T19:30:00.000Z | ||
| 61 | + body: | | ||
| 62 | + ## Report, part 1: what decision models are and how llama.cpp serves them (tasks 1 and 2) | ||
| 63 | + | ||
| 64 | + ### Definition (agreed with the user, 2026-11-26) | ||
| 65 | + "Decision models" = the models served by llama-server's **`POST /v1/systemone`** (ggml-org/llama.cpp PR #29818, merged 2026-10-02; follows the TypeSafe System One API). razorbill implements the same endpoint. Rerankers are not in scope. | ||
| 66 | + | ||
| 67 | + ### API (from tools/server/README.md of the PR) | ||
| 68 | + - Request: `state` (string, object or array; non-strings shown as JSON; chat messages allowed, their `image_url` parts become images), optional `images` (data URLs, max 8), `questions` = object id → `{type, instructions, criteria}`; optional `model`. | ||
| 69 | + - `choice`: `criteria` = object option → description (or null). | ||
| 70 | + - `score`: `criteria` = array of 2 to 10 levels, lowest first. | ||
| 71 | + - `noul` (yes/no): `criteria` optional `{true, false}` descriptions. | ||
| 72 | + - Response: `{model, answers: {id: ...}, usage: {input_tokens, output_tokens: 0}}`. | ||
| 73 | + - choice: `type, choice, probabilities (sum 1), confidence = max(0, (p_max - 1/n) / (1 - 1/n))`. | ||
| 74 | + - score: `type, score (expected level index), legend {"0": label...}, probabilities {"0": p...}, confidence = max(0, 1 - E|i - mode| / uniform distance)`. | ||
| 75 | + - noul: `type, noul` (probability of true). | ||
| 76 | + - Errors: 400 invalid request, 501 not a decision model / images unsupported. No streaming. Questions are answered independently. | ||
| 77 | + | ||
| 78 | + ### How the answers are computed (server-decision.cpp) | ||
| 79 | + No generation. Each question (and variant) is one prompt, rendered by a family-specific "systemone" Jinja template injected at conversion time; one forward pass; scores → softmax with a temperature stored in the model (per type, sometimes per option-count bucket) → probabilities. Four families: | ||
| 80 | + 1. **OpenJev** (Qwen3.5 27B, vision, CC BY-NC) and **lev** (Qwen3.5-4B + LoRA adapter merged at conversion): **label readout** = logits of the label tokens (A, B, C... / A..ZZ) at the last prompt position. lev: choice evaluated twice (options reversed) and averaged; noul read as a 9-level rating (expected value); keys sorted. | ||
| 81 | + 2. **Kev** (Qwen3.5-4B-Base + LoRA + `head.pt` projection `cls_out`): hidden states read at each option's `<|box_end|>` marker and at the last token; score = dot(pointer half of the last token, option half of the marker) / sqrt(d/2). | ||
| 82 | + 3. **Laya** (ModernBERT-large) and **Julia-1** (mmBERT-small): encoder; `[cls] question [sep] ([mask] option)* [sep] state [sep]`, options/question truncated to `max_head_tokens`; score = column `question type` of the head output at each mask marker. | ||
| 83 | + - Causal families share the common prompt prefix between the questions of a request. | ||
| 84 | + | ||
| 85 | + ### What it means for razorbill (mlx-swift-lm 3.32.3) | ||
| 86 | + - Qwen3.5 is supported by MLXLLM (`Qwen35.swift`): label readout (family 1) only needs the last-position logits of one prefill: feasible with the current stack. LoRA merge at load is needed for lev. | ||
| 87 | + - Kev needs hidden states + the `cls_out` projection; `head.pt` is a PyTorch pickle (cannot be read from Swift) — needs a conversion to safetensors. | ||
| 88 | + - ModernBERT is not in MLXEmbedders (Bert, NomicBert, Qwen3, Gemma3, LFM2 only): Laya/Julia need a port. | ||
| 89 | + - Encoder sequence classification in MLXEmbedders exists only as rerankers, with `package` scoring API (unusable). | ||
| 90 | + - The MLX conversions on the Hub are fragmented, each with its own runtime (`laya-mlx`, `jev-style`, `mlx-serve`, `Jakevin/kev-4b-ternary-mlx`...). Originals: `jaredpalmer/kev-4b` (peft + head.pt), `convaiinnovations/laya`, `SupersonicLabs/Julia-1`, `openjev/openjev` (has `helper/shim_mlx.py`). No GGUF-style `decision.type` metadata in MLX repos: the family must be detected from repo files or declared in the server config; templates and temperatures must be hard-coded per family (taken from llama.cpp's conversion code). | ||
| 91 | + - Shared prefix: Qwen3.5 is hybrid, its cache cannot be trimmed: sharing needs a snapshot of the state at the end of the prefix. | ||
| 92 | + | ||