torch.distributed.algorithms.ddp_comm_hooks.debugging_hooks 的源代码
从 typing 导入 Any,导入 torch,从 torch.distributed 导入 GradBucket __all__ = ["noop_hook"]
[文档]def noop_hook(_: Any, bucket: GradBucket) -> torch.futures.Future[torch.Tensor]:
""
返回一个包装输入的未来,使其成为一个不执行任何通信开销的无操作。
此钩子**仅**应用于 allreduce 优化中所有 reduce 分析的空闲空间分析,
而不是正常的梯度同步。
例如,如果在此钩子注册后只能观察到训练时间低于 10%的加速
通常意味着 allreduce 不是这种情况的性能瓶颈。
此类仪器特别有用
如果 GPU 追踪无法轻松检索或追踪分析复杂
一些因素,例如 allreduce 与计算之间的重叠或跨 rank 的解同步。
示例::
>>> # xdoctest: +SKIP
>>> ddp_model.register_comm_hook(None, noop_hook)
"""
fut: torch.futures.Future[torch.Tensor] = torch.futures.Future()
fut.set_result(bucket.buffer())
return fut