Skip to content

testgpuerror: measure FP16 error on the ONNX backend instead of comparing the net to itself - #1291

Open
seniorfish wants to merge 4 commits into
lightvector:masterfrom
seniorfish:fix/onnx-fp16-reporting
Open

seniorfish wants to merge 4 commits into
lightvector:masterfrom
seniorfish:fix/onnx-fp16-reporting

Conversation

@seniorfish

@seniorfish seniorfish commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Not a fix for #1238

This PR does not fix the wrong-output bug in #1238. It only stops the diagnostic from reporting zero error when it never measured anything. Judging correctness still requires -reference-file or a separate script, because a relative comparison passes if both sides make the same mistake.

Thanks to @pjw65, who suspected that the reference ran through the same backend. That turned out to be the case.

Why

testgpuerror should compare a net against an FP32 reference and report the difference. Two bugs prevented this on the ONNX backend.

First, the backend builds an FP32 graph and lets the execution provider choose runtime precision. Because the graph was FP32, isUsingFP16 always returned false even when running at reduced precision. Seeing false, testgpuerror skipped building an FP32 reference, compared the net to itself, and reported 0% error. On an OpenVINO GPU, which defaults to FP16, this looked like a clean pass without measuring anything.

Second, the reference net uses disableFP16, which only forced FP32 when onnxOpenVINOPrecision was empty. An explicit setting produced a second FP16 net instead.

Both bugs are now fixed. isUsingFP16 reports actual runtime precision, and useFP16 = false overrides an explicit precision setting.

The logs are clearer too, since 0% from a self-comparison looked like a real check. Output now explicitly states when an evaluator compares against itself with no external reference, and the batch check is no longer called "fp32 error". We also log the ONNX Runtime version, as several behaviors depend on it.

Finally, onnxOpenVINOPrecision now accepts only FP16 and FP32 (including lowercase fp32), dropping ACCURACY for three reasons. To start, ACCURACY just keeps the graph's precision rather than naming one, so user-supplied .onnx files depend on the file instead of the config, preventing honest reporting. Also, every other backend offers a single on/off choice. Beyond that, the name confuses users by looking like a distinct option while behaving just like FP32 on our graphs. ONNX Runtime has deprecated it as well, and the replacement API only takes precision hints.

Size

8 files changed.

Testing

Tested on Windows 11 with an Intel Arc B580 using OpenVINO and a 9x9 net.

  • Default and explicit FP16 build an FP32 reference and report expected FP16 error (~0.09% avg).
  • FP32 skips the reference and logs the self-comparison.
  • ACCURACY is rejected at startup.
  • Results agree with an external Eigen reference file.

isUsingFP16 returned false unconditionally, on the grounds that the emitted ONNX graph is fp32 and precision is chosen inside the execution provider. That is true of the graph, but the callers ask a different question: gputest and contribute use it to decide whether a separate FP32 evaluator can be built as a reference, so on OpenVINO they never built one. testgpuerror then compared the candidate against a copy of itself, reported exactly zero error and passed, while the OpenVINO GPU was in fact running FP16.

Report the effective per-thread precision instead: only OpenVINO downcasts the graph, an NPU-only thread cannot be asked for FP32 at all, and any precision other than FP32 keeps a reduced-precision path. FP32-only providers and NPU threads still report false, which keeps them on the self-comparison path rather than failing to build a reference.

Also let useFP16 = false override an explicitly set non-FP32 onnxOpenVINOPrecision. The reference evaluator is created with disableFP16, and while that override only applied to an empty precision, a config that set onnxOpenVINOPrecision explicitly would have produced a second FP16 evaluator, reinstating the self-comparison the change above is meant to remove.
When no separate FP32 evaluator can be built (FP32-only providers, an FP16-only NPU) or no reference file was given, the reference pass is the candidate itself. The first comparison is then zero by construction and only the second, batch-vs-serial, is a real test, so a zero result must not read as a passed precision check.

Name the evaluator and the reference source in the logs, relabel both stat blocks accordingly, and update the command help and the ONNX model docs to say that this is a relative test and that -reference-file is the absolute one. An Eigen build writes the reference file rather than loading it, so say that too instead of implying a comparison took place.

Derive the self-versus-reference distinction once, where the reference is chosen, so the labels cannot drift from what was actually compared.
Several behaviors here depend on the runtime version: the input-ordering workaround dates from ORT 1.23.0, the provider option set this backend passes is deprecated in favor of load_config, and precision handling differs between the built-in OpenVINO EP and the plugin EP. Without the version in the log, a report of a failed session cannot be tied to a runtime build.

Log it before any config check can throw, so a session that fails to build still reports the version. The OpenVINO runtime version is not available through the EP interface (ProviderInfo_OpenVINO only exposes GetAvailableDevices), so this logs ORT only.
The OpenVINO provider also accepts ACCURACY, which is not a precision but an execution-mode hint: it keeps whatever precision the graph already has. For the graph this backend emits that is indistinguishable from FP32, but for a .onnx file whose own tensors are fp16 it silently runs fp16, so the effective precision depends on the model file rather than on the config. KataGo offers exactly two settings here, the same choice useFP16 gives on the other backends, so reject the rest at config time with a message naming the supported values instead of letting the provider fail at session creation with its own device-dependent wording.

Checking the value needs its domain spelled out anyway, so also canonicalize the case: onnxOpenVINOPrecision = fp32 previously failed inside ORT because the provider is case-sensitive, and now works. The check runs after the useFP16 = false override, so a config asking for full FP32 that way is satisfied rather than rejected. With the domain enforced, threadUsesReducedPrecision can go back to a plain comparison against FP32 instead of guessing what an unrecognized value means.

BREAKING CHANGE: a config with onnxOpenVINOPrecision = ACCURACY now fails at startup. Use FP32, which gives the same effective precision for the graphs KataGo emits, or FP16.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant