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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MPS] Fix non-contig to contig tensor copy #86056

Closed
wants to merge 4 commits into from

Conversation

malfet
Copy link
Contributor

@malfet malfet commented Oct 1, 2022

This handles a rare case when MPS tensor is constructed from non-contiguous CPU tensor.
Fixes #85967

@malfet malfet requested a review from kulinseth as a code owner October 1, 2022 20:31
@pytorch-bot
Copy link

pytorch-bot bot commented Oct 1, 2022

🔗 Helpful Links

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

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

❌ 3 Failures

As of commit 557f10b:

The following jobs have failed:

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 1, 2022
@malfet malfet requested a review from a team October 1, 2022 20:31
@@ -186,7 +186,9 @@ void copy_cast_mps(at::Tensor& dst, const at::Tensor& src,
// For View tensors, the storage offset can be bigger than what's being reported by nbytes
src_total_size = at::detail::computeStorageNbytesContiguous(src.sizes(), src.element_size(), src.storage_offset());
} else {
src = src_;
// Views are not the only source of non-contiguous tensors
// For example, tensor constructed from ndarray can be non-contagious
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// For example, tensor constructed from ndarray can be non-contagious
// For example, tensor constructed from ndarray can be non-contiguous

nit

Copy link
Contributor

@janeyx99 janeyx99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix lint before merge 😛

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 2, 2022
@malfet malfet force-pushed the malfet/mps-fix-non-contig-copy branch from 7dcd968 to 557f10b Compare October 2, 2022 17:39
# See https://github.com/pytorch/pytorch/issues/85967
def test_from_numpy_non_contiguous(self):
a = np.arange(9).reshape(3, 3)[:, :2]
t_cpu = torch.tensor(a, device="cpu")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this tensor constructor copy the passed data and makes always contig tensors? should this not be torch.as_tensor instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it does, but that's the point: MPS copy operator did not handled this case correctly

@malfet malfet changed the title [MPS] Fix non-contig tensor copy [MPS] Fix non-contig to contig tensor copy Oct 2, 2022
@malfet
Copy link
Contributor Author

malfet commented Oct 2, 2022

@pytorchbot merge -f "MPS tests are green"

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a merge job. Check the current status here.
The merge job was triggered with the force (-f) flag. This means your change will be merged immediately, bypassing any CI checks (ETA: 1-5 minutes). If this is not the intended behavior, feel free to use some of the other merge options in the wiki.
Please reach out to the PyTorch DevX Team with feedback or questions!

@github-actions
Copy link

github-actions bot commented Oct 2, 2022

Hey @malfet.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

mehtanirav pushed a commit that referenced this pull request Oct 4, 2022
This handles a rare case when MPS tensor is constructed from non-contiguous CPU tensor.
Fixes #85967

Pull Request resolved: #86056
Approved by: https://github.com/janeyx99
@malfet malfet deleted the malfet/mps-fix-non-contig-copy branch January 20, 2024 03:04
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) ciflow/trunk Trigger trunk jobs on your pull request cla signed Merged release notes: mps Release notes category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MPS Tensor from sliced numpy array indexing error
5 participants