Repository navigation
testgpuerror: measure FP16 error on the ONNX backend instead of comparing the net to itself - #1291
Open
seniorfish wants to merge 4 commits into
Open
seniorfish wants to merge 4 commits into
seniorfish wants to merge 4 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-fileor 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
testgpuerrorshould 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,
isUsingFP16always returnedfalseeven when running at reduced precision. Seeingfalse,testgpuerrorskipped 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 whenonnxOpenVINOPrecisionwas empty. An explicit setting produced a second FP16 net instead.Both bugs are now fixed.
isUsingFP16reports actual runtime precision, anduseFP16 = falseoverrides 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,
onnxOpenVINOPrecisionnow accepts onlyFP16andFP32(including lowercasefp32), droppingACCURACYfor three reasons. To start,ACCURACYjust keeps the graph's precision rather than naming one, so user-supplied.onnxfiles 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 likeFP32on 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.
FP16build an FP32 reference and report expected FP16 error (~0.09% avg).FP32skips the reference and logs the self-comparison.ACCURACYis rejected at startup.