Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/187052
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ⏳ 1 Pending, 1 Unrelated FailureAs of commit 3ed8808 with merge base 9f132a8 ( BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
LocalDeviceMesh
9f72e27 to
eaa429e
Compare
|
This is better than the current logic, but not completely collision free, in rare cases, this can cause an issue. But I'm wondering if this is good enough. Let's say if we actually have a collision, can the later LocalTensor still reuse that cached one? It seems to be fine. cc., @wconstab |
|
@claude review this PR |
|
I think this logic looks fine. let's see what claude says and i'm also discussing with @fegin offline |
|
Claude finished @wconstab's task in 1m 56s —— View job PR Review: Fix coordinate cache in
|
fegin
left a comment
There was a problem hiding this comment.
This PR should fix the original collision issue. Thanks for the fix.
|
Claudes comment on the key description makes sense to me, so updated that to avoid confusion in the future. |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
Move coordinate cache to LocalDeviceMesh.
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.
Caching the result directly in LocalDeviceMesh, as it is a property of
that, is safer.
It might be possible that during the lifetime of a LocalDeviceMesh the
LocalTensorMode is changed which affects the coordinate calculation
through the `ranks` value, so use that as a key of a dict instead of
storing the value directly in a property.
Fixes pytorch#184526
Fixes 8e65dfa.
`(Local)DeviceMesh` seems to get serialized including its attributes which doesn't seem to work for the `LocalIntNode` contained. Use a tuple of all attributes used for calculation as the cache key.
|
Successfully rebased |
17c2a6c to
3ed8808
Compare
|
@pytorchbot merge -f "The failing test is not related" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
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
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
) (#3537) 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. Co-authored-by: Alexander Grund <[email protected]>
) (#3538) Cherry-pick of upstream commit 2314113 (pytorch#187052) onto release/2.12. 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. Co-authored-by: Alexander Grund <[email protected]>
) (#3539) Cherry-pick of upstream commit 2314113 (pytorch#187052) onto release/2.13. 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. Co-authored-by: Alexander Grund <[email protected]>
Alternative to #184534 after discussion and #187021.
The cache used the
idof the Mesh as the key which is not unique over the lifetime of theLocalTensorModeinstance: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 #184526
Fixes 8e65dfa.
Closes #184534
Closes #187021