Skip to content

make timeouts configurable #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions torchft/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,33 @@
MANAGER_PORT_ENV: str = "TORCHFT_MANAGER_PORT"
REPLICA_ID_KEY: str = "replica_id"

# Environment variables for various timeouts. These can also be passed
# in through the manager but the environment variables take precedence.
TIMEOUT_SEC_ENV: str = "TORCHFT_TIMEOUT_SEC"
QUORUM_TIMEOUT_SEC_ENV: str = "TORCHFT_QUORUM_TIMEOUT_SEC"
CONNECT_TIMEOUT_SEC_ENV: str = "TORCHFT_CONNECT_TIMEOUT_SEC"

T = TypeVar("T")


def get_timeout(
timeout_sec_env: str | None, default_timeout_sec: timedelta
) -> timedelta:
"""
Get the timeout from the environment variable or the default value.

Args:
timeout_sec_env: The environment variable for the timeout
default_timeout_sec: The default timeout
Returns:
The timeout to use. Environment variable takes precedence.
"""
if timeout_sec_env is not None:
return timedelta(seconds=int(timeout_sec_env))

return default_timeout_sec


class WorldSizeMode(Enum):
"""
This controls the numerics for the job when doing allreduces across replicas
Expand Down Expand Up @@ -177,9 +201,17 @@ def __init__(

self._pending_state_dict: Optional[Dict[str, object]] = None
self._use_async_quorum = use_async_quorum
self._timeout = timeout
self._quorum_timeout = quorum_timeout
self._connect_timeout = connect_timeout

self._timeout: timedelta = get_timeout(
os.environ.get(TIMEOUT_SEC_ENV, None), timeout
)
self._quorum_timeout: timedelta = get_timeout(
os.environ.get(QUORUM_TIMEOUT_SEC_ENV, None), quorum_timeout
)
self._connect_timeout: timedelta = get_timeout(
os.environ.get(CONNECT_TIMEOUT_SEC_ENV, None), connect_timeout
)

self._replica_world_size_mode = world_size_mode
self._init_sync = init_sync
self._max_retries = max_retries
Expand Down
Loading