[PR #2466] [CLOSED] engine+serve: the confidence monitor (STRATA_CONFIDENCE=1, measurement only) #4054

Closed
opened 2026-11-07 15:32:49 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2466
Author: @MrKop-git
Created: 10/14/2026
Status: ❌ Closed

Base: main ← Head: pr/confidence-monitor


📝 Commits (1)

  • 7b1c08c engine+serve: the confidence monitor (STRATA_CONFIDENCE=1, measurement only) - ActKV's token confidence, trend slope and a /metrics summary

📊 Changes

9 files changed (+341 additions, -2 deletions)

View changed files

📝 CMakeLists.txt (+3 -0)
📝 docs/DETAILS.md (+10 -0)
➕ include/strata/core/confidence.hpp (+109 -0)
📝 include/strata/core/verify.hpp (+5 -0)
📝 serve/server.py (+28 -1)
📝 serve/test_server.py (+51 -1)
➕ src/core/confidence_test.cpp (+82 -0)
📝 src/core/verify.cpp (+30 -0)
📝 src/program/generate.cpp (+23 -0)

📄 Description

Summary

An online number for "is the model confident right now" - ActKV's confidence signal (arXiv:2609.31395, section 6), which its evaluation used to detect an insufficient KV budget from the model's own behaviour:

  • Per kept decode row: ActKV's token confidence T = the negative mean log-probability of the top 20 predicted tokens (a higher T is a sharper distribution).
  • Per request: the mean of T and ActKV's trend slope alpha (sliding min-pool w=64 s=8, bottom 10% kept, first-order fit; negative means confidence is falling). The engine emits CONF <tokens> <mean> <slope> just before the request's DONE; the server attaches it to the request row and GET /metrics carries a "confidence" summary (count, mean, last mean, last slope).

Why it belongs in the engine: it is the signal for comparing lossy settings the numbers cannot - --kv q4_0 against int8, a tight --kv-resident - and later for budget feedback. The constants are ActKV's evaluation values; nothing here claims they are right for Strata, and no default changes.

What it changes and what it leaves alone

STRATA_CONFIDENCE=1 in the environment turns it on. Without the flag nothing runs: no copies, no line changes, every answer unchanged. The flag copies the head's logits from the GPU once per window (the STRATA_LOGPOS pattern), so it slows the decode - like STRATA_DECODE_TIMING, for comparing, not timing. No Metal path (it says so and turns itself off there).

How it was checked

  • src/core/confidence_test.cpp (CPU): the math on hand-worked rows (a flat row gives T = log V, a peaked row the exact value), the pooling, and the time ordering the trend fit needs - that last one caught a bug in my first cut (sorting the bottom set destroyed the trend).
  • serve/test_server.py (ConfidenceMonitor): the CONF-before-DONE pairing, a bad CONF line refusing to poison DONE, the row fields and the summary through GET /metrics. The full serve suite passes: 787 tests, 11 skipped.
  • Live on this box's GTX 1080 Ti (IQ3_S, --serve, two GENs in one session, STRATA_CONFIDENCE=1): a 128-token repeating prompt reports CONF 7 5.7530 0.000000, a scattered-id prompt CONF 1 4.7600 0.000000 - the metric moves the way ActKV's signal should. slope is 0 for requests shorter than one pool window (pinned by the test too).

Not tested

HIP (no toolchain here) and SYCL (separate engine tree). Multi-window trend behaviour on a long request (the live run's requests are short - the slope path is exercised in the unit test, not on hardware). Any threshold for "confidence is too low" - this PR is the measurement, not the alarm.

🤖 Generated with Claude Code


🔄 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/2466 **Author:** [@MrKop-git](https://github.com/MrKop-git) **Created:** 10/14/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/confidence-monitor` --- ### 📝 Commits (1) - [`7b1c08c`](https://github.com/Niko1221/Strata/commit/7b1c08c08e8d08b6b0b1d5f322c50594b5146776) engine+serve: the confidence monitor (STRATA_CONFIDENCE=1, measurement only) - ActKV's token confidence, trend slope and a /metrics summary ### 📊 Changes **9 files changed** (+341 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+3 -0) 📝 `docs/DETAILS.md` (+10 -0) ➕ `include/strata/core/confidence.hpp` (+109 -0) 📝 `include/strata/core/verify.hpp` (+5 -0) 📝 `serve/server.py` (+28 -1) 📝 `serve/test_server.py` (+51 -1) ➕ `src/core/confidence_test.cpp` (+82 -0) 📝 `src/core/verify.cpp` (+30 -0) 📝 `src/program/generate.cpp` (+23 -0) </details> ### 📄 Description ## Summary An online number for "is the model confident right now" - ActKV's confidence signal (arXiv:2609.31395, section 6), which its evaluation used to detect an insufficient KV budget from the model's own behaviour: - **Per kept decode row**: ActKV's token confidence `T` = the negative mean log-probability of the top 20 predicted tokens (a higher `T` is a sharper distribution). - **Per request**: the mean of `T` and ActKV's trend slope `alpha` (sliding min-pool w=64 s=8, bottom 10% kept, first-order fit; negative means confidence is falling). The engine emits `CONF <tokens> <mean> <slope>` just before the request's `DONE`; the server attaches it to the request row and `GET /metrics` carries a `"confidence"` summary (count, mean, last mean, last slope). Why it belongs in the engine: it is the signal for comparing lossy settings the numbers cannot - `--kv q4_0` against `int8`, a tight `--kv-resident` - and later for budget feedback. The constants are ActKV's evaluation values; nothing here claims they are right for Strata, and no default changes. ## What it changes and what it leaves alone `STRATA_CONFIDENCE=1` in the environment turns it on. **Without the flag nothing runs**: no copies, no line changes, every answer unchanged. The flag copies the head's logits from the GPU once per window (the `STRATA_LOGPOS` pattern), so it slows the decode - like `STRATA_DECODE_TIMING`, for comparing, not timing. No Metal path (it says so and turns itself off there). ## How it was checked - `src/core/confidence_test.cpp` (CPU): the math on hand-worked rows (a flat row gives `T = log V`, a peaked row the exact value), the pooling, and the time ordering the trend fit needs - that last one caught a bug in my first cut (sorting the bottom set destroyed the trend). - `serve/test_server.py` (`ConfidenceMonitor`): the `CONF`-before-`DONE` pairing, a bad `CONF` line refusing to poison `DONE`, the row fields and the summary through `GET /metrics`. **The full serve suite passes: 787 tests, 11 skipped.** - **Live on this box's GTX 1080 Ti** (IQ3_S, `--serve`, two `GEN`s in one session, `STRATA_CONFIDENCE=1`): a 128-token repeating prompt reports `CONF 7 5.7530 0.000000`, a scattered-id prompt `CONF 1 4.7600 0.000000` - the metric moves the way ActKV's signal should. `slope` is 0 for requests shorter than one pool window (pinned by the test too). ## Not tested HIP (no toolchain here) and SYCL (separate engine tree). Multi-window trend behaviour on a long request (the live run's requests are short - the slope path is exercised in the unit test, not on hardware). Any threshold for "confidence is too low" - this PR is the measurement, not the alarm. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:32:49 +07:00
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#4054
No description provided.