Skip to content

ciflow/torchtitan/201372

@ezyang ezyang tagged this 19 Oct 18:33
Part of #201298 (tracking issue: #201370)
Supported by @ezyang

Yes. Indexing with a `torch.uint8` tensor (`x[mask]`, `x[mask] = v`,
`index`, `index_put_`) used to treat it as a boolean mask and warn that this
was deprecated (since 1.2). It now raises an `IndexError`. Migrate by
converting the mask: `x[mask.bool()]`.

<!-- TODO(ezyang): fill in -->

> Follows the process in #201298: the uint8 mask deprecation has warned since
> 1.2, so it now becomes an error for at least one release. Giving uint8
> indices integer semantics (as NumPy does) is left as a separate decision.
>
> - `uint8_index_unsupported()` (was `uint8_index_deprecated()`) raises
>   instead of warning; `expandTensors` calls it for every uint8 index.
> - The indexing front end (`TensorIndexing.h`) sends the two uint8 cases
>   that bypassed `expandTensors` there too: `x[uint8_mask] = scalar` no
>   longer takes the masked_fill fast path (it failed with "masked_fill only
>   supports boolean masks"), and 0-dim uint8 indices are no longer silently
>   treated as bools (they never warned). The front ends still count uint8
>   indices as masks, so a mask-shaped uint8 index reaches this error rather
>   than an unrelated shape error.
> - Meta kernels for `index` / `index_put` raise the same error, so
>   torch.compile matches eager; `meta_index_Tensor` no longer expands uint8
>   masks. Fake tensor and inductor's masked fill fast path no longer
>   special-case uint8.
>
> Test plan: test_indexing.py (CPU + CUDA), test_fake_tensor.py,
> test_torch.py -k index -k mask, pytest test_ops.py / test_meta.py /
> test_proxy_tensor.py -k "(index or mask or getitem or setitem) and cpu".
> test/cpp/api/tensor_indexing.cpp built as a standalone gtest binary
> against this build (CPU + CUDA). MPS/ONNX tests not run locally.
>
> Authored with an AI assistant.
Assets 2
Loading