Skip to content

Fix Windows ONNX external data corruption by upgrading ONNX - #2816

Merged
kevalmorabia97 merged 5 commits into
NVIDIA:mainfrom
anmaurya001:fix/windows-onnx-external-data
Oct 24, 2026
Merged

kevalmorabia97 merged 5 commits into
NVIDIA:mainfrom
anmaurya001:fix/windows-onnx-external-data

Conversation

@anmaurya001

@anmaurya001 anmaurya001 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

Upgrade the ONNX extra from ~=1.21.0 to the locally validated ~=1.23.2 release line on Windows only. Non-Windows platforms retain ~=1.21.0, as requested in review. On Windows, exporting multiple tensors into shared external data with ONNX 1.21.0 can truncate a trailing 0x1A byte when reopening the file. Subsequent tensors overwrite earlier data, corrupting quantized weights and scales. This can produce incorrect output and runaway generation that eventually overflows the conversation context.

ONNX already corrected Windows binary-mode file opening upstream in onnx/onnx#7790. This change consumes the released fix and adds a regression test through ModelOpt's save_onnx, checking shared-file bytes and tensor round trips. Existing corrupted exports must be regenerated from clean weights.

The lockfile is intentionally left to the weekly workflow, as required by CONTRIBUTING.md.

Usage

Reinstall the ONNX extra with the updated dependency and regenerate affected exports from clean weights. No API changes.

Testing

  • Windows regression test on this branch: ONNX 1.23.2 passes all three cases. The unmodified ONNX 1.21.0 wheel fails the trailing-0x1A case (byte 1023 is overwritten), while the two control cases pass.
  • Changed-file pre-commit checks cover formatting, lint, typing, license headers, security lint, TOML and reStructuredText validation.
  • Focused command: python -m pytest -o addopts='' --noconftest tests/unit/onnx/test_external_data.py -q. The normal ONNX autouse C++ compilation fixture failed in this local environment; this run excludes repository conftest fixtures and optional coverage hooks.
  • Prior local end-to-end validation used ModelOpt 0.45.0rc0 with the unmodified ONNX 1.23.2 wheel: regenerated AWQ-lite INT4 model using 32 calibration samples; checked 341 external tensors with no overlaps or invalid scales; CUDA two-turn chat answered Paris and 4 and stopped normally.
  • Full local five-shot MMLU, all 57 subjects and 14,042 examples: regenerated INT4 8,099/14,042 (57.676969%); clean FP16 8,374/14,042 (59.635380%). These pipeline results are from the earlier ModelOpt configuration, not a full pipeline run on this PR's current main base.
  • Exact original CI reproduction and the complete current-main test suite have not been run. Release CI and reviewer validation remain required.

Before your PR is "Ready for review"

  • Is this change backward compatible?: Yes; no API changes. The ONNX dependency release line changes on Windows only.
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md?: N/A; existing dependency upgraded, no copied upstream implementation.
  • Did you write any new necessary tests?: Yes.
  • Did you update Changelog?: Yes.
  • Did you get Claude approval on this PR?: Pending; keep as draft until required review is complete.

Additional Information

Addresses NVBugs 6309022 and 6561663 through the shared Windows external-data corruption fix. Local evidence supports this cause; original CI acceptance remains pending.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue that could corrupt external tensor data when exporting ONNX models on Windows. Regenerate affected models from clean weights to ensure their data is intact.
  • Updates
    • Windows installations now use ONNX 1.23.2 for improved export compatibility. Non-Windows installations continue to use ONNX 1.21.0.

Signed-off-by: anmaurya001 <anmaurya@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 9103d57 and 3d63956.

Files selected for processing: 2
  • CHANGELOG.rst
  • pyproject.toml
Files skipped from review as they are similar to previous changes: 1
  • CHANGELOG.rst

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Walkthrough

The Windows ONNX dependency changes to version 1.23.2, while non-Windows systems retain version 1.21.0. A parametrized test checks external tensor bytes for three final-byte values and verifies that loading the model restores both tensors.

Changes: ONNX external tensor data

Layer / File(s) Summary
ONNX dependency and external-data regression test
pyproject.toml, docs/source/getting_started/windows/_installation_windows_arm64.rst, tests/unit/onnx/test_external_data.py, CHANGELOG.rst
The optional ONNX dependency uses version 1.23.2 on Windows and 1.21.0 on other platforms. The Windows ARM64 installation command and changelog are updated. A parametrized test checks external data bytes for three final-byte values and verifies that loading restores both tensors.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • NVIDIA/Model-Optimizer#2939: Adds shared ONNX model saving with external sidecar output and tests external tensor-data round trips, related to the same serialization behavior.
Merge Risk: Minimal · up to 3d639

No actionable merge-blocking risk remains in the reviewed changes.

Pre-merge checks: Passed 5 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (2 skipped: 2 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 5 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: upgrading ONNX to fix Windows external-data corruption.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns Passed PASS. The PR changes only one Python file, tests/unit/onnx/test_external_data.py, and it adds no torch.load(..., weights_only=False), numpy.load(..., allow_pickle=True), hardcoded `trust_remote_…
Full details: Security Anti-Patterns

Explanation

PASS. The PR changes only one Python file, tests/unit/onnx/test_external_data.py, and it adds no torch.load(..., weights_only=False), numpy.load(..., allow_pickle=True), hardcoded trust_remote_code=True, eval(), exec(), or # nosec. The pyproject.toml change only splits the existing onnx dependency by Windows platform and updates its version; it does not add a new dependency.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Comment thread CHANGELOG.rst Outdated
Comment thread pyproject.toml Outdated
"ml_dtypes",
"onnx-graphsurgeon>=0.6.1",
"onnx~=1.21.0",
"onnx~=1.23.2",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ajrasane does this affect Linux onnx features?

@kevalmorabia97

Copy link
Copy Markdown
Collaborator

/ok to test 50eecd0

Signed-off-by: anmaurya001 <anmaurya@nvidia.com>
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.11%. Comparing base (0638a27) to head (3d63956).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2816      +/-   ##
==========================================
- Coverage   79.82%   79.11%   -0.71%     
==========================================
  Files         661      661              
  Lines       74928    74928              
==========================================
- Hits        59810    59282     -528     
- Misses      15118    15646     +528     
Flag Coverage Δ
examples-diffusers 19.90% <ø> (-0.04%) ⬇️
examples-gpt-oss 13.44% <ø> (-0.03%) ⬇️
examples-hf_ptq 23.34% <ø> (-0.08%) ⬇️
examples-llm_distill 13.52% <ø> (-0.03%) ⬇️
examples-llm_eval 17.17% <ø> (-0.04%) ⬇️
examples-llm_qat 17.34% <ø> (-0.07%) ⬇️
examples-llm_sparsity 16.76% <ø> (-0.04%) ⬇️
examples-megatron_bridge 26.39% <ø> (-0.26%) ⬇️
examples-specdec_bench 13.23% <ø> (-0.03%) ⬇️
examples-speculative_decoding 17.42% <ø> (-0.10%) ⬇️
examples-torch_onnx 21.22% <ø> (-0.06%) ⬇️
examples-torch_trt 15.15% <ø> (-0.03%) ⬇️
examples-vllm_serve 17.38% <ø> (-0.04%) ⬇️
gpu 58.91% <ø> (-1.17%) ⬇️
regression 15.04% <ø> (-0.04%) ⬇️
unit 61.11% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cjluo-nv cjluo-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.

The ONNX bump and the regression test look correct, but the Windows ARM64 install guide still pins the ONNX version that has the corruption bug, so the fix only reaches part of the affected Windows users.

Needs action:

  • Update "onnx~=1.21.0" to "onnx~=1.23.2" in the manual pip install block of docs/source/getting_started/windows/_installation_windows_arm64.rst. Native Windows ARM64 users install from that command, so they would still get corrupted external data.
  • Confirm tests/unit/onnx/test_external_data.py runs in a Windows CI job. On Linux the test passes with either ONNX version, so it only catches this regression on Windows.
  • Confirm onnxconverter-common~=1.16.0, onnx-graphsurgeon, polygraphy and the pinned onnxruntime-gpu==1.22.0 (Windows x64) all work with ONNX 1.23.x. Your validation was a single end-to-end run.

No action needed:

  • The test matches how save_onnx writes external data: the file is named basename + "_data" and size_threshold=1024. Each 1 KiB tensor gets written out, and both are well below ONNX's alignment threshold, so the expected bytes are just the two tensors back to back.
  • The new test file's header is the standard NVIDIA Apache-2.0 header. No other licensing changes.

Comment thread pyproject.toml Outdated
Signed-off-by: anmaurya001 <anmaurya@nvidia.com>

@cjluo-nv cjluo-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.

Nudge: the earlier concerns are fixed, but a maintainer's question about Linux impact is still unanswered. The ONNX owner needs to confirm the 1.21 → 1.23 bump before this merges.

Needs action:

  • Confirm the 1.21 → 1.23 ONNX bump doesn't regress Linux ONNX features. @kevalmorabia97 asked @ajrasane on pyproject.toml:61 and nobody has replied yet. The compatibility checks the author reported were local only, and the lockfile is deliberately left to the weekly bump workflow.

No action needed:

  • ✔️ Resolved since the last review:
    • The ARM64 install guide now pins onnx~=1.23.2.
    • The CHANGELOG entry sits under 0.48.0 Bug Fixes, as requested.
    • The new test runs on Windows: the windows job in unit_tests.yml runs the full unit suite (not merge-gating), and the author reports all three cases passed there.
  • The new test in tests/unit/onnx/test_external_data.py matches how save_onnx writes external data, and it targets the trailing-0x1A truncation. Its header is the standard NVIDIA Apache-2.0 header.

Comment thread pyproject.toml Outdated
Signed-off-by: anmaurya001 <anmaurya@nvidia.com>
@kevalmorabia97
kevalmorabia97 marked this pull request as ready for review October 23, 2026 17:25
@kevalmorabia97
kevalmorabia97 requested review from a team as code owners October 23, 2026 17:25
Signed-off-by: anmaurya001 <anmaurya@nvidia.com>
@kevalmorabia97

Copy link
Copy Markdown
Collaborator

/ok to test 3d63956

@copy-pr-bot

copy-pr-bot Bot commented Oct 24, 2026

Copy link
Copy Markdown

/ok to test 3d63956

@kevalmorabia97, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@kevalmorabia97
kevalmorabia97 enabled auto-merge (squash) October 24, 2026 16:01
@kevalmorabia97

Copy link
Copy Markdown
Collaborator

/ok to test 3d63956

@kevalmorabia97
kevalmorabia97 merged commit 3c423a9 into NVIDIA:main Oct 24, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants