Skip to content

[release/2.11] Fix coordinate cache in LocalDeviceMesh (#187052) - #3537

Merged
pragupta merged 1 commit into
release/2.11from
cherry-pick/187052-local-tensor-coord-cache/release-2.11
Aug 4, 2026
Merged

pragupta merged 1 commit into
release/2.11from
cherry-pick/187052-local-tensor-coord-cache/release-2.11

Conversation

@albmalamd

Copy link
Copy Markdown

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.

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)
@albmalamd
albmalamd requested a review from pragupta August 4, 2026 13:57
@pragupta pragupta changed the title [cherry-pick] Fix coordinate cache in LocalDeviceMesh (#187052) [release/2.11] Fix coordinate cache in LocalDeviceMesh (#187052) Aug 4, 2026
@pragupta
pragupta merged commit b793dce into release/2.11 Aug 4, 2026
@pragupta
pragupta deleted the cherry-pick/187052-local-tensor-coord-cache/release-2.11 branch August 4, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants