快捷方式

事件

该模块包含与标准 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')[source][source]
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)[source][source]

初始化 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')[source][source]
返回类型

处理器

事件对象

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

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

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

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

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

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

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

class torch.distributed.elastic.events.api.EventSource(value)[source][source]

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

torch.distributed.elastic.events.api.EventMetadataValue

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

文档

访问 PyTorch 全面的开发者文档

查看文档

教程

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

查看教程

资源

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

查看资源