-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Make device-specific event inherits from torch.Event #134845
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/134845
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 1 Unrelated FailureAs of commit fd6dac2 with merge base ad8fae2 ( NEW FAILURE - The following job has failed:
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. |
|
Why did you change torch._C._CudaEventBase and not torch.cuda.Event ? Is there a significant different between inheriting for one or the other? |
In the previous design, pytorch/torch/csrc/cuda/Stream.h Line 9 in 23a2161
![]() The new design leads to a simpler class hierarchy and avoids duplicated methods. For torch._StreamBase, it is originally an unnecessary parent class. It results in a complicated inheritance shown below. |
|
Thanks a lot for the clear explanation! My guess is that the long term vision is to remove |
albanD
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments to the cuda code apply to the xpu side as well.
| PyObject_HEAD c10::Event event; | ||
| }; | ||
| extern PyObject* THPEventClass; | ||
| TORCH_API extern PyTypeObject* THPEventClass; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You add this to our public API because you need it on a third party c++ code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think the out-of-tree backend needs this to support linear inheritance.
| }; | ||
|
|
||
| void THCPEvent_init(PyObject* module) { | ||
| Py_INCREF(THPEventClass); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please assert that it is non-null here. In case someone changes the init order and this has not been set yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
Updated.
torch/csrc/cuda/Event.h
Outdated
|
|
||
| struct THCPEvent { | ||
| struct THCPEvent : THPEvent { | ||
| PyObject_HEAD at::cuda::CUDAEvent cuda_event; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you actually need the PyObject_HEAD after subclassing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not necessary. Removed.
I don't ensure if |
|
@albanD, may I know if this series of PR is reasonable for you? |
|
@albanD May I know if there are any other comments for these two PRs? |
albanD
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
Might be good to add a small test to ensure the inheritence is exactly what we expect it to be if we plan on relying on it.
Can be done in a follow up if needed.
@guangyey let's add case to check the inheritance. |
|
@albanD @gujinghui Add some UTs to check the expected inheritance. |
Merge failedReason: 4 jobs have failed, first few of them are: xpu / linux-jammy-xpu-py3.9 / test (default, 1, 4, linux.idc.xpu), xpu / linux-jammy-xpu-py3.9 / test (default, 2, 4, linux.idc.xpu), xpu / linux-jammy-xpu-py3.9 / test (default, 3, 4, linux.idc.xpu), xpu / linux-jammy-xpu-py3.9 / test (default, 4, 4, linux.idc.xpu) Details for Dev Infra teamRaised by workflow job |
|
"Unrelated failures" |
|
"Unrelated failures" |
Merge failedReason: Not merging any PRs at the moment because there is a merge blocking https://github.com/pytorch/pytorch/labels/ci:%20sev issue open at: Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -f "Unrelated failures" |
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 |
# Motivation This PR intends to make device-specific Event inherit from the generic torch.Event. The benefit is providing a generic abstract class `torch.Event` for different devices, like `torch.Stream`. This make it easier for Dynamo to capture the Event of different devices, like torch.cuda.Event and torch.xpu.Event. And the next PR would like to remove previous useless base class `_StreamBase` and `_EventBase` to avoid multiple Inheritance. Pull Request resolved: pytorch#134845 Approved by: https://github.com/albanD, https://github.com/EikanWang
This PR intends to make device-specific Event inherit from the generic torch.Event. The benefit is providing a generic abstract class `torch.Event` for different devices, like `torch.Stream`. This make it easier for Dynamo to capture the Event of different devices, like torch.cuda.Event and torch.xpu.Event. And the next PR would like to remove previous useless base class `_StreamBase` and `_EventBase` to avoid multiple Inheritance. Pull Request resolved: pytorch#134845 Approved by: https://github.com/albanD, https://github.com/EikanWang
This PR intends to make device-specific Event inherit from the generic torch.Event. The benefit is providing a generic abstract class `torch.Event` for different devices, like `torch.Stream`. This make it easier for Dynamo to capture the Event of different devices, like torch.cuda.Event and torch.xpu.Event. And the next PR would like to remove previous useless base class `_StreamBase` and `_EventBase` to avoid multiple Inheritance. Pull Request resolved: pytorch#134845 Approved by: https://github.com/albanD, https://github.com/EikanWang




Stack from ghstack (oldest at bottom):
Motivation
This PR intends to make device-specific Event inherit from the generic torch.Event. The benefit is providing a generic abstract class
torch.Eventfor different devices, liketorch.Stream. This make it easier for Dynamo to capture the Event of different devices, like torch.cuda.Event and torch.xpu.Event.And the next PR would like to remove previous useless base class
_StreamBaseand_EventBaseto avoid multiple Inheritance.cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10