Skip to content

PackedTensor #2258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

PackedTensor #2258

wants to merge 4 commits into from

Conversation

justinchuby
Copy link
Collaborator

@justinchuby justinchuby commented May 1, 2025

Fix #2250

Copy link

codecov bot commented May 1, 2025

❌ 3 Tests Failed:

Tests completed Failed Passed Skipped
14460 3 14457 1879
View the top 3 failed test(s) by shortest run time
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0393_test_gather_negative_indices
Stack Traces | 0.003s run time
onnxscript\backend\onnx_export_test.py:137: in extract_functions
    mod = importlib.import_module(import_name)
C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.onnx_backend_test_code.test_gather_negative_indices'

The above exception was the direct cause of the following exception:
.nox\test\lib\site-packages\parameterized\parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
onnxscript\backend\onnx_export_test.py:271: in test_export2python_produces_correct_onnx_script_model
    functions = extract_functions(backend_test.name, code, self.test_folder)
onnxscript\backend\onnx_export_test.py:139: in extract_functions
    raise AssertionError(
E   AssertionError: Unable to import 'tests.onnx_backend_test_code.test_gather_negative_indices' (e=No module named 'tests.onnx_backend_test_code.test_gather_negative_indices') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_gather_negative_indices.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_gather_negative_indices.py', current folder: D:\a\onnxscript\onnxscript
E   ---- CONTENT --
E   import numpy
E   from onnx import TensorProto
E   from onnx.helper import make_tensor
E   from onnxscript import script, external_tensor
E   from onnxscript.values import Opset
E   from onnxscript.onnx_types import FLOAT, INT64
E   from onnxscript.onnx_opset import opset13
E   
E   @script()
E   def bck_test_gather_negative_indices(data: FLOAT[10], indices: INT64[3]) -> (FLOAT[3]):
E       y = opset13.Gather(data, indices, axis=0)
E       return y
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0309_test_cumsum_2d_negative_axis
Stack Traces | 0.004s run time
onnxscript\backend\onnx_export_test.py:137: in extract_functions
    mod = importlib.import_module(import_name)
C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.onnx_backend_test_code.test_cumsum_2d_negative_axis'

The above exception was the direct cause of the following exception:
.nox\test\lib\site-packages\parameterized\parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
onnxscript\backend\onnx_export_test.py:271: in test_export2python_produces_correct_onnx_script_model
    functions = extract_functions(backend_test.name, code, self.test_folder)
onnxscript\backend\onnx_export_test.py:139: in extract_functions
    raise AssertionError(
E   AssertionError: Unable to import 'tests.onnx_backend_test_code.test_cumsum_2d_negative_axis' (e=No module named 'tests.onnx_backend_test_code.test_cumsum_2d_negative_axis') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_cumsum_2d_negative_axis.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_cumsum_2d_negative_axis.py', current folder: D:\a\onnxscript\onnxscript
E   ---- CONTENT --
E   import numpy
E   from onnx import TensorProto
E   from onnx.helper import make_tensor
E   from onnxscript import script, external_tensor
E   from onnxscript.values import Opset
E   from onnxscript.onnx_types import DOUBLE, INT32
E   from onnxscript.onnx_opset import opset14
E   
E   @script()
E   def bck_test_cumsum_2d_negative_axis(x: DOUBLE[2,3], axis: INT32) -> (DOUBLE[2,3]):
E       y = opset14.CumSum(x, axis)
E       return y
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0981_test_resize_upsample_sizes_nearest_axes_3_2
Stack Traces | 0.004s run time
onnxscript\backend\onnx_export_test.py:137: in extract_functions
    mod = importlib.import_module(import_name)
C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.onnx_backend_test_code.test_resize_upsample_sizes_nearest_axes_3_2'

The above exception was the direct cause of the following exception:
.nox\test\lib\site-packages\parameterized\parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
onnxscript\backend\onnx_export_test.py:271: in test_export2python_produces_correct_onnx_script_model
    functions = extract_functions(backend_test.name, code, self.test_folder)
onnxscript\backend\onnx_export_test.py:139: in extract_functions
    raise AssertionError(
E   AssertionError: Unable to import 'tests.onnx_backend_test_code.test_resize_upsample_sizes_nearest_axes_3_2' (e=No module named 'tests.onnx_backend_test_code.test_resize_upsample_sizes_nearest_axes_3_2') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_resize_upsample_sizes_nearest_axes_3_2.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_resize_upsample_sizes_nearest_axes_3_2.py', current folder: D:\a\onnxscript\onnxscript
E   ---- CONTENT --
E   import numpy
E   from onnx import TensorProto
E   from onnx.helper import make_tensor
E   from onnxscript import script, external_tensor
E   from onnxscript.values import Opset
E   from onnxscript.onnx_types import FLOAT, INT64
E   from onnxscript.onnx_opset import opset19
E   
E   @script()
E   def bck_test_resize_upsample_sizes_nearest_axes_3_2(X: FLOAT[1,1,2,2], sizes: INT64[2]) -> (FLOAT[1,1,7,8]):
E       Y = opset19.Resize(X, None, None, sizes, axes=[3, 2], mode='nearest')
E       return Y

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

wip

Verified

This commit was signed with the committer’s verified signature.
zymap Yong Zhang
@justinchuby justinchuby force-pushed the justinchu/packed-tensor branch from 01d6a50 to 6ae4ed2 Compare May 1, 2025 19:01
self._dtype = dtype

if isinstance(value, np.ndarray):
if value.dtype == ml_dtypes.float4_e2m1fn or value.dtype == ml_dtypes.uint4 or value.dtype == ml_dtypes.int4:

Check notice

Code scanning / lintrunner

PYLINT/R1714 Note

Consider merging these comparisons with 'in' by using 'value.dtype in (ml_dtypes.float4_e2m1fn, ml_dtypes.uint4, ml_dtypes.int4)'. Use a set instead if elements are hashable. (consider-using-in)
See consider-using-in. To disable, use # pylint: disable=consider-using-in
if isinstance(value, np.ndarray):
if value.dtype == ml_dtypes.float4_e2m1fn or value.dtype == ml_dtypes.uint4 or value.dtype == ml_dtypes.int4:
# Pack the array into uint8
value = _type_casting.pack_int4(value)

Check failure

Code scanning / lintrunner

MYPY/assignment Error

Incompatible types in assignment (expression has type "ndarray[Any, dtype[unsignedinteger[_8Bit]]]", variable has type "TArrayCompatible") To disable, use # type: ignore[assignment]
using the ``.view()`` method.
"""
if isinstance(self._raw, np.ndarray) or _compatible_with_numpy(self._raw):
array = self._raw.__array__(dtype)

Check failure

Code scanning / lintrunner

PYLINT/E0602 Error

Undefined variable 'dtype' (undefined-variable)
See undefined-variable. To disable, use # pylint: disable=undefined-variable
using the ``.view()`` method.
"""
if isinstance(self._raw, np.ndarray) or _compatible_with_numpy(self._raw):
array = self._raw.__array__(dtype)

Check failure

Code scanning / lintrunner

RUFF/F821 Error

using the ``.view()`` method.
"""
if isinstance(self._raw, np.ndarray) or _compatible_with_numpy(self._raw):
array = self._raw.__array__(dtype)

Check failure

Code scanning / lintrunner

MYPY/name-defined Error

Name "dtype" is not defined To disable, use # type: ignore[name-defined]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

[IR] Create a PackedTensor to store packed 4bit data
1 participant