Repository navigation
npu: key a score answer by level index, as upstream does (#653) - #776
Conversation
d3_runtime's normalize_question() renders a score as a choice whose option keys are the level
INDICES ("0","1",...) and whose descriptions are the level texts, so product_answer() emits
`probabilities` and `legend` keyed that way. npu/systemone.h keyed both by the level text instead,
which is a different answer object for the same decision -- invisible until now because the nine
golden fixtures only cover the prompt, and because score's `score` and `confidence` values were
already identical.
The prompt is unchanged: it prints the answer code and the level text, neither of which was ever
the key. ctest systemone_contract now asserts that a score answer is keyed "0".."n-1" and that it
is not keyed by the level text.
PR Reviewer Guide 🔍(Review updated until commit 06af0fa)Here are some key observations to aid the review process:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
Small, and I checked the claim against the reference implementation rather than against the PR's own quote of it.
Ran: tests/systemone_test.cpp at f3c9efa9 — systemone: ok, rc 0 (it now carries the two new assertions:
keys are "0"/"1"/"2", legend["1"] == "ok", and neither map is keyed by the level text).
Verified against d3_runtime.py itself (the pack's copy on this box, /tmp/d3meta/d3_runtime.py):
normalize_question(), score branch:
return Question(kind, question, rendered,
[str(i) for i in range(len(levels))], # keys
list(criteria)) # descriptions
product_answer(), score branch:
"probabilities": dict(zip(question.keys, shares)),
"legend": {key: _canonical(text) for key, text in zip(question.keys, question.descriptions)},
So the keys really are the level indices and the legend really is keyed by them — the change matches upstream
exactly, and score/confidence are unchanged because upstream computes them from enumerate(shares), which the
C++ already did. The prompt side is untouched too: upstream renders criteria: {text: None for text in levels}, i.e.
texts only, which is what this tree already emitted — so the "nine golden fixtures could not see it" explanation is
right, they cover the prompt.
Nit, not a blocker: the new comment says "upstream's option KEY is the level's index while the level text is only what
the prompt shows", which is true of score but reads as a rule for all kinds — for choice, upstream's keys are the
caller's criteria keys (keys = list(criteria)), and noul uses options(rendered). One word ("for a score, …")
keeps a future reader from applying it to choice.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
Confirmation at 743404b3 after update-branch (main's #768 squash merged in; author commit f3c9efa unchanged). Re-ran
the suite rather than assuming the merge was inert:
$ g++-16 -std=c++26 -O1 -Inpu … tests/systemone_test.cpp && ./systemone_test
systemone: ok rc 0
The keying claim still matches d3_runtime.py ([str(i) for i in range(len(levels))] in normalize_question, and
product_answer keying probabilities/legend by it). Nit unchanged: the new comment reads as a rule for every kind
but is true of score. tprs-ready stays.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
Confirmation at 06af0fa6 after update-branch: their own files are byte-identical to the head I verdicted — verified with
git diff --stat <previous head> 06af0fa6 -- <this PR's paths> → empty, the merge brought #768's and #775's squashes
(7f4e98a, e55096b) and nothing else. Content as reviewed (systemone), build green. tprs-ready stays.
|
Persistent review updated to latest commit 06af0fa |
What
A one-question answer object is keyed wrongly for
score, found while writing the/v1/systemoneroute (#775) on top of this contract.d3_runtime.normalize_question()renders a score as a choice whose option keys are the level indices, not the level texts:and
product_answer()builds the answer from those keys:npu/systemone.h::answer_of()keyed both by the level text instead, so a client readingprobabilitiesorlegendsaw{"cheap": …}where the d3 server it stands in for emits{"1": …}.scoreandconfidencewere already identical, and the prompt is untouched (it prints the answer code and the level text, neither of which was ever the key) — which is why the nine golden fixtures, which cover the prompt only, could not see it.Change
npu/systemone.h: the score branch pushes"0".."n-1"as the option keys, with the level texts still what the prompt shows and the legend describes.tests/systemone_test.cpp:ctest systemone_contractnow asserts the keys are"0"/"1"/"2", thatlegend["1"] == "ok", and that neither map is keyed by the level text.Verified
ctest systemone_contract,systemone_route,decision_head,npu_samplingtools/copyright.py --checkd3_format.pyfixtures)/v1/systemonescore row with #775 + this applied locally (Qwen3-0.6B, synthetic readout, host GEMM undernpu-hold -l npufeat, 0 amdxdna errors){"confidence":0.810,"legend":{"0":"bad","1":"ok","2":"great"},"probabilities":{"0":0.949,"1":0.0492,"2":0.00167},"score":0.0525,"type":"score"}Independent of #775: this is the contract's answer shape, so it can land in either order.
That row is measured on a tree with both commits (this one cherry-picked onto #775's branch, then removed again — #775 stays a single commit and this PR is independent of it). Before this change the same request answered
{"bad":…,"ok":…,"great":…}, which is the divergence this PR fixes.