Repository navigation
Conversation
Alternative to pytorch#184534 after discussion and pytorch#187021. The cache used the `id` of the Mesh as the key which is not unique over the lifetime of the `LocalTensorMode` instance: When the mesh is destroyed its slot may be reused leading to silently wrong, indeterministic results. E.g.: mesh_dim0_local_rank = mesh_2d["dim0"].get_local_rank(mesh_dim=0) mesh_dim1_local_rank = mesh_2d["dim1"].get_local_rank(mesh_dim=0) The values for both might be the same as the 2nd could use the cached coords from the first submesh, which is a temporary that gets immediately destroyed. Use the attributes used for the calculation as the cache key instead. Those are all tuples or data classes which works fine. Fixes pytorch#184526 Fixes 8e65dfa. Closes pytorch#184534 Closes pytorch#187021 Pull Request resolved: pytorch#187052 Approved by: https://github.com/fegin (cherry picked from commit 2314113)
LocalDeviceMesh (#187052)LocalDeviceMesh (#187052)
pragupta
deleted the
cherry-pick/187052-local-tensor-coord-cache/release-2.11
branch
August 4, 2026 15:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-pick of upstream commit 2314113 (pytorch#187052) onto release/2.11.
The LocalTensorMode coordinate cache was keyed by the mesh's Python object id, which is not unique over the lifetime of the mode: when a temporary submesh is destroyed, Python may reuse its id for the next submesh, silently returning stale coordinates for a different mesh dimension. This fixes the cache key to use the actual inputs to the coordinate calculation (ndim, flattened rank map, layout) instead.
Fixes ROCM-28605, pytorch#184526.
Verified locally: test/distributed/tensor/test_utils.py::TestStridedShardingWithLocalTensor: {test_2d_mesh_strided_sharding,test_2d_mesh_2d_tensor_strided_sharding} fail before this commit and pass after it.