[Easy][torch.Event] Fix and improve the docs of torch.Event (#151411)

**Changes:**
- add detailed function or class signature
- fix the wrong display of torch.Event.wait and torch.Event.record
Pull Request resolved: https://github.com/pytorch/pytorch/pull/151411
Approved by: https://github.com/albanD
ghstack dependencies: #151404, #151221
This commit is contained in:
FFFrog
2025-04-23 14:26:13 +08:00
committed by PyTorch MergeBot
parent bd7dc1b17d
commit 0f9b02c839

View File

@ -13394,14 +13394,20 @@ Example::
add_docstr(
torch.Event,
r"""
Event(device, *, enable_timing) -> Event
Event(device=None, *, enable_timing=False, blocking=False, interprocess=False)
Query and record Stream status to identify or control dependencies across Stream and measure timing.
Arguments:
device (:class:`torch.device`, optional): the desired device for the Event.
If not given, the current :ref:`accelerator<accelerators>` type will be used.
enable_timing (bool, optional): indicates if the event should measure time (default: ``False``).
enable_timing (bool, optional): indicates if the event should measure time (default: ``False``)
blocking (bool, optional): if ``True``, :meth:`wait` will be blocking (default: ``False``)
interprocess (bool): if ``True``, the event can be shared between processes (default: ``False``)
.. warning::
Both blocking and interprocess are not supported right now and are noops.
Returns:
Event: An torch.Event object.
@ -13409,6 +13415,7 @@ Returns:
Example::
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
>>> event = torch.Event()
>>> e_cuda = torch.Event(device='cuda')
""",
)
@ -13464,14 +13471,14 @@ Example::
add_docstr(
torch.Event.record,
r"""
Event.record(stream) -> None
Event.record(stream=None) -> None
Record the event in a given stream. The stream's device must match the event's device.
This function is equivalent to ``stream.record_event(self)``.
Arguments:
stream (:class:`torch.Stream`, optional): A stream to be recorded.
If not given, the current stream will be used.
If not given, the current stream will be used.
Example::
@ -13502,13 +13509,13 @@ Example::
add_docstr(
torch.Event.wait,
r"""
Event.wait(stream) -> None
Event.wait(stream=None) -> None
Make all future work submitted to the given stream wait for this event.
Arguments:
stream (:class:`torch.Stream`, optional): A stream to synchronize.
If not given, the current stream will be used.
If not given, the current stream will be used.
Example::