pytorch
db6cfff8 - fix: forbid multi-index for index_select over scalar (#94347)

Commit
1 year ago
fix: forbid multi-index for index_select over scalar (#94347) Fixes #88940 According to the [doc](https://pytorch.org/docs/stable/generated/torch.index_select.html): 1. "The returned tensor has the same number of dimensions as the original tensor (`input`). " 2. "The `dim`th dimension has the same size as the length of `index`; other dimensions have the same size as in the original tensor." These two conditions cannot be satisfied at the same time if the `input` is a scalar && `index` has multiple values: because a scalar at most holds one element (according to property 1, the output is a scalar), it is impossible to satisfy "The `dim`th dimension has the same size as the length of `index`" when `index` has multiple values. However, currently, if we do so we either get: 1. Buffer overflow with ASAN; 2. Or (w/o ASAN) silently returns outputs that is not consistent with the doc (`x.index_select(0, torch.Tensor([0, 0, 0]).int())` returns `x`). As a result, we should explicitly reject such cases. Pull Request resolved: https://github.com/pytorch/pytorch/pull/94347 Approved by: https://github.com/malfet
Author
Committer
Parents
Loading