code: def test_launch_multi_slot_chief(
      mock_time: mock.MagicMock,
      mock_check_sshd: mock.MagicMock,
      mock_cluster_info: mock.MagicMock,
      mock_subprocess: mock.MagicMock,
  ) -> None:
      cluster_info = test_util.make_mock_cluster_info(
          ["0.0.0.0", "0.0.0.1"], 0, 4
      )
      mock_cluster_info.return_value = cluster_info
      mock_start_time = time.time()
      mock_time.return_value = mock_start_time
      script = ["s1", "s2"]
      sshd_cmd = launch.deepspeed.create_sshd_cmd()
      pid_server_cmd = launch.deepspeed.create_pid_server_cmd(
          cluster_info.allocation_id, len(cluster_info.slot_ids)
      )
      deepspeed_cmd = launch.deepspeed.create_run_command(
          cluster_info.container_addrs[0],
          launch.deepspeed.get_hostfile_path(
              multi_machine=True,
              allocation_id=cluster_info.allocation_id,
          ),
      )
      pid_client_cmd = launch.deepspeed.create_pid_client_cmd(
          cluster_info.allocation_id
      )
      log_redirect_cmd = launch.deepspeed.create_log_redirect_cmd()
  
      launch_cmd = (
          pid_server_cmd
          + deepspeed_cmd
          + pid_client_cmd
          + log_redirect_cmd
          + script
      )
  
      sshd_proc_mock = mock.MagicMock()
      launch_proc_mock = mock.MagicMock()
  
      def mock_process(
          cmd: List[str], *args: Any, **kwargs: Any
      ) -> Any:
          if cmd == sshd_cmd:
              return sshd_proc_mock(*args, **kwargs)
          if cmd == launch_cmd:
              return launch_proc_mock(*args, **kwargs)
          return None
  
      mock_subprocess.side_effect = mock_process
  
      with test_util.set_resources_id_env_var():
          launch.deepspeed.main(script)
  
      mock_cluster_info.assert_called_once()
      assert (
          os.environ["DET_CHIEF_IP"] == cluster_info.container_addrs[0]
      )
      assert os.environ["USE_DEEPSPEED"] == "1"
      assert os.environ["PDSH_SSH_ARGS"] == (
          "-o PasswordAuthentication=no -o StrictHostKeyChecking=no "
          f"-p {constants.DTRAIN_SSH_PORT} -2 -a -x %h"
      )
  
      mock_subprocess.assert_has_calls(
          [mock.call(sshd_cmd), mock.call(launch_cmd)]
      )
  
      assert mock_check_sshd.call_count == len(
          cluster_info.container_addrs
      )
      mock_check_sshd.assert_has_calls(
          [
              mock.call(
                  addr, mock_start_time + 20, constants.DTRAIN_SSH_PORT
              )
              for addr in cluster_info.container_addrs
          ]
      )
  
      launch_proc_mock().wait.assert_called_once()
  
      sshd_proc_mock().kill.assert_called_once()
      sshd_proc_mock().wait.assert_called_once()
  
      # Cleanup deepspeed environment file created in launch.deepspeed.main
      deepspeed_env_path = os.path.join(
          os.getcwd(), DEEPSPEED_ENVIRONMENT_NAME
      )
      if os.path.isfile(deepspeed_env_path):
          os.remove(deepspeed_env_path)
  
file_path: determined/harness/tests/launch/test_deepspeed.py
imports: import os
  import time
  from typing import Any, List
  from unittest import mock
  import pytest
  from deepspeed.launcher.runner import DEEPSPEED_ENVIRONMENT_NAME
  import determined.launch.deepspeed
  from determined import constants, launch
  from tests.launch import test_util
label_desc: Use image node_id 2 for calling a global function with example usage: test_launch_multi_slot_chief(mock_time, mock_check_sshd, mock_cluster_info, mock_subprocess) and returns: None, sshd_proc_mock, launch_proc_mock