Skip to content

Conversation

@vraspar
Copy link
Contributor

@vraspar vraspar commented Dec 18, 2025

Description

This is first PR towards adding 2 bit support to ORT

I will create follow up PRs to

  • Add CPU operators (CAST, QDQ, non compute ops)

Motivation and Context

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.

@vraspar vraspar requested a review from Copilot January 13, 2026 19:07
@vraspar vraspar marked this pull request as ready for review January 13, 2026 19:08
Copy link
Contributor

Copilot AI left a comment

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 adds foundational support for 2-bit integer types (INT2/UINT2) to ONNX Runtime, following the ONNX 1.20 specification. It introduces type definitions, registration, and utilities but does not yet include CPU operators (which are planned for follow-up PRs).

Changes:

  • Introduces Int2x4 and UInt2x4 types for packing 4 two-bit values into a single byte
  • Registers INT2/UINT2 types throughout the runtime's type system and provider bridge
  • Adds comprehensive unit tests for the new 2-bit types

Reviewed changes

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

Show a summary per file
File Description
include/onnxruntime/core/framework/int2.h Core implementation of Int2x4/UInt2x4 classes with pack/unpack utilities
include/onnxruntime/core/session/onnxruntime_c_api.h Adds UINT2/INT2 enum values to public C API
onnxruntime/core/framework/data_types.cc Registers INT2/UINT2 tensor types and adds them to type lists
onnxruntime/core/framework/element_type_lists.h Adds AllIRv13 type list including Int2x4/UInt2x4
onnxruntime/core/framework/tensorprotoutils.cc Implements tensor proto serialization/deserialization for INT2/UINT2
onnxruntime/core/providers/shared_library/* Adds provider bridge support for INT2/UINT2 types
onnxruntime/test/framework/int2_test.cc Comprehensive unit tests for Int2x4/UInt2x4 functionality
onnxruntime/test/util/compare_ortvalue.cc Adds comparison logic for INT2/UINT2 test outputs
onnxruntime/test/unittest_util/checkers.cc Adds tensor checking utilities for INT2/UINT2
onnxruntime/test/onnx/tensorprotoutils.cc Adds test utilities for unpacking INT2/UINT2 tensors
Various other files Updates type dispatch macros and utilities to include INT2/UINT2

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

ORT_CXX_API_THROW("p_data == nullptr, but size != 0", OrtErrorCode::ORT_INVALID_ARGUMENT); \
} \
if (ONNX_NAMESPACE::ONNX_TYPE != tensor.data_type()) { \
ORT_CXX_API_THROW("TensorProto data type is not INT2", OrtErrorCode::ORT_INVALID_ARGUMENT); \
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The error message is imprecise. It should specify whether the expected type is INT2 or UINT2 to match the specific type being unpacked. Consider making this error message generic (e.g., 'TensorProto data type does not match expected type') or using a parameter to specify the exact type.

Copilot uses AI. Check for mistakes.
UInt2x4,
Int2x4>;

// TODO: This needs upgrade to some newer version ,buit it has been
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

Corrected spelling of 'buit' to 'but'.

Suggested change
// TODO: This needs upgrade to some newer version ,buit it has been
// TODO: This needs upgrade to some newer version ,but it has been

Copilot uses AI. Check for mistakes.
@vraspar vraspar requested a review from jambayk January 13, 2026 19:12
@vraspar vraspar force-pushed the vraspar/int2-support branch from 814dce8 to 5d82d3c Compare January 14, 2026 18:13
@justinchuby justinchuby added this to the 1.24.0 milestone Jan 14, 2026
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.

5 participants