-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Support for uint16
, uint32
, and uint64
#58734
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
Comments
Someone just asked about other uint types on Slack. And from pytorch/vision#4326 (comment):
16-bit image support making There are no plans to work on this issue currently I think, unless more demand materializes. |
I'll add one :) Another tangible need for uint16 support in torchvision is pytorch/vision#4731 We added support for native 16 bits png decoding in torchvision, but we can't make this API public for now, because we output int32 tensors and this wouldn't be compatible with the rest of our transforms. |
Bumping this. My research collaborators and I are working on some cryptographic applications where we could really use |
We have a GIS pipeline that uses image transforms from multiple projects, some of which only support uint, but uint8 leads to too much loss of color information. We could really use uint16 support. |
I would appreciate uint16 support! I'm trying to do NLP stuff with a large dataset of tokens between 0 and 51000, and it's annoying to consume double the storage to keep them as int32s (I'm currently storing them as uint16 via HuggingFace, but I need to load them as NumPy and manually convert them) |
I'm doing work on HDR imaging and we read images from the camera as 16-bit unsigned. It's possible to work around it by using other frameworks but it would be really useful. |
This is exactly the issue me and my team are faced with right now. |
I'm doing work with DICOM data that is often 10 or even 14 unsigned bits. A uint16 would be very nice for these! My work is focused on speed so using the smallest possible datatype would be very appreciated. |
We should add these dtypes, and then build out support via PT2. We probably aren't going to add kernels for everything but Triton makes it very easy to JIT compile these operations. |
@ezyang would Triton be able to enable CPU support? |
Not Triton per se, but we have a CPU inductor backend, so the answer is yes! |
From Triage review: We still need some limited eager support, e.g. factory functions, conversion functions. Also consideration with autocast? (maybe not too bad?) |
Also, bit ops are only well-defined/standardized in CPUs for unsigned dtypes if I understand well: #105465 |
uint16 would also be useful for interop with opencv ( |
The dtypes are very useless right now (not even fill works), but it makes torch.uint16, uint32 and uint64 available as a dtype. Towards #58734 Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
The dtypes are very useless right now (not even fill works), but it makes torch.uint16, uint32 and uint64 available as a dtype. Towards #58734 Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
The dtypes are very useless right now (not even fill works), but it makes torch.uint16, uint32 and uint64 available as a dtype. Towards #58734 Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
The dtypes are very useless right now (not even fill works), but it makes torch.uint16, uint32 and uint64 available as a dtype. Towards #58734 Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
The dtypes are very useless right now (not even fill works), but it makes torch.uint16, uint32 and uint64 available as a dtype. Towards #58734 Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
The dtypes are very useless right now (not even fill works), but it makes torch.uint16, uint32 and uint64 available as a dtype. Towards #58734 Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
The dtypes are very useless right now (not even fill works), but it makes torch.uint16, uint32 and uint64 available as a dtype. Towards #58734 Signed-off-by: Edward Z. Yang <ezyang@meta.com> Pull Request resolved: #116594 Approved by: https://github.com/albanD ghstack dependencies: #116698, #116693
Hi guys! I would like to add another usage for uint16 on GPUs, which can be used in designing efficient adaptive sparse optimizers. |
When working with torch, the output is often float32. Torch does not have good support for conversion to uint types: pytorch/pytorch#58734 Support float32 and the signed integer types for convenience.
ANother
|
Another |
And another usecase for unsigned dtypes is bitshifts, as bitshift for signed dtypes (if signed bit is set) is theoretically implementation-defined or undefined |
@vadimkantorov @rbelew In case you didn't realise torch >= 2.3 has all the unsigned int types. |
Yeah, I saw the support, but I didn't realize which ops are enabled for them. E.g. is bitshift enabled? |
@malfet just added bitshift. Op support is on a per request basis: we will add it if requested |
If you are meaning the #135525, it only added and/or/xor, but maybe bitshifts were added in some other PRs... |
Echoing the comment from @neelnanda-io, would be great to add |
for embedding I think this involves beefing up index_select |
related on supporting natively shorted bitwidth indexes: (might also be useful for the sparse tensors, wherever indexes are used to also support shorter dtypes including unsigned, and not only int64) and also related (on efficient support of shorter-width dtypes for Embedding - but back then in the signed context): |
As a data point, we tried enabling unsigned integers in the Array API test suite, in data-apis/array-api-compat#253 That results in 70-odd failures, the majority of which are of the |
I also ran accross those I thought I'd also report: import torch as xp
x = xp.asarray([1, 2, 3], dtype=xp.uint64)
sentinel = xp.iinfo(xp.uint64).max // 2 + 1
x[0] = sentinel - 1 # OK
x[0] = xp.asarray(sentinel, dtype=x.dtype) # OK
x[0] = sentinel # RuntimeError: Overflow when unpacking long Since operations are added by request (#58734 (comment)), I'd like to request the following. These are chosen because they are defined by the standard yet import operator as op
# from array_api_compat import torch as xp
import torch as xp
x = xp.asarray(1, dtype=xp.uint16)
A = xp.asarray([[1]], dtype=xp.uint16)
i = xp.asarray([True])
abs(x) # "abs_cpu" not implemented for 'UInt16'
x + x # "add_stub" not implemented for 'UInt16'
xp.arange(10, dtype=xp.uint16) # "arange_cpu" not implemented for 'UInt16'
~x # "bitwise_not_cpu" not implemented for 'UInt16'
x // x # "div_floor_cpu" not implemented for 'UInt16'
x[i] # "index_cpu" not implemented for 'UInt16'
x > x # "gt_cpu" not implemented for 'UInt16'
x >= x # "ge_cpu" not implemented for 'UInt16'
x < x # "lt_cpu" not implemented for 'UInt16'
x <= x # "le_cpu" not implemented for 'UInt16'
x << x # "lshift_cpu" not implemented for 'UInt16'
A[i] = 2 # "masked_fill" not implemented for 'UInt16'
xp.maximum(x, x) # "maximum_cpu" not implemented for 'UInt16'
xp.minimum(x, x) # "minimum_cpu" not implemented for 'UInt16'
-x # "neg_cpu" not implemented for 'UInt16'
xp.nextafter(x, x) # "nextafter_cpu" not implemented for 'UInt16'
x % x # "remainder_cpu" not implemented for 'UInt16'
x >> x # "rshift_cpu" not implemented for 'UInt16'
xp.sign(x) # "sign_cpu" not implemented for 'UInt16'
xp.tril(A) # "tril" not implemented for 'UInt16'
xp.triu(A) # "triu" not implemented for 'UInt16'
xp.where(i, x, x) # "where_cpu" not implemented for 'UInt16' That's:
|
Uh oh!
There was an error while loading. Please reload this page.
The array API specification stipulates the data types that we need to support to be compliant. Currently we are missing support for
uint16
,uint32
, anduint64
.cc @mruberry @rgommers @asmeurer @leofang @AnirudhDagar @asi1024 @emcastillo @kmaehashi @ezyang @msaroufim @wconstab @bdhirsh @anijain2305 @zou3519 @gchanan @soumith @ngimel
The text was updated successfully, but these errors were encountered: