Skip to content

Add two-ONNX comparison to winml eval --mode compare#1139

Draft
xieofxie wants to merge 4 commits into
mainfrom
hualxie/compare_onnx
Draft

Add two-ONNX comparison to winml eval --mode compare#1139
xieofxie wants to merge 4 commits into
mainfrom
hualxie/compare_onnx

Conversation

@xieofxie

Copy link
Copy Markdown
Contributor

Summary

Extends winml eval --mode compare so the reference can be a second ONNX file instead of only the HuggingFace PyTorch model derived from --model-id.

A new --reference <path> option points at a reference .onnx. When set, both the candidate (-m) and the reference run as raw ORT sessions (WinMLSession) on identical RandomDataset inputs, and the existing tensor-similarity metrics (cosine, SQNR, PSNR, MSE, max-abs-diff) are computed over their aligned outputs. Because both are raw ONNX graphs, no HF config/task is loaded, so --model-id and --task are not required in this path. Both sessions honor --device / --ep.

Usage

winml eval -m candidate.onnx --mode compare --reference reference.onnx

Changes

  • eval/config.py: add reference_path field (cli_name="reference") with to_dict / from_dict support.
  • commands/eval.py: add --reference option; _resolve_reference() normalizes hub refs and validates .onnx existence; allow_missing_model_id lets a bare ONNX candidate skip the --model-id requirement; guard so --reference only works with --mode compare; print the reference path.
  • eval/evaluate.py: skip task resolution and load no torch model for the two-ONNX path; guard None model_id/task and print the reference in the config summary.
  • eval/tensor_similarity_evaluator.py: add _ONNXSessionModel wrapper (exposes onnx_path, io_config, __call__ returning torch tensors); build both raw sessions when reference_path is set, reusing the existing similarity metrics.
  • docs/commands/eval.md: document --reference, clarify --mode, add a two-ONNX example.
  • Tests: cover config round-trip, _resolve_reference validation, the compare-mode guard, bare-ONNX candidate handling, the two-ONNX evaluate flow, and the _ONNXSessionModel wrapper.

Scope

Phase 1 supports an ONNX-file reference only. HF-local-folder and composite-model references are deferred.

Introduce a --reference option so --mode compare can diff two ONNX files
directly instead of only comparing an ONNX candidate against its HF
PyTorch reference. Both models run as raw ORT sessions on identical
RandomDataset inputs, so --model-id and --task are not required and no
torch/transformers reference is loaded.

- config: add reference_path field (to_dict/from_dict)
- cli: --reference option, _resolve_reference validation/normalization,
  allow bare ONNX candidate without --model-id, require --mode compare
- evaluate: skip task resolution and return no model for the two-ONNX
  path; print reference in config summary
- evaluator: _ONNXSessionModel wrapper; build both raw sessions when
  reference_path is set, reusing the existing similarity metrics
- docs + unit tests
@xieofxie
xieofxie requested a review from a team as a code owner July 20, 2026 03:31
Hualiang Xie added 2 commits July 20, 2026 14:23
Support comparing a candidate and reference on real input tensors from a
.npz archive instead of randomly generated ones, mirroring winml perf's
--input-data. The whole archive is treated as a single sample and its keys
are validated/cast against the candidate's inputs. Only valid with
--mode compare (accuracy modes need labels).

- datasets/input_data.py: shared load_input_data (moved from perf) plus a
  single-sample InputDataDataset wrapper
- perf: load_input_data now delegates to the shared module (lazy import,
  same public symbol)
- config: add input_data field (to_dict/from_dict)
- cli: --input-data option, compare-mode guard, example; report header
  shows Reference / Input data / Samples: 1
- evaluator: prepare_data builds InputDataDataset when input_data is set
- evaluate: print the input-data path in the config summary
- docs + unit tests
@xieofxie
xieofxie marked this pull request as draft July 20, 2026 06:40
Treat the leading axis of each .npz array as the sample axis so a single
archive can hold N samples. All inputs must share the same leading length
N; scalars and empty arrays are rejected with a clear error. The compare
loop runs each sample independently (sliced to a batch of 1), so the
similarity metrics table reflects a real distribution (mean/std/min/max)
across N inputs. The effective sample count is propagated to the report
header and JSON output.
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