Skip to content

Fix bugs with handling subbyte types#45

Merged
justinchuby merged 4 commits intomainfrom
bug-fix
Jan 13, 2026
Merged

Fix bugs with handling subbyte types#45
justinchuby merged 4 commits intomainfrom
bug-fix

Conversation

@justinchuby
Copy link
Copy Markdown
Owner

@justinchuby justinchuby commented Jan 13, 2026

Support 2bit types.

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 13, 2026

Codecov Report

❌ Patch coverage is 88.63636% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.85%. Comparing base (5488053) to head (c67d598).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/onnx_safetensors/_safetensors_io.py 88.50% 4 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #45      +/-   ##
==========================================
+ Coverage   68.60%   70.85%   +2.25%     
==========================================
  Files           6        6              
  Lines         379      374       -5     
  Branches       64       57       -7     
==========================================
+ Hits          260      265       +5     
+ Misses         96       92       -4     
+ Partials       23       17       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby justinchuby merged commit 7d7cfa4 into main Jan 13, 2026
13 checks passed
@justinchuby justinchuby deleted the bug-fix branch January 13, 2026 20:40
Copy link
Copy Markdown
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 pull request fixes bugs related to handling sub-byte data types in the onnx-safetensors library. The changes improve support for 2-bit, 4-bit, and other specialized numeric types.

Changes:

  • Added support for new data types (INT2, UINT2, FLOAT4E2M1, FLOAT8E8M0, COMPLEX64) with proper safetensors mappings
  • Simplified sub-byte type handling by using tensor.nbytes and tensor.dtype.bitwidth instead of custom helper functions
  • Fixed struct unpacking format for reading safetensors headers from "i" (4-byte) to "<Q" (8-byte unsigned long long)
  • Refactored save_file to eliminate code duplication and improve maintainability
  • Updated save_model to restore original tensor values after saving, avoiding side effects on the input model
  • Removed unused math and tqdm imports

Reviewed changes

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

File Description
src/onnx_safetensors/_safetensors_io.py Core changes for sub-byte type handling, dtype mappings, header reading fix, and code refactoring
src/onnx_safetensors/init.py Version change from 1.5.0 to 1.4.1

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

Comment thread src/onnx_safetensors/_safetensors_io.py
Comment thread src/onnx_safetensors/_safetensors_io.py
Comment on lines +443 to +451
values_to_save: list[ir.Value] = []
for value in initialized_values:
tensor = value.const_value
assert tensor is not None
if tensor.nbytes < size_threshold_bytes:
continue
tensors_to_save.append(tensor)
values_to_save.append(value)

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 variable values_to_save is populated but never used in the function. It should either be used for its intended purpose or removed to avoid confusion.

Suggested change
values_to_save: list[ir.Value] = []
for value in initialized_values:
tensor = value.const_value
assert tensor is not None
if tensor.nbytes < size_threshold_bytes:
continue
tensors_to_save.append(tensor)
values_to_save.append(value)
for value in initialized_values:
tensor = value.const_value
assert tensor is not None
if tensor.nbytes < size_threshold_bytes:
continue
tensors_to_save.append(tensor)

Copilot uses AI. Check for mistakes.
)

__version__ = "1.5.0"
__version__ = "1.4.1"
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 version is being changed from 1.5.0 to 1.4.1, which is a downgrade. Typically, bug fixes should increment the patch version (e.g., 1.5.0 to 1.5.1) rather than downgrade to a previous version. This could cause confusion with package versioning and updates.

Suggested change
__version__ = "1.4.1"
__version__ = "1.5.1"

Copilot uses AI. Check for mistakes.
Comment thread src/onnx_safetensors/_safetensors_io.py
Comment thread src/onnx_safetensors/_safetensors_io.py
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.

2 participants