Skip to content

Conversation

Copy link

Copilot AI commented Nov 10, 2025

Add support for UINT2/INT2 data types

Following the pattern from PR onnx#128 (FLOAT8E8M0 support), this PR adds comprehensive support for INT2/UINT2 data types that were added to ONNX in PR #7446.

Changes Made:

  • Add INT2 and UINT2 enum values to _enums.py (values 25 and 26)
  • Add numpy type mappings for ml_dtypes.int2 and ml_dtypes.uint2
  • Add type properties (bitwidth=2, signed/unsigned, integer type)
  • Add short names ("i2" and "u2")
  • Update _core.py to handle INT2/UINT2 in packed tensor lists and numpy view functions
  • Add pack_2bitx4 and unpack_2bitx4 functions in _type_casting.py for 2-bit packing
  • Update serde.py to include INT2/UINT2 in serialization sets and handle 2-bit unpacking
  • Update tensor_adapters.py for torch tensor support (mappings added, but tests excluded as PyTorch doesn't support creating tensors with these types yet)
  • Add comprehensive tests in _core_test.py, _enums_test.py, serde_test.py
  • Update PackedTensor to support 2-bit types alongside 4-bit types
  • Update tensors.md documentation to include INT2/UINT2
  • All tests passing

Testing:

All existing tests pass, and new tests have been added to verify:

  • Enum values and type properties
  • Numpy type conversions
  • Tensor creation and serialization
  • Pack/unpack operations for 2-bit data
  • Torch dtype mappings (though PyTorch doesn't yet support creating tensors with these types)
  • Serde round-trip operations

Notes:

  • While PyTorch has torch.int2 and torch.uint2 dtype definitions, it doesn't support creating tensors with these types yet, so torch tensor tests are excluded
  • The tensor_adapters.py file includes the mappings for future compatibility when PyTorch adds full support
Original prompt

Helpe me create PR for this issue: onnx#250


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix handling of TensorAttributes in ONNX IR Add support for UINT2/INT2 data types Nov 10, 2025
Copilot AI requested a review from vraspar November 10, 2025 22:12
@vraspar
Copy link
Owner

vraspar commented Dec 15, 2025

@copilot Do i need to add anything to tensors.md to support int2/uint2

Copy link
Author

Copilot AI commented Dec 15, 2025

@copilot Do i need to add anything to tensors.md to support int2/uint2

Yes, I've updated the documentation in tensors.md to include INT2/UINT2. The changes are in commit aabcb44:

  • Updated the section title to include "int2"
  • Added [U]INT2 to the list of non-native NumPy dtypes
  • Updated the unpacking note to include uint2/int2
  • Updated initialization constraints to include int2 and uint2

This follows the same documentation pattern used for INT4/UINT4.

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.

3 participants