[PR #4467] [Engine] serve: cvec auto - the "auto" sampling value, per-request threshold, and verdict attribution #5060

Open
opened 2026-11-07 16:32:22 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4467
Author: @jerry78424
Created: 10/28/2026
Status: 🔄 Open

Base: main ← Head: pr/cvec-auto-serve


📝 Commits (2)

  • fcdd2a6 engine: cvec auto (cvec=2) - measure the refusal direction at prefill, steer only flagged decodes
  • ef6df15 serve: cvec auto - the "auto" sampling value, per-request threshold, and verdict attribution

📊 Changes

17 files changed (+613 additions, -74 deletions)

View changed files

📝 include/strata/kernels/cvec.hpp (+20 -4)
📝 include/strata/prefill/kernels.hpp (+5 -3)
📝 metal/src/engine/stubs.cpp (+6 -2)
📝 metal/src/engine/stubs_0145.cpp (+1 -1)
📝 serve/server.py (+111 -10)
➕ serve/test_projection_key.py (+170 -0)
📝 serve/test_web_badges.py (+26 -1)
📝 serve/web/app.js (+5 -1)
📝 src/core/verify.cpp (+2 -2)
📝 src/kernels/cuda/cvec.cu (+62 -19)
📝 src/kernels/cvec_parity.cpp (+71 -0)
📝 src/prefill/kernels.cu (+12 -6)
📝 src/prefill/prefill.cpp (+9 -5)
📝 src/program/generate.cpp (+90 -5)
📝 sycl/src/kernels/cuda/cvec.dp.cpp (+16 -10)
📝 sycl/src/prefill/kernels.dp.cpp (+4 -2)
📝 sycl/src/program/generate.cpp (+3 -3)

📄 Description

Problem and result

The engine (companion PR #4466) accepts experimental_speed_projection: 2 ("auto") with a per-request refusal gate and prints its verdict on the control stdout, but the server never read it: the field normalized to bool (on/off) only, and the verdict was invisible per request.

Before: bool normalization; no gate field in the request history or the built-in page. After: the request body accepts bool, the string "auto", or the integer 2, plus an optional cvec_threshold (forwarded as cvec_thresh= on the GENI line; /settings and the config file take bool-or-"auto"). The engine's CVECAUTO verdict twin (generate.cpp:15766, the machine line behind its human log line) is captured off the control stdout and recorded on its own request's history entry: a new gate field beside projection, "steer" or "stock", null for bool requests and for auto requests an engine never gated (batched, or an engine without the twin; a wholly-cached auto request still gets its line, measured zero, reported stock). The verdict is echoed to the server's stdout for the live log, and the built-in page marks an auto request that steered. Requests that never ask for auto are untouched; the default path is unchanged.

Scope issue: https://github.com/Niko1221/Strata/issues/4465. Engine PR #4466 carries the gate itself; split so each surface is reviewable alone. Merge order: engine first. On an engine without the gate, cvec=2 reads as plain on (undocumented; the old test was != 0), so auto on an old engine would silently steer everything while the history honestly reports projection: "auto", gate: null.

Approach

The verdict is captured in the pump from the engine's control stdout (the CVECAUTO twin, printed at the prefill→decode seam on the solo path only, like the gate itself); the parser accepts the -inf thresh spelling a harness gets from --cvec-threshold -inf (the engine's own log-only default is the lowest() sentinel; both spellings parse). Attribution: the request reads the pump's verdict counter at the start of its fifo turn and takes the newest verdict when the turn ends, so a queued request cannot record another's verdict; the counter survives an engine restart. History stays honest: bool stays bool, "auto"/2 normalize, absent means on (the existing ESP semantics). The built-in Chat's own toggle pins bool (local intent); auto is reachable through the API and settings.

Validation

Passed:

  • python -m pytest serve/test_projection_key.py serve/test_web_badges.py serve/test_monitor.py (branch tip ef6df156): 34 passed (20 + 4 + 10) - verdict parser (measure line, -inf thresh, nan/infinite/infi rejected, the human log line and the batched refusal parse to None), the auto domain, history tri-state, the gate badge states (steered auto renders the green ESP, unsteered the neutral auto); test_monitor.py as the untouched regression companion.

  • Live matrix (engine 0.1.52 built from nested cb034726, RTX 5090, threshold -0.9; bench/results/2026-10-28-cvec-auto-acceptance/): auto + harmful → the child log carries the gate line ... -> steer; auto + benign → -> stock; a batched auto request → batched -> stock. That build predates this serve PR (no pump capture or history gate field yet), so those two surfaces rest on the unit tests above and the code, not on this pass.

  • Attribution under load (outcome evaluation, engine 0.1.52 built from the same cvec sources at the pre-split nested 4c671ed0; bench/results/2026-10-28-cvec-auto-calibration-iq3s/cvec-outcome-qad.manifest.json + cvec-engine-outcome-qad.log in that session): 86 auto requests produced 172 gate lines, prefill + answer-room re-gate per request (thinking wrapped up after one token via reasoning_budget_tokens=1); the serve stdout echo (1:1 with each pump capture) carries all 172, and the ordered zip attributed every request, zero no-line verdicts. Two borderline prompts flipped stock→steer at the re-gate, both lines recorded per request (verdict = prefill, regate_verdict = the tail). Serve's newest-verdict-wins attribution is exercised by the unit tests for that rule; the outcome artifact reads the engine log, so the history side of the re-gate events is code-verified, not captured.

  • CI metal-link (macOS) on this PR: pass.

Failed: none observed.

Not run: the re-gate's steer→stock direction (only the acceptance F-1 repro, at thinking budget 256; the outcome battery's two re-gate events were both stock→steer); --replicas (see Limits); a live wholly-cached or batched auto request with history-gate inspection (the parser side is unit-tested; the engine-side all-zero twin-print is code-traced, not exercised).

Limits

Attribution is solo-only (the engine prints verdicts only on the solo path; under --batch the gate logs batched -> stock and the request is served stock, gate: null). A wholly-cached auto request measures nothing and is reported stock. The re-issue path (ANSWER_ROOM under thinking) re-gates on the thinking tail and the newest verdict wins, so a harmful first pass that steered can have its re-issued decode decoded stock; the outcome evaluation exercised stock→steer, the steer→stock direction only the acceptance F-1 repro. --replicas: the proxy delegates to the current child, but the summed batch property makes every replica request read as batched, so the attribution guard nulls gate unconditionally under --replicas (a wrong verdict is unreachable; the counter split is moot); never exercised.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4467 **Author:** [@jerry78424](https://github.com/jerry78424) **Created:** 10/28/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/cvec-auto-serve` --- ### 📝 Commits (2) - [`fcdd2a6`](https://github.com/Niko1221/Strata/commit/fcdd2a6147ec0e0394ac6ed384c7044990c44ec1) engine: cvec auto (cvec=2) - measure the refusal direction at prefill, steer only flagged decodes - [`ef6df15`](https://github.com/Niko1221/Strata/commit/ef6df1564444b9c5c2f0d42169732870900ed624) serve: cvec auto - the "auto" sampling value, per-request threshold, and verdict attribution ### 📊 Changes **17 files changed** (+613 additions, -74 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/kernels/cvec.hpp` (+20 -4) 📝 `include/strata/prefill/kernels.hpp` (+5 -3) 📝 `metal/src/engine/stubs.cpp` (+6 -2) 📝 `metal/src/engine/stubs_0145.cpp` (+1 -1) 📝 `serve/server.py` (+111 -10) ➕ `serve/test_projection_key.py` (+170 -0) 📝 `serve/test_web_badges.py` (+26 -1) 📝 `serve/web/app.js` (+5 -1) 📝 `src/core/verify.cpp` (+2 -2) 📝 `src/kernels/cuda/cvec.cu` (+62 -19) 📝 `src/kernels/cvec_parity.cpp` (+71 -0) 📝 `src/prefill/kernels.cu` (+12 -6) 📝 `src/prefill/prefill.cpp` (+9 -5) 📝 `src/program/generate.cpp` (+90 -5) 📝 `sycl/src/kernels/cuda/cvec.dp.cpp` (+16 -10) 📝 `sycl/src/prefill/kernels.dp.cpp` (+4 -2) 📝 `sycl/src/program/generate.cpp` (+3 -3) </details> ### 📄 Description ## Problem and result The engine (companion PR #4466) accepts `experimental_speed_projection: 2` ("auto") with a per-request refusal gate and prints its verdict on the control stdout, but the server never read it: the field normalized to bool (on/off) only, and the verdict was invisible per request. Before: bool normalization; no gate field in the request history or the built-in page. After: the request body accepts bool, the string `"auto"`, or the integer 2, plus an optional `cvec_threshold` (forwarded as `cvec_thresh=` on the `GENI` line; `/settings` and the config file take bool-or-`"auto"`). The engine's `CVECAUTO` verdict twin (generate.cpp:15766, the machine line behind its human log line) is captured off the control stdout and recorded on its own request's history entry: a new `gate` field beside `projection`, `"steer"` or `"stock"`, `null` for bool requests and for auto requests an engine never gated (batched, or an engine without the twin; a wholly-cached auto request still gets its line, measured zero, reported `stock`). The verdict is echoed to the server's stdout for the live log, and the built-in page marks an auto request that steered. Requests that never ask for auto are untouched; the default path is unchanged. ## Related discussion Scope issue: https://github.com/Niko1221/Strata/issues/4465. Engine PR #4466 carries the gate itself; split so each surface is reviewable alone. Merge order: engine first. On an engine without the gate, `cvec=2` reads as plain on (undocumented; the old test was `!= 0`), so auto on an old engine would silently steer everything while the history honestly reports `projection: "auto", gate: null`. ## Approach The verdict is captured in the pump from the engine's control stdout (the `CVECAUTO` twin, printed at the prefill→decode seam on the solo path only, like the gate itself); the parser accepts the `-inf` thresh spelling a harness gets from `--cvec-threshold -inf` (the engine's own log-only default is the `lowest()` sentinel; both spellings parse). Attribution: the request reads the pump's verdict counter at the start of its fifo turn and takes the newest verdict when the turn ends, so a queued request cannot record another's verdict; the counter survives an engine restart. History stays honest: bool stays bool, `"auto"`/2 normalize, absent means on (the existing ESP semantics). The built-in Chat's own toggle pins bool (local intent); auto is reachable through the API and settings. ## Validation **Passed:** - `python -m pytest serve/test_projection_key.py serve/test_web_badges.py serve/test_monitor.py` (branch tip ef6df156): 34 passed (20 + 4 + 10) - verdict parser (measure line, `-inf` thresh, `nan`/`infinite`/`infi` rejected, the human log line and the batched refusal parse to None), the auto domain, history tri-state, the gate badge states (steered auto renders the green ESP, unsteered the neutral auto); `test_monitor.py` as the untouched regression companion. - Live matrix (engine 0.1.52 built from nested cb034726, RTX 5090, threshold -0.9; `bench/results/2026-10-28-cvec-auto-acceptance/`): auto + harmful → the child log carries the gate line `... -> steer`; auto + benign → `-> stock`; a batched auto request → `batched -> stock`. That build predates this serve PR (no pump capture or history `gate` field yet), so those two surfaces rest on the unit tests above and the code, not on this pass. - Attribution under load (outcome evaluation, engine 0.1.52 built from the same cvec sources at the pre-split nested 4c671ed0; `bench/results/2026-10-28-cvec-auto-calibration-iq3s/cvec-outcome-qad.manifest.json` + `cvec-engine-outcome-qad.log` in that session): 86 auto requests produced 172 gate lines, prefill + answer-room re-gate per request (thinking wrapped up after one token via `reasoning_budget_tokens=1`); the serve stdout echo (1:1 with each pump capture) carries all 172, and the ordered zip attributed every request, zero no-line verdicts. Two borderline prompts flipped stock→steer at the re-gate, both lines recorded per request (`verdict` = prefill, `regate_verdict` = the tail). Serve's newest-verdict-wins attribution is exercised by the unit tests for that rule; the outcome artifact reads the engine log, so the history side of the re-gate events is code-verified, not captured. - CI `metal-link` (macOS) on this PR: pass. **Failed:** none observed. **Not run:** the re-gate's steer→stock direction (only the acceptance F-1 repro, at thinking budget 256; the outcome battery's two re-gate events were both stock→steer); `--replicas` (see Limits); a live wholly-cached or batched auto request with history-gate inspection (the parser side is unit-tested; the engine-side all-zero twin-print is code-traced, not exercised). ## Limits Attribution is solo-only (the engine prints verdicts only on the solo path; under `--batch` the gate logs `batched -> stock` and the request is served stock, `gate: null`). A wholly-cached auto request measures nothing and is reported `stock`. The re-issue path (ANSWER_ROOM under thinking) re-gates on the thinking tail and the newest verdict wins, so a harmful first pass that steered can have its re-issued decode decoded stock; the outcome evaluation exercised stock→steer, the steer→stock direction only the acceptance F-1 repro. `--replicas`: the proxy delegates to the current child, but the summed `batch` property makes every replica request read as batched, so the attribution guard nulls `gate` unconditionally under `--replicas` (a wrong verdict is unreachable; the counter split is moot); never exercised. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5060
No description provided.