Skip to content
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

ENH: torch: unsigned types #253

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

ENH: torch: unsigned types #253

wants to merge 3 commits into from

Conversation

ev-br
Copy link
Member

@ev-br ev-br commented Feb 20, 2025

  • add type promotion rules for (uintN, uintM) and (uintN, intM)
  • return correct dtype lists in _info
  • stop skipping uintN tests on CI

EDIT: this PR is not mergeable currently. Running tests torch/uint results in ~70 failures as of pytorch 2.6.0, see the CI logs below (and/or the fold-out in #253 (comment)). We have to wait for pytorch itself to proceed with array-api-compat.torch wrappers.

@ev-br ev-br marked this pull request as draft February 20, 2025 20:03
@ev-br ev-br marked this pull request as ready for review February 22, 2025 18:43
Copy link
Contributor

@crusaderky crusaderky left a comment

Choose a reason for hiding this comment

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

Shouldn't this be matched by a bunch of lines disappearing from torch-xfails.txt? And if not, does it mean this change is untested?

@ev-br
Copy link
Member Author

ev-br commented Feb 25, 2025

Oh yeah, running tests locally with torch 2.5.1 generates 78 new failures (below the fold); torch 2.6 has 73. Some are in the test suite, and some are torch limitations. So it is tested, if indirectly --- just not on CI.
The CI passes because it sets ARRAY_API_TESTS_SKIP_DTYPES=uint16,uint32,uint64.

Which means we might want to revert gh-244 for the next release and lump it together with this one and the necessary fixes to the test suite. Just adding ~70 xfails is a bit extreme, at least without a deeper investigation.

$ $ ARRAY_API_TESTS_MODULE=array_api_compat.torch pytest array_api_tests/ -v --xfails-file ../array-api-compat/torch-xfails.txt --skips-file ../array-api-compat/torch-skips.txt

...

========================================================================================= short test summary info =========================================================================================
FAILED array_api_tests/test_array_object.py::test_setitem_masking - RuntimeError: "index_put" not implemented for 'UInt16'
FAILED array_api_tests/test_data_type_functions.py::test_astype - RuntimeError: value cannot be converted to type int64_t without overflow
FAILED array_api_tests/test_indexing_functions.py::test_take - RuntimeError: "index_select" not implemented for 'UInt16'
FAILED array_api_tests/test_linalg.py::test_cross - RuntimeError: "cross" not implemented for 'UInt16'
FAILED array_api_tests/test_linalg.py::test_diagonal - TypeError: an integer is required
FAILED array_api_tests/test_linalg.py::test_linalg_matmul - RuntimeError: "dot" not implemented for 'UInt16'
FAILED array_api_tests/test_linalg.py::test_matmul - RuntimeError: "dot" not implemented for 'UInt16'
FAILED array_api_tests/test_linalg.py::test_linalg_matrix_transpose - TypeError: an integer is required
FAILED array_api_tests/test_linalg.py::test_matrix_transpose - TypeError: an integer is required
FAILED array_api_tests/test_linalg.py::test_outer - RuntimeError: Promotion for uint16, uint32, uint64 types is not supported, attempted to promote Byte and UInt16
FAILED array_api_tests/test_linalg.py::test_linalg_tensordot - RuntimeError: "addmm_impl_cpu_" not implemented for 'UInt16'
FAILED array_api_tests/test_linalg.py::test_tensordot - RuntimeError: "addmm_impl_cpu_" not implemented for 'UInt16'
FAILED array_api_tests/test_linalg.py::test_trace - TypeError: an integer is required
FAILED array_api_tests/test_linalg.py::test_linalg_vecdot - RuntimeError: Promotion for uint16, uint32, uint64 types is not supported, attempted to promote Byte and UInt16
FAILED array_api_tests/test_linalg.py::test_vecdot - RuntimeError: Promotion for uint16, uint32, uint64 types is not supported, attempted to promote Byte and UInt16
FAILED array_api_tests/test_manipulation_functions.py::test_concat - RuntimeError: Promotion for uint16, uint32, uint64 types is not supported, attempted to promote Byte and UInt16
FAILED array_api_tests/test_manipulation_functions.py::test_flip - RuntimeError: "flip_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_manipulation_functions.py::test_stack - RuntimeError: Promotion for uint16, uint32, uint64 types is not supported, attempted to promote Byte and UInt16
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_abs[abs] - RuntimeError: "abs_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_abs[__abs__] - RuntimeError: "abs_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_add[add(x1, x2)] - RuntimeError: "add_stub" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_add[__add__(x, s)] - RuntimeError: "add_stub" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_add[__iadd__(x1, x2)] - RuntimeError: "add_stub" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_add[__iadd__(x, s)] - RuntimeError: "add_stub" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_and[bitwise_and(x1, x2)] - RuntimeError: "bitwise_and_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_and[__and__(x, s)] - RuntimeError: "bitwise_and_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_and[__iand__(x1, x2)] - RuntimeError: "bitwise_and_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_and[__iand__(x, s)] - RuntimeError: "bitwise_and_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_left_shift[bitwise_left_shift(x1, x2)] - RuntimeError: "lt_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_left_shift[__lshift__(x, s)] - RuntimeError: "lshift_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_left_shift[__ilshift__(x1, x2)] - RuntimeError: "lt_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_left_shift[__ilshift__(x, s)] - RuntimeError: "lshift_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_invert[bitwise_invert] - RuntimeError: "bitwise_not_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_invert[__invert__] - RuntimeError: "bitwise_not_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_or[bitwise_or(x1, x2)] - RuntimeError: "bitwise_or_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_or[__or__(x, s)] - RuntimeError: "bitwise_or_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_or[__ior__(x1, x2)] - RuntimeError: "bitwise_or_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_or[__ior__(x, s)] - RuntimeError: "bitwise_or_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_right_shift[bitwise_right_shift(x1, x2)] - RuntimeError: "lt_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_right_shift[__rshift__(x, s)] - RuntimeError: "rshift_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_right_shift[__irshift__(x, s)] - RuntimeError: "rshift_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_xor[bitwise_xor(x1, x2)] - RuntimeError: "bitwise_xor_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_xor[__xor__(x, s)] - RuntimeError: "bitwise_xor_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_xor[__ixor__(x1, x2)] - RuntimeError: "bitwise_xor_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_bitwise_xor[__ixor__(x, s)] - RuntimeError: "bitwise_xor_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_clip - ExceptionGroup: Hypothesis found 2 distinct failures. (2 sub-exceptions)
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_equal[equal(x1, x2)] - RuntimeError: Promotion for uint16, uint32, uint64 types is not supported, attempted to promote UInt16 and Byte
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_greater[greater(x1, x2)] - RuntimeError: "gt_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_greater[__gt__(x, s)] - RuntimeError: "gt_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_greater_equal[greater_equal(x1, x2)] - RuntimeError: "ge_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_greater_equal[__ge__(x, s)] - RuntimeError: "ge_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_less[less(x1, x2)] - RuntimeError: "lt_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_less[__lt__(x, s)] - RuntimeError: "lt_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_less_equal[less_equal(x1, x2)] - RuntimeError: "le_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_less_equal[__le__(x, s)] - RuntimeError: "le_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_multiply[__imul__(x1, x2)] - RuntimeError: Promotion for uint16, uint32, uint64 types is not supported, attempted to promote Long and UInt16
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_negative[negative] - RuntimeError: "neg_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_negative[__neg__] - RuntimeError: "neg_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_not_equal[not_equal(x1, x2)] - RuntimeError: Promotion for uint16, uint32, uint64 types is not supported, attempted to promote UInt16 and Byte
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_pow[pow(x1, x2)] - ExceptionGroup: Hypothesis found 2 distinct failures. (2 sub-exceptions)
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_pow[__pow__(x, s)] - RuntimeError: "pow" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_pow[__ipow__(x1, x2)] - RuntimeError: "ge_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_pow[__ipow__(x, s)] - RuntimeError: "pow" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_sign - RuntimeError: "sign_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_square - RuntimeError: "pow" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_subtract[subtract(x1, x2)] - RuntimeError: "add_stub" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_subtract[__sub__(x, s)] - RuntimeError: "add_stub" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_subtract[__isub__(x1, x2)] - RuntimeError: "add_stub" not implemented for 'UInt16'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_subtract[__isub__(x, s)] - RuntimeError: "add_stub" not implemented for 'UInt16'
FAILED array_api_tests/test_searching_functions.py::test_argmax - RuntimeError: "argmax_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_searching_functions.py::test_argmin - RuntimeError: "argmin_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_searching_functions.py::test_nonzero - RuntimeError: "nonzero_count_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_searching_functions.py::test_where - RuntimeError: "where_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_statistical_functions.py::test_cumulative_sum - ExceptionGroup: Hypothesis found 2 distinct failures. (2 sub-exceptions)
FAILED array_api_tests/test_statistical_functions.py::test_max - RuntimeError: "max_values_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_statistical_functions.py::test_min - RuntimeError: "min_values_cpu" not implemented for 'UInt16'
FAILED array_api_tests/test_statistical_functions.py::test_prod - ExceptionGroup: Hypothesis found 2 distinct failures. (2 sub-exceptions)
FAILED array_api_tests/test_statistical_functions.py::test_sum - AssertionError: out.dtype=int64, but should be uint64 [sum(uint8)]
============================================================= 78 failed, 882 passed, 20 skipped, 38 xfailed, 182 warnings in 66.90s (0:01:06) =============================================================

@crusaderky
Copy link
Contributor

Please don't revert #244; array-api-extras needs it for its tests to pass. #244 shows that basic functionality for these dtypes does work. I suspect scipy also benefits from it (see scipy/scipy#22584).

This definitely highlights the current state of affairs for uint types in torch. Without it I was under the false impression that everything worked now.
If 76 xfails are too much to put in the xfails file, maybe we can add regex support to array-api-tests.

ev-br added a commit to ev-br/array-api-compat that referenced this pull request Feb 26, 2025
This reverts commit c787bea.

PyTorch support for unsigned ints is patchy, as of pytorch 2.6 at least.
See data-apis#253 (comment)
for a discussion.
@crusaderky
Copy link
Contributor

@crusaderky
Copy link
Contributor

Ah I see that these tests run on hypothesis. Which means that if you XFAIL them for uint you are suppressing any failures on signed ints too - which is much worse.

I would suggest to leave the env variable where it is and add a comment to the xfails file to point out the elephant in the room. With that I'm happy to merge this PR.

@ev-br
Copy link
Member Author

ev-br commented Feb 26, 2025

Okay, the fact that scipy tests pass after scipy/scipy#22584 is reassuring.
Then indeed it makes sense to keep the current state of the main branch for 2.3, and strengthen the wording in the changelog.

This definitely highlights the current state of affairs for uint types in torch. Without it I was under the false impression that everything worked now.

That makes it two of us under that impression.
I asked a senior pytorch developer offline, and the answer is basically (paraphrasing) "nobody has gotten around to adding the required kernels; doing the work was not high enough priority so far, but if somebody's up to it, great".

To make it more visible, this PR now runs uint tests on CI, https://github.com/data-apis/array-api-compat/actions/runs/13540575384/job/37840526473?pr=253

If 76 xfails are too much to put in the xfails file, maybe we can add regex support to array-api-tests.

It's not only that it's too much. The problem AFAICS is that it's currently not easy to xfail a test with, say, uint16 and keep the test of int16. This is just an artefact of how array-api-suite is organized; restructuring it would be very welcome; let's keep that discussion in the array-api-repo though.

@crusaderky
Copy link
Contributor

crusaderky commented Feb 26, 2025

It's not only that it's too much. The problem AFAICS is that it's currently not easy to xfail a test with, say, uint16 and keep the test of int16. This is just an artefact of how array-api-suite is organized

It would require moving the dtype out of hypothesis and into pytest.mark.parametrize, which to me feels like a lot of work if just for pytorch.

@ev-br
Copy link
Member Author

ev-br commented Feb 26, 2025

For completeness, cross-ref the PyTorch issue: pytorch/pytorch#58734

@rgommers
Copy link
Member

The CI passes because it sets ARRAY_API_TESTS_SKIP_DTYPES=uint16,uint32,uint64.

Keeping gh-244 and keeping this skip in CI seems like the okay and low-effort way to go at first sight.

@ev-br ev-br mentioned this pull request Feb 26, 2025
7 tasks
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.

3 participants