array-api-compat icon indicating copy to clipboard operation
array-api-compat copied to clipboard

ENH: `torch` dtype promotions

Open crusaderky opened this issue 8 months ago • 6 comments

  • On PyTorch >=2.3, support uint16, uint32, and uint64 in result_type
  • On PyTorch >=2.3, sum and prod will now promote uint8, uint16 and uint32 to uint64.

crusaderky avatar Apr 03 '25 10:04 crusaderky

https://github.com/data-apis/array-api-compat/pull/253 seems to have run into a wall with uint promotions in pytorch, did something change meanwhile in the meantime?

ev-br avatar Apr 03 '25 11:04 ev-br

#253 seems to have run into a wall with uint promotions in pytorch, did something change meanwhile in the meantime?

No, nothing has changed on the torch side AFAIK.

  • The changes to the dtypes table in this PR are functionally the same as in #253, but IMHO cleaner. They don't need to wait for full torch support in various functions to be merged.
  • The fix to sum(x, dtype=x.dtype, axis=() is unrelated to dtype promotion
  • The promotion of uint8/16/32 to uint64 in sum and prod is missing in #253, and something you want to have anyway
  • Unlike #253, this PR changes neither CI nor __array_namespace_info__, which is what makes that PR non-mergeable.

crusaderky avatar Apr 03 '25 11:04 crusaderky

this PR changes neither CI nor array_namespace_info, which is what makes that PR non-mergeable.

You lost me here :-). So is it basically "let's add something because we want it, but not test it on CI because we know it'll break"?

ev-br avatar Apr 03 '25 14:04 ev-br

this PR changes neither CI nor array_namespace_info, which is what makes that PR non-mergeable.

You lost me here :-). So is it basically "let's add something because we want it, but not test it on CI because we know it'll break"?

Well, we will need this and the other PR eventually when torch introduces support. We can either keep this PR unmerged, or leave it in main but untested by CI. Final users that somehow manage to avoid the many non-functioning APIs will benefit from it immediately.

crusaderky avatar Apr 03 '25 14:04 crusaderky

We can either keep this PR unmerged, or leave it in main but untested by CI.

The latter we definitely do not want to do.

ev-br avatar Apr 07 '25 14:04 ev-br

I've updated this to incorporate the latest changes and added the contents of #253, which can now be closed.

crusaderky avatar Apr 15 '25 14:04 crusaderky