Skip to content

Conversation

@pytorchbot
Copy link
Collaborator

This fixes internal crash due to the invalid bufer size computation if sliced API is used

Not sure what was the purpose of

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

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)
@pytorch-bot
Copy link

pytorch-bot bot commented Oct 22, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/138535

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (1 Unrelated Failure)

As of commit 6db59b4 with merge base b7eb725 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added ciflow/mps Run MPS tests (subset of trunk) release notes: mps Release notes category labels Oct 22, 2024
@malfet malfet merged commit f31b8bb into release/2.5 Oct 22, 2024
@github-actions github-actions bot deleted the cherry-pick-138314-by-pytorch_bot_bot_ branch November 22, 2024 02:09
aostrowski-hbn pushed a commit to HabanaAI/pytorch-fork that referenced this pull request Jan 7, 2025
pytorch/pytorch@v2.5.0...v2.5.1

Squashed new commits are as follows:
* update getting started xpu (pytorch#138090)
* [Cherry-Pick] Use cuda 12.4 pytorch_extra_install_requirements as default (pytorch#138526)
* Don't try to load cufile (pytorch#138539)
* Add link to torch.compile the missing manual in troubleshooting (pytorch#137369)
* Update cpuinfo submodule (pytorch#138600)
* Update doc copyrights to 2024 (pytorch#138650)
* [SDPA-CUDNN] Make CuDNN Attention Opt in (pytorch#138587)
* [MPS] Fix sliced cast (pytorch#138535)
* Disabling amp context when invoking compiler (pytorch#138659)

Change-Id: I3e282e8b4809b97b38605420c64d1bd1b0b938aa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mps Run MPS tests (subset of trunk) open source release notes: mps Release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants