[DTensor RNG][BC Breaking] Change DTensor Philox seed and offset from int to tensor - #173876
[DTensor RNG][BC Breaking] Change DTensor Philox seed and offset from int to tensor#173876yiming0416 wants to merge 1 commit into
Conversation
This PR needs a
|
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/173876
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit a5af529 with merge base 4a6363b ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
72a5f5e to
9faa3fd
Compare
wconstab
left a comment
There was a problem hiding this comment.
i think this is probably a good change. it is BC breaking though, so we need to at least document it and ensure our release notes flag it. We should also wait for some others to take a look and give feedback.
| any_rank_philox = _PhiloxState(any_rank_device_state) | ||
| state.seed = any_rank_philox.seed | ||
| state.offset = any_rank_philox.offset | ||
| state.seed = int(any_rank_philox.seed.item()) |
There was a problem hiding this comment.
you're adding a new .item() call in the per op dispatch hot path.
is this only ok because you aren't tracing localtensor? does it have perf implications to localtensor mode though?
There was a problem hiding this comment.
local tensor should be fine... wouldn't worry about the overhead here.
There was a problem hiding this comment.
Currently we are not tracing LocalTensor. I did see _LocalPhiloxState in _LocalOffsetBasedRNGTracker which has a similar pattern that we could potentially get rid of .item() call there. But it has a larger surface so I didn't do that.
| @property | ||
| def offset(self) -> int: | ||
| return int(self._state[8:].view(dtype=torch.int64).item()) | ||
| def offset(self) -> torch.Tensor: |
There was a problem hiding this comment.
this is technically a BC breaking change, though it is on an underscore API, it is something external users depend on (I would cc @wanchaol and @leonardo0lyj @jc-bytedance @pengyanghua to see if they mind at least).
| torch.uint8 | ||
| ) | ||
| self._state[:8] = seed_tensor | ||
| def seed(self, seed: torch.Tensor) -> None: |
There was a problem hiding this comment.
the new version of the API probably should be more strict: previosuly, it was always going to be a tensor with 1 int64 value in it viewed as uint8. now, it is not gauranteed to be a 1elt tensor anymore
There was a problem hiding this comment.
added assert to make sure seed is a 1-elt tensor
|
|
||
| @property | ||
| def seed(self) -> int: | ||
| return int(self._state[:8].view(dtype=torch.uint64).item()) |
There was a problem hiding this comment.
i'm happy to get rid of this .item() call
f551b79 to
a8e94d3
Compare
|
can you also update your PR desc with a full description of why/what you changed? |
a8e94d3 to
1a139d7
Compare
@wconstab updated the PR desc. |
b8a3c6c to
8b49c6b
Compare
8b49c6b to
97e2528
Compare
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: <urlopen error [Errno 111] Connection refused> Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
97e2528 to
9161613
Compare
9161613 to
a5af529
Compare
Merge failedReason: New commits were pushed while merging. Please rerun the merge command. Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
… int to tensor (pytorch#173876) When tracing a DTensor random op, it involves tracing the RNG state in `OffsetBasedRNGTracker`. However the `.item()` call in the `_PhiloxState` is not fake tensor friendly. In this PR, we remove the `.item()` call in `_PhiloxState` so that the getter and setter of `seed` and `offset` directly interact with Tensors and it is more tracing friendly. `_LocalPhiloxState` in `_LocalOffsetBasedRNGTracker` has a similar pattern that we could potentially get rid of the `.item()` call. Right now we don't trace local tensor, so PR keeps it unchanged but makes sure it's compatible with the new `_PhiloxState` Pull Request resolved: pytorch#173876 Approved by: https://github.com/dolpm, https://github.com/wconstab
When tracing a DTensor random op, it involves tracing the RNG state in
OffsetBasedRNGTracker. However the.item()call in the_PhiloxStateis not fake tensor friendly.In this PR, we remove the
.item()call in_PhiloxStateso that the getter and setter ofseedandoffsetdirectly interact with Tensors and it is more tracing friendly._LocalPhiloxStatein_LocalOffsetBasedRNGTrackerhas a similar pattern that we could potentially get rid of the.item()call. Right now we don't trace local tensor, so PR keeps it unchanged but makes sure it's compatible with the new_PhiloxState