Commit f31b8bb
[MPS] Fix sliced cast (#138535)
[MPS] Fix sliced cast (#138314)
This fixes internal crash due to the invalid bufer size computation if sliced API is used
Not sure what was the purpose of
```c++
IntArrayRef baseShape;
if (src.is_view()) {
baseShape = src._base().sizes();
} else {
baseShape = getIMPSAllocator()->getBufferShape(src.storage().data());
}
int flattenedShaped = 1;
for (const auto i : c10::irange(baseShape.size())) {
flattenedShaped *= baseShape[i];
}
```
As flattenShaped could be much easier computed as `[srcBuf
lengh]/src.element_size()`, and even if `srcBuf` is padded it's a safe thing to do.
When someone allocated buffer to hold say uint8 and that view-casted it
to float16, attempt to compute `baseShape` returned sizes of original
tensor in its data type, rather than size in new dtypes
Fixes #137800
Pull Request resolved: #138314
Approved by: https://github.com/albanD, https://github.com/DenisVieriu97
(cherry picked from commit de16159)
Co-authored-by: Nikita Shulga <nikita.shulga@gmail.com>1 parent 848e7ac commit f31b8bb
2 files changed
+9
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
542 | 542 | | |
543 | 543 | | |
544 | 544 | | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
557 | 548 | | |
558 | 549 | | |
559 | 550 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10964 | 10964 | | |
10965 | 10965 | | |
10966 | 10966 | | |
| 10967 | + | |
| 10968 | + | |
| 10969 | + | |
| 10970 | + | |
| 10971 | + | |
| 10972 | + | |
10967 | 10973 | | |
10968 | 10974 | | |
10969 | 10975 | | |
| |||
0 commit comments