xref: /aosp_15_r20/external/pytorch/torch/distributed/constants.py (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1*da0073e9SAndroid Build Coastguard Workerfrom datetime import timedelta
2*da0073e9SAndroid Build Coastguard Workerfrom typing import Optional
3*da0073e9SAndroid Build Coastguard Worker
4*da0073e9SAndroid Build Coastguard Workerfrom torch._C._distributed_c10d import _DEFAULT_PG_TIMEOUT
5*da0073e9SAndroid Build Coastguard Worker
6*da0073e9SAndroid Build Coastguard Worker
7*da0073e9SAndroid Build Coastguard Worker__all__ = ["default_pg_timeout", "default_pg_nccl_timeout"]
8*da0073e9SAndroid Build Coastguard Worker
9*da0073e9SAndroid Build Coastguard Worker# Default process group wide timeout, if applicable.
10*da0073e9SAndroid Build Coastguard Worker# This only applies to the non-nccl backends
11*da0073e9SAndroid Build Coastguard Worker# To make an attempt at backwards compatibility with THD, we use an
12*da0073e9SAndroid Build Coastguard Worker# extraordinarily high default timeout, given that THD did not have timeouts.
13*da0073e9SAndroid Build Coastguard Workerdefault_pg_timeout: timedelta = _DEFAULT_PG_TIMEOUT
14*da0073e9SAndroid Build Coastguard Worker# Separate timeout for PGNCCL mainly becuase it's always been that way in the C++ layer, but until recently
15*da0073e9SAndroid Build Coastguard Worker# there was one default that applied across all backends in the python layer.
16*da0073e9SAndroid Build Coastguard Worker# Later, we could consider merging them back together at the c++ layer if we can align on a same value.
17*da0073e9SAndroid Build Coastguard Worker# (only if TORCH_NCCL_BLOCKING_WAIT or TORCH_NCCL_ASYNC_ERROR_HANDLING is set to 1).
18*da0073e9SAndroid Build Coastguard Worker
19*da0073e9SAndroid Build Coastguard Workertry:
20*da0073e9SAndroid Build Coastguard Worker    from torch._C._distributed_c10d import _DEFAULT_PG_NCCL_TIMEOUT
21*da0073e9SAndroid Build Coastguard Worker
22*da0073e9SAndroid Build Coastguard Worker    default_pg_nccl_timeout: Optional[timedelta] = _DEFAULT_PG_NCCL_TIMEOUT
23*da0073e9SAndroid Build Coastguard Workerexcept ImportError:
24*da0073e9SAndroid Build Coastguard Worker    # if C++ NCCL support is not compiled, we don't have access to the default nccl value.
25*da0073e9SAndroid Build Coastguard Worker    # if anyone is actually trying to use nccl in this state, it should error.
26*da0073e9SAndroid Build Coastguard Worker    default_pg_nccl_timeout = None
27