Skip to content

use torch to compute discrepancies in OnnxDiscrepancyCheck#2540

Merged
xiaoyu-work merged 9 commits into
mainfrom
xadupre/disc
Jun 24, 2026
Merged

use torch to compute discrepancies in OnnxDiscrepancyCheck#2540
xiaoyu-work merged 9 commits into
mainfrom
xadupre/disc

Conversation

@xadupre

@xadupre xadupre commented Jun 23, 2026

Copy link
Copy Markdown
Member

Describe your changes

OnnxDiscrepancyCheck is using numpy to compute discrepancies, it must be switched to torch for bfloat16.

@xadupre xadupre marked this pull request as ready for review June 23, 2026 10:37
Copilot AI review requested due to automatic review settings June 23, 2026 10:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates OnnxDiscrepancyCheck to use PyTorch (instead of NumPy) for element-wise discrepancy computations so the pass can handle bfloat16 models, and adds unit tests for inferring ONNX weight dtypes to align reference-model precision.

Changes:

  • Added ONNX weight dtype inference + ONNX→torch dtype mapping utilities and used them to cast the reference HF model to match ONNX weight precision.
  • Replaced NumPy-based absolute-difference computation with a torch-based implementation (double precision).
  • Added unit tests covering ONNX weight dtype inference and dtype mapping.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
olive/passes/onnx/discrepancy_check.py Adds ONNX weight dtype inference + switches discrepancy math to torch; casts reference model to match inferred ONNX precision.
test/passes/onnx/test_discrepancy_check.py Adds unit tests for ONNX weight dtype inference and ONNX→torch dtype mapping.

Comment thread olive/passes/onnx/discrepancy_check.py Outdated
Comment thread olive/passes/onnx/discrepancy_check.py Outdated
Comment thread olive/passes/onnx/discrepancy_check.py
Comment thread test/passes/onnx/test_discrepancy_check.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread olive/passes/onnx/discrepancy_check.py
Comment thread test/passes/onnx/test_discrepancy_check.py Outdated
xadupre and others added 2 commits June 23, 2026 13:59
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@xiaoyu-work

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@xiaoyu-work xiaoyu-work merged commit 160de9d into main Jun 24, 2026
13 checks passed
@xiaoyu-work xiaoyu-work deleted the xadupre/disc branch June 24, 2026 17:31
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.

5 participants