Skip to content

Conversation

@snnn
Copy link
Member

@snnn snnn commented Oct 22, 2025

Description

This PR adds support for int8, uint8, int16, and uint16 data types to the Max and Min operators for opset 12 and later, resolving issue #26382.

Issue

Fixes #26382

Users encountered the error Could not find an implementation for Max(13) node with name '_0' when trying to use Max or Min operators with int8 or uint8 data types, even though these types are required by the ONNX specification for opset 12+.

Changes

Core Implementation (onnxruntime/core/providers/cpu/math/element_wise_ops.cc)

  1. Updated type registration for Max and Min opset 12: Added int8_t, int16_t, uint8_t, and uint16_t to the supported type lists
  2. Updated type dispatchers: Modified Min_8::Compute and Max_8::Compute to dispatch to implementations for the new types

Tests (onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc)

Added comprehensive unit tests for all new data types:

  • Max_12_Int8, Max_12_UInt8, Max_12_Int16, Max_12_UInt16
  • Min_12_Int8, Min_12_UInt8, Min_12_Int16, Min_12_UInt16

Each test verifies:

  • Element-wise operations
  • Broadcasting functionality
  • Multiple input handling
  • Appropriate value ranges for each type

Technical Details

  • The existing Eigen-based implementation already handles all numeric types generically
  • No changes to computation logic were needed
  • Only type registration and dispatching were updated
  • Changes follow existing code patterns in the codebase

ONNX Specification Compliance

This implementation now fully complies with the ONNX specification for Max and Min operators at opset 12+, which requires support for:

  • tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64)
  • tensor(int8), tensor(int16), tensor(int32), tensor(int64)
  • tensor(float16), tensor(float), tensor(double), tensor(bfloat16)

Impact

  • ✅ Enables int8/uint8 quantized models using Max/Min operators
  • ✅ Improves ONNX specification compliance
  • ✅ Fully backward compatible
  • ✅ No breaking changes or performance impact

Testing

./onnxruntime_test_all --gtest_filter="MathOpTest.Max_12_*8*:MathOpTest.Min_12_*8*:MathOpTest.Max_12_*16*:MathOpTest.Min_12_*16*"

Checklist

@snnn
Copy link
Member Author

snnn commented Oct 22, 2025

This PR was created by Github Copilot CLI. I am trying to use it demonstrate how to use Github Copilot to speed up our work.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

You can commit the suggested changes from lintrunner.

Fixes #26382

This commit adds support for int8, uint8, int16, and uint16 data types
to the Max and Min operators for opset 12 and later, bringing the
implementation into compliance with the ONNX specification.

Changes:
- Updated type registration for Max and Min operators (opset 12+)
- Updated type dispatchers in Min_8::Compute and Max_8::Compute
- Added comprehensive unit tests for all new data types

The existing Eigen-based implementation already handles all numeric
types generically, so only type registration and dispatching needed
updates. This change is fully backward compatible.
@skottmckay
Copy link
Contributor

Do any real models need the 16-bit types? Typically we only add required types to keep binary size growth minimal.

@snnn
Copy link
Member Author

snnn commented Oct 24, 2025

@Honry , could you help answer this question?

@Honry
Copy link
Contributor

Honry commented Oct 24, 2025

The issue is captured when I tested Max and Min unit tests of 8-bit types with WebNN EP.

@skottmckay, Do you specify the non-necessity of supporting 16-bit types? That'd be fine to me.

@snnn
Copy link
Member Author

snnn commented Oct 24, 2025

@skottmckay, we have a pipeline to monitor binary size, and there is no change for Android minimal build's binary size. There should be some increases in the default build, but it should be fine?

@skottmckay
Copy link
Contributor

it's still code that we have to test and maintain, and if there's no real usage of it that seems to be of limited value.

Gemini added 2 commits October 27, 2025 13:40
Address review feedback from skottmckay: remove int16/uint16 types as they
are not commonly used in real models. Keep only int8/uint8 support which
was the original requirement from the WebNN EP testing.

Changes:
- Removed int16_t and uint16_t from type registration for Max/Min opset 12
- Removed int16_t and uint16_t from MLTypeCallDispatcher in Compute methods
- Removed all int16/uint16 test cases (4 tests removed)
- Updated documentation to reflect supported types

The change reduces code maintenance burden while still providing the
necessary int8/uint8 support for quantized models.
@snnn snnn changed the title Add int8/uint8/int16/uint16 support for Max and Min operators Add int8/uint8 support for Max and Min operators Oct 27, 2025
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.

Support int8 and uint8 data types for Max and Min

4 participants