Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

tensor __setitem__ incorrect on mps when dtypes mismatch #95417

Closed
hchau630 opened this issue Feb 23, 2023 · 2 comments
Closed

tensor __setitem__ incorrect on mps when dtypes mismatch #95417

hchau630 opened this issue Feb 23, 2023 · 2 comments
Labels
module: advanced indexing Related to x[i] = y, index functions module: mps Related to Apple Metal Performance Shaders framework module: type promotion Related to semantics of type promotion triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@hchau630
Copy link

hchau630 commented Feb 23, 2023

馃悰 Describe the bug

On my M1 Macbook, torch.Tensor.__setitem__ yields incorrect result when using mps and when the dtype of the assigned elements is not the same as the dtype of the tensor on which __setitem__ is called.

import torch

device = torch.device('mps')

t = torch.zeros(5, device=device)
u = torch.ones(2, device=device).long()
t[2:4] = u
print(t)

Output:
tensor([1., 1., 0., 0., 0.], device='mps:0')

Expected:
tensor([0., 0., 1., 1., 0.], device='mps:0')

Versions

Collecting environment information...
PyTorch version: 1.13.1
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 12.6.3 (arm64)
GCC version: Could not collect
Clang version: 12.0.0 (clang-1200.0.32.28)
CMake version: Could not collect
Libc version: N/A

Python version: 3.9.13 (main, Oct 13 2022, 16:12:19)  [Clang 12.0.0 ] (64-bit runtime)
Python platform: macOS-12.6.3-arm64-arm-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Apple M1 Pro

Versions of relevant libraries:
[pip3] numpy==1.23.4
[pip3] torch==1.13.1
[conda] numpy                     1.23.4                   pypi_0    pypi
[conda] torch                     1.13.1                   pypi_0    pypi

cc @nairbv @mruberry @kulinseth @albanD @malfet @DenisVieriu97 @razarmehr @abhudev

@ezyang ezyang added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module module: type promotion Related to semantics of type promotion module: advanced indexing Related to x[i] = y, index functions module: mps Related to Apple Metal Performance Shaders framework labels Feb 27, 2023
@hchau630
Copy link
Author

hchau630 commented Mar 20, 2023

this still seems to be a problem in 2.0.0 (though it works in the latest nightly build), even though the fix is merged into the main branch 3 weeks ago. Is it to be expected @ezyang? Sorry if it's a dumb question, I don't really know how the release cycle for pytorch works.

@ezyang
Copy link
Contributor

ezyang commented Mar 21, 2023

no it didn't make it into 2.0.0. I have proposed it for inclusion in 2.0.1.

hchau630 pushed a commit to hchau630/pytorch that referenced this issue Apr 10, 2023
This PR handles the case where the `dst` tensor of type casting has a storage offset by creating a temporary buffer to store results and then copy them back to the dst with the offset added.

Fixes pytorch#95417

Pull Request resolved: pytorch#95573
Approved by: https://github.com/kulinseth
@atalman atalman modified the milestone: 2.0.1 May 3, 2023
jhavukainen pushed a commit to kulinseth/pytorch that referenced this issue Mar 15, 2024
This PR handles the case where the `dst` tensor of type casting has a storage offset by creating a temporary buffer to store results and then copy them back to the dst with the offset added.

Fixes pytorch#95417

Pull Request resolved: pytorch#95573
Approved by: https://github.com/kulinseth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: advanced indexing Related to x[i] = y, index functions module: mps Related to Apple Metal Performance Shaders framework module: type promotion Related to semantics of type promotion triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants