快捷方式

事件

模块包含与标准 Python 日志集成的事件处理机制。

使用示例

from torch.distributed.elastic import events
event = events.Event(name="test_event", source=events.EventSource.WORKER, metadata={...})
events.get_logging_handler(destination="console").info(event)

API 方法

torch.distributed.elastic.events.record(event, destination='null')[源代码][源代码]
torch.distributed.elastic.events.construct_and_record_rdzv_event(run_id, message, node_state, name='', hostname='', pid=None, master_endpoint='', local_id=None, rank=None)[源代码][源代码]

初始化 rendezvous 事件对象并记录其操作。

参数
  • run_id (str) – Rendezvous 的运行 ID。

  • message (str) – 描述事件的消息。

  • node_state (NodeState) – 节点的状态(INIT、RUNNING、SUCCEEDED、FAILED)。

  • name (str) – 事件名称。(例如,正在执行的当前操作)。

  • hostname (str) – 节点的hostname。

  • pid (Optional[int]) – 节点的进程 ID。

  • master_endpoint (str) – Rendezvous 存储的主端点(如果已知)。

  • local_id (Optional[int]) – 节点的 local_id(如果在 dynamic_rendezvous.py 中定义)

  • rank (Optional[int]) – 节点的 rank(如果已知)。

返回

None

返回类型

None

示例

>>> # See DynamicRendezvousHandler class
>>> def _record(
...     self,
...     message: str,
...     node_state: NodeState = NodeState.RUNNING,
...     rank: Optional[int] = None,
... ) -> None:
...     construct_and_record_rdzv_event(
...         name=f"{self.__class__.__name__}.{get_method_name()}",
...         run_id=self._settings.run_id,
...         message=message,
...         node_state=node_state,
...         hostname=self._this_node.addr,
...         pid=self._this_node.pid,
...         local_id=self._this_node.local_id,
...         rank=rank,
...     )
torch.distributed.elastic.events.get_logging_handler(destination='null')[源代码][源代码]
返回类型

处理程序

事件对象

class torch.distributed.elastic.events.api.Event(name, source, timestamp=0, metadata=<factory>)[源代码][源代码]

此类表示在 Torchelastic 作业执行期间发生的通用事件。

事件可以是任何类型的有意义的操作。

参数
  • name (str) – 事件名称。

  • source (EventSource) – 事件生产者,例如 agent 或 worker

  • timestamp (int) – 事件发生时的毫秒级时间戳。

  • metadata (Dict[str, Optional[Union[str, int, float, bool]]]) – 与事件关联的附加数据。

class torch.distributed.elastic.events.api.EventSource(value)[源代码][源代码]

事件生产者的已知标识符。

torch.distributed.elastic.events.api.EventMetadataValue

别名 Optional[Union[str, int, float, bool]]

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深入教程

查看教程

资源

查找开发资源并获得问题解答

查看资源