Skip to content
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

[Core] Make multi-node job fail fast when one fails, and output segment fault #3081

Merged
merged 25 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions docs/source/running-jobs/environment-variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ and ``run`` stages have different environment variables available.
Setup Stage
~~~~~~~~~~~

Since setup commands always run on all nodes of a cluster, SkyPilot ensures both of these environment variables (the ranks and the IP list) never change across multiple setups on the same cluster.
Michaelvll marked this conversation as resolved.
Show resolved Hide resolved

.. list-table::
:widths: 20 70 10
:header-rows: 1
Expand Down
17 changes: 8 additions & 9 deletions sky/backends/cloud_vm_ray_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import time
import typing
from typing import Any, Dict, Iterable, List, Optional, Set, Tuple, Union
import uuid

import colorama
import filelock
Expand Down Expand Up @@ -3129,19 +3128,19 @@ def _setup(self, handle: CloudVmRayResourceHandle, task: task_lib.Task,
# Disable connection sharing for setup script to avoid old
# connections being reused, which may cause stale ssh agent
# forwarding.
ssh_credentials.pop('ssh_control_name')
runners = command_runner.SSHCommandRunner.make_runner_list(
ip_list, port_list=port_list, **ssh_credentials)
ssh_credentials.pop('ssh_control_name', None)

random_suffix = uuid.uuid4().hex[:8]
remote_setup_file_name = f'/tmp/sky_setup_{random_suffix}'
remote_setup_file_name = f'/tmp/sky_setup_{self.run_timestamp}'
# Need this `-i` option to make sure `source ~/.bashrc` work
setup_cmd = f'/bin/bash -i {remote_setup_file_name} 2>&1'

def _setup_node(runner: command_runner.SSHCommandRunner) -> None:
def _setup_node(node_id: int) -> None:
setup_envs = task.envs.copy()
setup_envs['SKYPILOT_SETUP_NODE_IPS'] = '\n'.join(internal_ips)
setup_envs['SKYPILOT_SETUP_NODE_RANK'] = str(runners.index(runner))
setup_envs['SKYPILOT_SETUP_NODE_RANK'] = str(node_id)
runner = command_runner.SSHCommandRunner(ip_list[node_id],
port=port_list[node_id],
**ssh_credentials)
setup_script = log_lib.make_task_bash_script(setup,
env_vars=setup_envs)
with tempfile.NamedTemporaryFile('w', prefix='sky_setup_') as f:
Expand Down Expand Up @@ -3198,7 +3197,7 @@ def error_message() -> str:
# which can cause the program waiting for all the threads to finish,
# even if some of them raise exceptions. We should replace it with
# multi-process.
subprocess_utils.run_in_parallel(_setup_node, runners)
subprocess_utils.run_in_parallel(_setup_node, range(num_nodes))

if detach_setup:
# Only set this when setup needs to be run outside the self._setup()
Expand Down
4 changes: 2 additions & 2 deletions sky/utils/subprocess_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import random
import subprocess
import time
from typing import Any, Callable, List, Optional, Tuple, Union
from typing import Any, Callable, Iterable, List, Optional, Tuple, Union

import colorama
import psutil
Expand Down Expand Up @@ -50,7 +50,7 @@ def get_parallel_threads() -> int:
return max(4, cpu_count - 1)


def run_in_parallel(func: Callable, args: List[Any]) -> List[Any]:
def run_in_parallel(func: Callable, args: Iterable[Any]) -> List[Any]:
"""Run a function in parallel on a list of arguments.

The function should raise a CommandError if the command fails.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,8 @@ def test_multi_node_failure(generic_cloud: str):
# TODO(zhwu): we use multi-thread to run the commands in setup
# commands in parallel, which makes it impossible to fail fast
# when one of the nodes fails. We should fix this in the future.
# The --detach-setup version can fail fast, as the setup is
# submitted to the remote machine, which does not use multi-thread.
# Refer to the comment in `subprocess_utils.run_in_parallel`.
# f'sky launch -y -c {name} --cloud {generic_cloud} tests/test_yamls/failed_worker_setup.yaml && exit 1', # Ensure the job setup failed.
f'sky launch -y -c {name} --cloud {generic_cloud} --detach-setup tests/test_yamls/failed_worker_setup.yaml',
Expand Down
Loading