Introduce int32 index_fill and index_copy indices#142160
Introduce int32 index_fill and index_copy indices#142160rpsilva-aws wants to merge 1 commit intopytorch:mainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/142160
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit 763b7e4 with merge base 0318589 ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "release notes: cuda" |
|
cc: @miladm for visibility, since this is somewhat an extension/related to pytorch/xla#8450. |
|
@eqy can you take a look at this? |
0719b7d to
27ef254
Compare
✅ Deploy Preview for chimerical-cranachan-793287 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
Fixed a typo in the CUDA file, PTAL. |
|
@eqy Can you help restart the WF? Thank you. |
27ef254 to
763b7e4
Compare
The indices are for the elements along a specific dimension, and these are implicitly capped by the index type. The total number of elements for the indices can have repeated values if I am not mistaken, so the assertion wouldn't necessarily hold. I also thought of aligning the first dimension type with the indices, but doesn't necessarily need to hold, but we do have an assert for that: |
What I mean is, does it make sense to add a check against a dim with size > |
I see, thanks for your suggestion - and if I am not mistaken, this already is in place. In the current kernel implementation, when we iterate through the indices, the existing TORCH_CHECK_INDEX macro should already do this bounds checking for each index against dim (size > idx <= INT_MAX, for int32). This should already make it a safe operation for handling 32-bit indices: https://github.com/pytorch/pytorch/pull/142160/files#diff-8aa1a200ec63d23db422aa31b6dca1e6cb372887c43b064ef435210b1b0dec0aR3446. If you instead mean the dim input, then these represent the dim tensor that we operate within, it wouldn't be directly related. Let me know if this helps answer it. |
|
@eqy do you have other concerns here? Let me know if any, in case this could still go in for 2.6. |
|
My concern was not memory safety, but rather warning/alerting the user in cases where the index width could not be used to fully address a given dimension, e.g., dim size > 2**32 but index type |
|
A trivial code example: What would the second case do here? IMO relying on potential UB (e.g., assuming the conversion rolls negative) seems flaky |
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
|
@pytorchbot label "no-stale" |
|
Keep this alive. |
|
See #141994 for a related RFC. |
@rpsilva-aws @eqy can the following be used to check for index bound? canUse32BitIndexMath can_use_32bit_indexing pytorch/aten/src/ATen/TensorIterator.cpp Line 1299 in cb1e313 |
|
@rpsilva-aws will you rebase? |
Fixes #142090
This PR extends index_fill and index_copy operations to support int32 indices in addition to the existing int64 support:
cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10