Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linux_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
dockerfile_path: tools/ci_build/github/linux/docker/Dockerfile.manylinux2_28_cpu
docker_image_repo: onnxruntimecpubuildpythonx64
# MATERIALIZE=ON needs no explicit pre-build pip install on this leg: the manylinux cp314
# image already ships onnx==1.22.0 + numpy==2.4.2 (the exact gate pins) via its
# image already ships the pinned onnx + numpy versions via its
# requirements.txt (install_deps.sh installs it into cp311-cp314). Intentional, not an
# omission -- unlike the QNN/android legs which run on bare agents and pip-install the pins.
extra_build_flags: '--use_binskim_compliant_compile_flags --build_wheel --build_nuget --enable_transformers_tool_test --cmake_extra_defines onnxruntime_BUILD_BENCHMARKS=ON --cmake_extra_defines onnxruntime_MATERIALIZE_ONNX_NODE_TESTS=ON'
Expand Down
7 changes: 3 additions & 4 deletions cmake/deps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ microsoft_gsl;https://github.com/microsoft/GSL/archive/refs/tags/v4.2.1.zip;1094
microsoft_wil;https://github.com/microsoft/wil/archive/refs/tags/v1.0.250325.1.zip;826c8bd47c2258ec61b8b218e031e5b33d27f761
mimalloc;https://github.com/microsoft/mimalloc/archive/refs/tags/v2.1.1.zip;d5ee7d34223d0567892db5179849939c8769dc41
mp11;https://github.com/boostorg/mp11/archive/refs/tags/boost-1.82.0.zip;9bc9e01dffb64d9e0773b2e44d2f22c51aace063
# ONNX pinned to the 1.22.0 final release (tag v1.22.0). rc2->final changed only CI
# workflow yml + VERSION_NUMBER (no operator-schema, opset, or testdata change), so it is
# pure version plumbing. The 7 CI requirements.txt files are pinned to onnx==1.22.0 (now on PyPI).
onnx;https://github.com/onnx/onnx/archive/refs/tags/v1.22.0.zip;2b2cd58ac7a26df5371266149e0c76776330cdf1
# ONNX 1.23.2 final release (opset 28).
# The 7 CI requirements.txt files are pinned to onnx==1.23.2.
onnx;https://github.com/onnx/onnx/archive/refs/tags/v1.23.2.zip;8846de32ab45e653c2cd651d8d6c4c299fb1583d
# Use the latest commit of 10.9-GA
onnx_tensorrt;https://github.com/onnx/onnx-tensorrt/archive/d5dce67db7c2e64b07e055571f5ec06f7f254de2.zip;01114d3b67650857281fa50faa2e412130a63b69
protobuf;https://github.com/protocolbuffers/protobuf/releases/download/v33.6/protobuf-33.6.tar.gz;051fee744fcca04dab37eb009d49aa3e9546acda
Expand Down
2 changes: 1 addition & 1 deletion cmake/external/onnx
Submodule onnx updated 8207 files
36 changes: 12 additions & 24 deletions cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1942,13 +1942,13 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
# coverage gap this feature exists to close.
# ---------------------------------------------------------------------------
if (onnxruntime_MATERIALIZE_ONNX_NODE_TESTS AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
# onnx version pin: derive from the archive URL in cmake/deps.txt (single source of truth).
string(REGEX MATCH "v([0-9]+\\.[0-9]+\\.[0-9]+)" _onnx_url_ver "${DEP_URL_onnx}")
# Derive the expected wheel version from the archive URL so this also works with installed ONNX packages.
string(REGEX MATCH "v([0-9]+\\.[0-9]+\\.[0-9]+)" _onnx_url_version "${DEP_URL_onnx}")
if(CMAKE_MATCH_1)
set(_onnx_pinned_version ${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Could not parse the pinned onnx version from DEP_URL_onnx='${DEP_URL_onnx}' "
"(expected a vX.Y.Z tag). Fix cmake/deps.txt or this regex.")
message(FATAL_ERROR "Could not parse the pinned ONNX version from DEP_URL_onnx='${DEP_URL_onnx}' "
"(expected a vX.Y.Z tag). Fix cmake/deps.txt or this parser.")
endif()

# Python interpreter is not guaranteed for static test-only builds (the top-level
Expand Down Expand Up @@ -1976,27 +1976,10 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
" OR reconfigure with -Donnxruntime_MATERIALIZE_ONNX_NODE_TESTS=OFF (node-test coverage will be dropped).\n"
" Details: ${_onnx_err}")
endif()
# onnx version gate: HARD FAIL on a genuine mismatch, but RC / pre-release AWARE.
# ONNX's opset-bump workflow ships wheels like 1.23.0rc1 or 1.23.0.dev20240101 whose
# COMPILED opset registry already matches the formal 1.23.0 tag, so we compare on the
# RELEASE BASE (major.minor.micro) rather than the raw string. This mirrors
# materialize_onnx_node_tests.py::_release_base EXACTLY (regex ^(\d+)\.(\d+)\.(\d+), with a
# raw-string fallback when there is no leading X.Y.Z) so the cmake and Python layers agree:
# an rcN/.devN wheel of the pinned tag passes, while a real major/minor/micro mismatch
# (e.g. 1.21.x, or 1.23.0 when pinned at 1.22.0) still FATALs. Both sides are normalized;
# _onnx_pinned_version is already a clean X.Y.Z (parsed from the deps.txt vX.Y.Z tag), so
# normalizing it is a no-op kept only for symmetry with the Python two-sided compare.
string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" _onnx_ver_base "${_onnx_ver}")
if(_onnx_ver_base STREQUAL "")
set(_onnx_ver_base "${_onnx_ver}")
endif()
string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" _onnx_pin_base "${_onnx_pinned_version}")
if(_onnx_pin_base STREQUAL "")
set(_onnx_pin_base "${_onnx_pinned_version}")
endif()
if(NOT _onnx_ver_base STREQUAL _onnx_pin_base)
# The source and wheel are both final releases, so require exact version parity.
if(NOT _onnx_ver STREQUAL _onnx_pinned_version)
message(FATAL_ERROR
"onnx ${_onnx_ver} (release base ${_onnx_ver_base}) != pinned ${_onnx_pinned_version} "
"onnx ${_onnx_ver} != pinned ${_onnx_pinned_version} "
"(cmake/deps.txt). A mismatched wheel bakes the wrong opset/IR into the materialized "
"corpus (silent drift).\n"
" Fix: pip install onnx==${_onnx_pinned_version}")
Expand Down Expand Up @@ -2074,6 +2057,11 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
VERBATIM)
add_custom_target(onnx_node_tests_materialized ALL
DEPENDS ${_materialized_node_root}/.stamp)
# Keep the corpus available for targeted onnx_test_runner builds as well as
# normal ALL builds. The runner is the direct C++ consumer of this artifact.
if(TARGET onnx_test_runner)
add_dependencies(onnx_test_runner onnx_node_tests_materialized)
endif()

if (NOT onnxruntime_REDUCED_OPS_BUILD)
# First-class ctest over the materialized node corpus (the durable replacement for the
Expand Down
215 changes: 68 additions & 147 deletions cmake/patches/onnx/onnx.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 791e24b..5f861a1 100644
index 6f1d56949..7e6331dec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,6 +46,7 @@ option(ONNX_DISABLE_EXCEPTIONS "Disable exception handling." OFF)
@@ -53,6 +53,7 @@ option(ONNX_DISABLE_EXCEPTIONS "Disable exception handling." OFF)
option(ONNX_DISABLE_STATIC_REGISTRATION "Disable static registration for ONNX operator schemas." OFF)
option(ONNX_USE_UNITY_BUILD "Enable Unity (Jumbo) build for" OFF)
option(ONNX_PYODIDE_BUILD "Build ONNX for Pyodide/Emscripten (wasm32)." OFF)
+option(ONNX_MINIMAL_BUILD "Build only essential ONNX components" OFF)
option(ONNX_INSTALL "Install ONNX targets, headers, and CMake config files" ON)
if(WIN32)
option(ONNX_USE_MSVC_STATIC_RUNTIME "Build with MSVC static runtime. Ignored if CMAKE_MSVC_RUNTIME_LIBRARY is defined." OFF)
@@ -515,7 +516,22 @@ add_dependencies(onnx_proto onnx_proto_gen)
@@ -562,7 +563,23 @@ add_dependencies(onnx_proto onnx_proto_headers)
# Core library. Hand-written sources come from target_sources(onnx ...) in the
# subdirectories; the protobuf objects are pulled in from onnx_proto.
add_library(onnx $<TARGET_OBJECTS:onnx_proto>)
Expand All @@ -22,6 +22,7 @@ index 791e24b..5f861a1 100644
+ # the full operator/schema sources via add_subdirectory(onnx).
+ target_sources(onnx PRIVATE
+ "${ONNX_ROOT}/onnx/defs/data_type_utils.cc"
+ "${ONNX_ROOT}/onnx/defs/doc_strings.cc"
+ )
+ # Ensure ONNX_ML is treated as ON for minimal build consistency with ORT's file
+ set(ONNX_ML ON CACHE BOOL "Enable traditional ML API." FORCE)
Expand All @@ -34,158 +35,78 @@ index 791e24b..5f861a1 100644
add_dependencies(onnx onnx_proto)
set_target_properties(onnx PROPERTIES CXX_VISIBILITY_PRESET hidden)
add_onnx_global_defines(onnx)
diff --git a/onnx/defs/doc_strings.cc b/onnx/defs/doc_strings.cc
index 976280392..8c22e55ff 100644
--- a/onnx/defs/doc_strings.cc
+++ b/onnx/defs/doc_strings.cc
@@ -1705,6 +1705,8 @@ const char kDoc_DequantizeLinear_ver24[] = "";
const char kDoc_RandomNormal_ver1[] = "";
const char kDoc_Round_ver11[] = "";
const char kDoc_SpaceToDepth_ver1[] = "";
+const char kDoc_SpaceToDepth_ver28[] = "";
+const char kDoc_DepthToSpace_ver28[] = "";
const char kDoc_InstanceNormalization_ver6[] = "";
const char kDoc_ThresholdedRelu_ver10[] = "";
const char kDoc_Acosh_ver9[] = "";
diff --git a/onnx/defs/nn/defs.cc b/onnx/defs/nn/defs.cc
index 4b58256e6..1a8103e7c 100644
--- a/onnx/defs/nn/defs.cc
+++ b/onnx/defs/nn/defs.cc
@@ -2692,7 +2692,7 @@ ONNX_OPERATOR_SET_SCHEMA(
// positive value.
axis += input_ndim;
}
- if (axis < 0) {
+ if (axis < 0 || axis >= input_ndim) {
fail_shape_inference(
"Unexpected axis value (",
axis,
diff --git a/onnx/defs/nn/old.cc b/onnx/defs/nn/old.cc
index 3887169..8432613 100644
index cbb1532c0..6597a2ef9 100644
--- a/onnx/defs/nn/old.cc
+++ b/onnx/defs/nn/old.cc
@@ -4078,7 +4078,6 @@ ONNX_OPERATOR_SET_SCHEMA(
@@ -4118,7 +4118,6 @@ ONNX_OPERATOR_SET_SCHEMA(
GroupNormalization,
18,
OpSchema()
- .Deprecate()
.SetDoc(GroupNormalization_ver18_doc)
.Attr("epsilon", "The epsilon value to use to avoid division by zero.", AttributeProto::FLOAT, 1e-5f)
.Attr(
diff --git a/onnx/defs/nn/defs.cc b/onnx/defs/nn/defs.cc
index 0c271d5..6d64da7 100644
--- a/onnx/defs/nn/defs.cc
+++ b/onnx/defs/nn/defs.cc
@@ -2670,7 +2670,7 @@ ONNX_OPERATOR_SET_SCHEMA(
// positive value.
axis += input_ndim;
}
- if (axis < 0) {
+ if (axis < 0 || axis >= input_ndim) {
fail_shape_inference(
"Unexpected axis value (",
axis,
diff --git a/onnx/common/assertions.h b/onnx/common/assertions.h
--- a/onnx/common/assertions.h
+++ b/onnx/common/assertions.h
@@ -27,9 +27,9 @@
#endif
std::string barf(const char* fmt, ...);

-[[noreturn]] void throw_assert_error(std::string& /*msg*/);
+[[noreturn]] void throw_assert_error(const std::string& /*msg*/);

-[[noreturn]] void throw_tensor_error(std::string& /*msg*/);
+[[noreturn]] void throw_tensor_error(const std::string& /*msg*/);

} // namespace ONNX_NAMESPACE

diff --git a/onnx/common/assertions.cc b/onnx/common/assertions.cc
--- a/onnx/common/assertions.cc
+++ b/onnx/common/assertions.cc
@@ -42,11 +42,11 @@
}

-void throw_assert_error(std::string& msg) {
+void throw_assert_error(const std::string& msg) {
ONNX_THROW_EX(assert_error(msg));
}

-void throw_tensor_error(std::string& msg) {
+void throw_tensor_error(const std::string& msg) {
ONNX_THROW_EX(tensor_error(msg));
diff --git a/onnx/defs/printer.cc b/onnx/defs/printer.cc
index 1d43bccb0..b6beed6f3 100644
--- a/onnx/defs/printer.cc
+++ b/onnx/defs/printer.cc
@@ -9,6 +9,9 @@
#include <cmath>
#include <cstdint>
#include <iomanip>
+#include <limits>
+#include <locale>
+#include <sstream>
#include <string>
#include <type_traits>
#include <vector>
@@ -31,6 +34,14 @@ std::vector<Widened> ParseRawIntData(const TensorProto& tensor) {
// point, the shortest form that round-trips through the parser.
template <typename T>
void PrintNumber(std::ostream& os, T value) {
+#if defined(__APPLE__) && defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
+ __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160300
+ // std::to_chars is unavailable when targeting iOS releases before 16.3.
+ std::ostringstream value_stream;
+ value_stream.imbue(std::locale::classic());
+ value_stream << std::setprecision(std::numeric_limits<T>::max_digits10) << value;
+ os << value_stream.str();
+#else
if constexpr (std::is_floating_point_v<T>) {
// Normalize NaN: MSVC's to_chars emits payload forms like "nan(ind)"
// that the parser does not accept.
@@ -42,6 +53,7 @@ void PrintNumber(std::ostream& os, T value) {
std::array<char, 32> buf{};
const auto res = std::to_chars(buf.data(), buf.data() + buf.size(), value);
os.write(buf.data(), res.ptr - buf.data());
+#endif
}

} // namespace ONNX_NAMESPACE
diff --git a/onnx/common/tensor.h b/onnx/common/tensor.h
--- a/onnx/common/tensor.h
+++ b/onnx/common/tensor.h
@@ -51,13 +51,13 @@
/// size_from_dim() cannot handle this case, while elem_num() handles it correctly
int64_t elem_num() const {
- return safe_dim_product(sizes_, [](const char* msg) { throw tensor_error(msg); });
+ return safe_dim_product(sizes_, [](const char* msg) { throw_tensor_error(msg); });
}
int64_t size_from_dim(int dim) const {
if (dim < 0) {
dim += static_cast<int>(sizes_.size());
}
ONNX_ASSERT(dim >= 0 && (size_t)dim < sizes_.size())
- return safe_dim_product(sizes_.begin() + dim, sizes_.end(), [](const char* msg) { throw tensor_error(msg); });
+ return safe_dim_product(sizes_.begin() + dim, sizes_.end(), [](const char* msg) { throw_tensor_error(msg); });
}

int32_t elem_type() const {
diff --git a/onnx/common/scoped_resource.h b/onnx/common/scoped_resource.h
--- a/onnx/common/scoped_resource.h
+++ b/onnx/common/scoped_resource.h
@@ -25,18 +25,18 @@
// Usage:
-// using ScopedFd = ScopedResource<-1, close_fd>;
-// ScopedFd guard(fd); // destructor calls close_fd(fd)
+// using ScopedFd = ScopedResource<FdTraits>;
+// ScopedFd guard(fd); // destructor calls FdTraits::close(fd)
// int raw = guard.release(); // relinquish ownership
-template <auto Invalid, void (*Close)(decltype(Invalid))>
+template <typename Traits>
class ScopedResource {
- using T = decltype(Invalid);
+ using T = typename Traits::type;
T val_;

public:
explicit ScopedResource(T v) : val_(v) {}
~ScopedResource() {
- if (val_ != Invalid) {
- Close(val_);
+ if (val_ != Traits::invalid()) {
+ Traits::close(val_);
}
}
T get() const {
return val_;
@@ -44,7 +44,7 @@
}
T release() {
T tmp = val_;
- val_ = Invalid;
+ val_ = Traits::invalid();
return tmp;
}
ScopedResource(const ScopedResource&) = delete;
@@ -55,20 +55,32 @@
#ifdef _WIN32
-inline void close_handle(HANDLE h) {
- CloseHandle(h);
-}
-using ScopedHandle = ScopedResource<INVALID_HANDLE_VALUE, close_handle>;
+struct HandleTraits {
+ using type = HANDLE;
+ static HANDLE invalid() {
+ return INVALID_HANDLE_VALUE;
+ }
+ static void close(HANDLE h) {
+ CloseHandle(h);
+ }
+};
+using ScopedHandle = ScopedResource<HandleTraits>;
#endif

-inline void close_fd(int fd) {
+struct FdTraits {
+ using type = int;
+ static constexpr int invalid() {
+ return -1;
+ }
+ static void close(int fd) {
#ifdef _WIN32
- _close(fd);
+ _close(fd);
#else
- close(fd);
+ ::close(fd);
#endif
-}
-using ScopedFd = ScopedResource<-1, close_fd>;
+ }
+};
+using ScopedFd = ScopedResource<FdTraits>;

// RAII guard that invokes a callable on destruction (scope exit).
template <typename F>
class ScopeExit {
F fn_;

bool IsValidIdentifier(const std::string& str) {
Loading
Loading