From 50eecd04b2de5fa13e1b473d5ca6fccba926699d Mon Sep 17 00:00:00 2001 From: anmaurya001 Date: Thu, 15 Oct 2026 17:05:38 +0530 Subject: [PATCH 1/4] Fix Windows ONNX external data corruption by upgrading ONNX Signed-off-by: anmaurya001 --- CHANGELOG.rst | 1 + pyproject.toml | 2 +- tests/unit/onnx/test_external_data.py | 42 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/unit/onnx/test_external_data.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1cf3bf26f8b..0d1dd76e27b 100755 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,7 @@ Changelog **Bug Fixes** +- Fix corrupted ONNX external tensor data when exporting models on Windows by upgrading ONNX. Regenerate affected models from clean weights. - Fix ONNX preprocessing with custom TensorRT plugin libraries on TensorRT 11. - Fix ``INT8_DEFAULT_CFG``, ``FP8_DEFAULT_CFG``, ``NVFP4_DEFAULT_CFG`` and the other presets and recipes that import ``configs/ptq/units/default_disabled_quantizers`` and enable ``*input_quantizer``: since 0.44 they also quantized ``nn.LayerNorm`` inputs, which adds quantization error to the residual stream of models built on ``nn.LayerNorm`` such as BERT-style encoders. Re-quantize affected models; a recipe that wants ``nn.LayerNorm`` quantizers must enable them after importing that unit. diff --git a/pyproject.toml b/pyproject.toml index a72fc5e1014..fae0d41f5f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ onnx = [ "lief", "ml_dtypes", "onnx-graphsurgeon>=0.6.1", - "onnx~=1.21.0", + "onnx~=1.23.2", "onnxconverter-common~=1.16.0", # Python 3.10 support for ModelOpt ONNX is deprecated and will be removed in a future release. # Native Windows ARM64 does not support ModelOpt ONNX on Python 3.10. diff --git a/tests/unit/onnx/test_external_data.py b/tests/unit/onnx/test_external_data.py new file mode 100644 index 00000000000..ddb77e997f8 --- /dev/null +++ b/tests/unit/onnx/test_external_data.py @@ -0,0 +1,42 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import onnx +import pytest + +from modelopt.onnx.utils import save_onnx + + +@pytest.mark.parametrize("last_byte", [0x00, 0x0A, 0x1A]) +def test_save_external_data_preserves_tensor_boundaries(tmp_path, last_byte): + # Windows text-mode file opening can truncate a trailing Ctrl-Z before append. + first = np.full(1024, 0x41, dtype=np.uint8) + first[-1] = last_byte + second = np.full(1024, 0x42, dtype=np.uint8) + tensors = [ + onnx.numpy_helper.from_array(value, name) + for name, value in [("first", first), ("second", second)] + ] + graph = onnx.helper.make_graph([], "external_data", [], [], initializer=tensors) + model = onnx.helper.make_model(graph) + path = tmp_path / "model.onnx" + + save_onnx(model, str(path), save_as_external_data=True) + + assert (tmp_path / "model.onnx_data").read_bytes() == first.tobytes() + second.tobytes() + restored = onnx.load(path) + for actual, expected in zip(restored.graph.initializer, [first, second], strict=True): + np.testing.assert_array_equal(onnx.numpy_helper.to_array(actual), expected) From 39312c0a4a8f80d5a1f18ff891333be17cf57bcb Mon Sep 17 00:00:00 2001 From: anmaurya001 Date: Thu, 15 Oct 2026 17:21:45 +0530 Subject: [PATCH 2/4] Move Windows ONNX fix to the 0.48 changelog Signed-off-by: anmaurya001 --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0d1dd76e27b..d0ce20eb242 100755 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,7 +12,6 @@ Changelog **Bug Fixes** -- Fix corrupted ONNX external tensor data when exporting models on Windows by upgrading ONNX. Regenerate affected models from clean weights. - Fix ONNX preprocessing with custom TensorRT plugin libraries on TensorRT 11. - Fix ``INT8_DEFAULT_CFG``, ``FP8_DEFAULT_CFG``, ``NVFP4_DEFAULT_CFG`` and the other presets and recipes that import ``configs/ptq/units/default_disabled_quantizers`` and enable ``*input_quantizer``: since 0.44 they also quantized ``nn.LayerNorm`` inputs, which adds quantization error to the residual stream of models built on ``nn.LayerNorm`` such as BERT-style encoders. Re-quantize affected models; a recipe that wants ``nn.LayerNorm`` quantizers must enable them after importing that unit. @@ -149,6 +148,7 @@ Changelog **Bug Fixes** +- Fix corrupted ONNX external tensor data when exporting models on Windows by upgrading ONNX. Regenerate affected models from clean weights. - Fix exports using the built-in Transformers NemotronH implementation retaining incompatible legacy remote-code config and model mappings. Re-export affected checkpoints before deployment. - Fix INT8 real quantization (``mtq.compress``) of FP16 weights zeroing or clipping channels with a small amax: their scales underflowed in FP16. Scales of newly compressed INT8 weights are now stored in FP32. - Fix Hugging Face exports classifying registered Qwen VLM parameters as unplaced source weights, which overwrote quantized tensors with original weights and incorrectly excluded their modules from quantization. Re-export affected checkpoints. From 930d87bdd3d502562a5113b5ad91ed82c705ee65 Mon Sep 17 00:00:00 2001 From: anmaurya001 Date: Sat, 17 Oct 2026 12:07:26 +0530 Subject: [PATCH 3/4] Update Windows ARM64 installation to fixed ONNX release Signed-off-by: anmaurya001 --- .../getting_started/windows/_installation_windows_arm64.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/getting_started/windows/_installation_windows_arm64.rst b/docs/source/getting_started/windows/_installation_windows_arm64.rst index 2bafcf0be4e..e50f039a303 100644 --- a/docs/source/getting_started/windows/_installation_windows_arm64.rst +++ b/docs/source/getting_started/windows/_installation_windows_arm64.rst @@ -101,7 +101,7 @@ explicit dependency installation avoids selecting the Windows x64 ``onnxruntime- & $PythonExe -m pip install ` cppimport cupy-cuda13x lief ml_dtypes ` - "onnx~=1.21.0" "onnx-graphsurgeon>=0.6.1" ` + "onnx~=1.23.2" "onnx-graphsurgeon>=0.6.1" ` "onnxconverter-common~=1.16.0" onnxscript ` "onnxslim>=0.1.76" "polygraphy>=0.49.22" ` "onnxruntime>=1.24.2" onnxruntime-ep-nv-tensorrt-rtx-cu13 From 9103d576f87089bd290895c243e871616e34946c Mon Sep 17 00:00:00 2001 From: anmaurya001 Date: Fri, 23 Oct 2026 10:32:49 +0530 Subject: [PATCH 4/4] Scope fixed ONNX dependency upgrade to Windows Signed-off-by: anmaurya001 --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index fae0d41f5f1..76633859e3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,8 @@ onnx = [ "lief", "ml_dtypes", "onnx-graphsurgeon>=0.6.1", - "onnx~=1.23.2", + "onnx~=1.21.0; platform_system != 'Windows'", + "onnx~=1.23.2; platform_system == 'Windows'", "onnxconverter-common~=1.16.0", # Python 3.10 support for ModelOpt ONNX is deprecated and will be removed in a future release. # Native Windows ARM64 does not support ModelOpt ONNX on Python 3.10.