maddiedawson commented on code in PR #41770:
URL: https://github.com/apache/spark/pull/41770#discussion_r1258932690


##########
python/pyspark/ml/torch/deepspeed/tests/test_deepspeed_distributor.py:
##########
@@ -0,0 +1,180 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import os
+import sys
+from typing import List, Any, Callable, Dict
+import unittest
+
+from pyspark.ml.torch.deepspeed.deepspeed_distributor import 
DeepspeedTorchDistributor
+
+
+class DeepspeedTorchDistributorUnitTests(unittest.TestCase):
+    def _get_env_var(self, var_name: str, default_value: Any) -> Any:
+        value = os.getenv(var_name)
+        if value:
+            return value
+        os.environ[var_name] = str(default_value)
+        return default_value
+
+    def _get_env_variables_distributed(self):
+        MASTER_ADDR = self._get_env_var("MASTER_ADDR", "127.0.0.1")
+        MASTER_PORT = self._get_env_var("MASTER_PORT", 2000)
+        RANK = self._get_env_var("RANK", 0)
+        return MASTER_ADDR, MASTER_PORT, RANK
+
+    def test_get_torchrun_args_local(self):
+        number_of_processes = 5
+        EXPECTED_TORCHRUN_ARGS_LOCAL = ["--standalone", "--nnodes=1"]
+        EXPECTED_PROCESSES_PER_NODE_LOCAL = number_of_processes
+        (
+            get_local_mode_torchrun_args,
+            process_per_node,
+        ) = DeepspeedTorchDistributor._get_torchrun_args(True, 
number_of_processes)
+        self.assertEqual(get_local_mode_torchrun_args, 
EXPECTED_TORCHRUN_ARGS_LOCAL)
+        self.assertEqual(EXPECTED_PROCESSES_PER_NODE_LOCAL, process_per_node)
+
+    def test_get_torchrun_args_distributed(self):
+        number_of_processes = 5
+        MASTER_ADDR, MASTER_PORT, RANK = self._get_env_variables_distributed()
+        EXPECTED_TORCHRUN_ARGS_DISTRIBUTED = [
+            f"--nnodes={number_of_processes}",
+            f"--node_rank={RANK}",
+            f"--rdzv_endpoint={MASTER_ADDR}:{MASTER_PORT}",
+            "--rdzv_id=0",
+        ]
+        torchrun_args_distributed, process_per_node = 
DeepspeedTorchDistributor._get_torchrun_args(
+            False, number_of_processes
+        )
+        self.assertEqual(torchrun_args_distributed, 
EXPECTED_TORCHRUN_ARGS_DISTRIBUTED)
+        self.assertEqual(process_per_node, 1)
+
+    def test_create_torchrun_command_local(self):
+        DEEPSPEED_CONF = "path/to/deepspeed"
+        TRAIN_FILE_PATH = "path/to/exec"
+        NUM_PROCS = 10
+        input_params = {}
+        input_params["local_mode"] = True
+        input_params["num_processes"] = NUM_PROCS
+        input_params["deepspeed_config"] = DEEPSPEED_CONF
+
+        # get the arguments for no argument, local run
+        torchrun_local_args_expected = ["--standalone", "--nnodes=1"]
+        with self.subTest(msg="Testing local training with no extra args"):
+            LOCAL_CMD_NO_ARGS_EXPECTED = [
+                sys.executable,
+                "-m",
+                "torch.distributed.run",
+                *torchrun_local_args_expected,
+                f"--nproc_per_node={NUM_PROCS}",
+                TRAIN_FILE_PATH,
+                "-deepspeed",
+                "--deepspeed_config",
+                DEEPSPEED_CONF,
+            ]
+            local_cmd = DeepspeedTorchDistributor._create_torchrun_command(
+                input_params, TRAIN_FILE_PATH
+            )
+            self.assertEqual(local_cmd, LOCAL_CMD_NO_ARGS_EXPECTED)
+        with self.subTest(msg="Testing local training with extra args for the 
training script"):
+            local_mode_version_args = ["--arg1", "--arg2"]
+            LOCAL_CMD_ARGS_EXPECTED = [
+                sys.executable,
+                "-m",
+                "torch.distributed.run",
+                *torchrun_local_args_expected,
+                f"--nproc_per_node={NUM_PROCS}",
+                TRAIN_FILE_PATH,
+                *local_mode_version_args,
+                "-deepspeed",
+                "--deepspeed_config",
+                DEEPSPEED_CONF,
+            ]
+
+            local_cmd_with_args = 
DeepspeedTorchDistributor._create_torchrun_command(
+                input_params, TRAIN_FILE_PATH, *local_mode_version_args
+            )
+            self.assertEqual(local_cmd_with_args, LOCAL_CMD_ARGS_EXPECTED)
+
+    def test_create_torchrun_command_distributed(self):
+        DEEPSPEED_CONF = "path/to/deepspeed"
+        TRAIN_FILE_PATH = "path/to/exec"
+        NUM_PROCS = 10
+        input_params = {}
+        input_params["local_mode"] = True
+        input_params["num_processes"] = NUM_PROCS
+        input_params["deepspeed_config"] = DEEPSPEED_CONF
+        # distributed training environment
+        (
+            distributed_master_address,
+            distributed_master_port,
+            distributed_rank,
+        ) = self._get_env_variables_distributed()
+        distributed_torchrun_args = [
+            f"--nnodes={NUM_PROCS}",
+            f"--node_rank={distributed_rank}",
+            
f"--rdzv_endpoint={distributed_master_address}:{distributed_master_port}",
+            "--rdzv_id=0",
+        ]
+        with self.subTest(msg="Distributed training command verification with 
no extra args"):
+            DISTRIBUTED_CMD_NO_ARGS_EXPECTED = [
+                sys.executable,
+                "-m",
+                "torch.distributed.run",
+                *distributed_torchrun_args,
+                "--nproc_per_node=1",
+                TRAIN_FILE_PATH,
+                "-deepspeed",
+                "--deepspeed_config",
+                DEEPSPEED_CONF,
+            ]
+            # test distributed training without arguments
+            input_params["local_mode"] = False
+            distributed_command = 
DeepspeedTorchDistributor._create_torchrun_command(
+                input_params, TRAIN_FILE_PATH
+            )
+            self.assertEqual(DISTRIBUTED_CMD_NO_ARGS_EXPECTED, 
distributed_command)
+        with self.subTest(msg="Distributed training command verification with 
extra arguments"):
+            # test distributed training with random arguments

Review Comment:
   What do you mean random? I think this comment can be removed since the 
subtest message is descriptive



##########
python/pyspark/ml/torch/distributor.py:
##########
@@ -155,10 +155,7 @@ class Distributor:
     """
 
     def __init__(
-        self,
-        num_processes: int = 1,
-        local_mode: bool = True,
-        use_gpu: bool = True,
+        self, num_processes: int = 1, local_mode: bool = True, use_gpu: bool = 
True, ssl_conf=None

Review Comment:
   Keep this at one arg per line



##########
python/pyspark/ml/torch/deepspeed/deepspeed_distributor.py:
##########
@@ -0,0 +1,143 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import json
+import os
+import sys
+import tempfile
+from typing import (
+    Union,
+    Callable,
+    List,
+    Dict,
+    Optional,
+    Any,
+    Tuple,
+)
+
+from pyspark.ml.torch.distributor import TorchDistributor
+
+
+class DeepspeedTorchDistributor(TorchDistributor):
+    def __init__(
+        self,
+        num_gpus: int = 1,
+        nnodes: int = 1,
+        local_mode: bool = True,
+        use_gpu: bool = True,
+        deepspeed_config=None,
+    ):
+        """
+        This class is used to run deepspeed training workloads with spark 
clusters. The user has the option to
+        specify the number of gpus per node and the number of nodes (the same 
as if running from terminal),
+        as well as specify a deepspeed configuration file.
+
+        Parameters
+        ----------
+        num_gpus: int
+            The number of GPUs to use per node (analagous to num_gpus in 
deepspeed command).
+
+        nnodes: int
+            The number of nodes that should be used for the run.
+
+        local_mode: bool
+            Whether or not to run the training in a distributed fashion or 
just locally.
+
+        use_gpu: bool
+            Boolean flag to determine whether to utilize gpus.
+
+        deepspeed_config: Union[Dict[str,Any], str] or None:
+            The configuration file to be used for launching the deepspeed 
application.
+            If it is a dictionary mapping parameters to values, then we will 
create the file.
+            If None, deepspeed will fall back to default parameters.
+        """
+        num_processes = num_gpus * nnodes
+        DEEPSPEED_SSL_CONF = "deepspeed.spark.distributor.ignoreSsl"
+        self.deepspeed_config = deepspeed_config
+        super().__init__(num_processes, local_mode, use_gpu, 
_ssl_conf=DEEPSPEED_SSL_CONF)
+        self.cleanup_deepspeed_conf = False
+
+    @staticmethod
+    def _get_deepspeed_config_path(deepspeed_config):
+        if isinstance(deepspeed_config, dict):
+            with tempfile.NamedTemporaryFile(mode="w+", delete=False, 
suffix=".json") as fil:

Review Comment:
   Can you rename "fil" to "f" or "file"



##########
python/pyspark/ml/torch/deepspeed/tests/test_deepspeed_distributor.py:
##########
@@ -0,0 +1,180 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import os
+import sys
+from typing import List, Any, Callable, Dict
+import unittest
+
+from pyspark.ml.torch.deepspeed.deepspeed_distributor import 
DeepspeedTorchDistributor
+
+
+class DeepspeedTorchDistributorUnitTests(unittest.TestCase):
+    def _get_env_var(self, var_name: str, default_value: Any) -> Any:
+        value = os.getenv(var_name)
+        if value:
+            return value
+        os.environ[var_name] = str(default_value)
+        return default_value
+
+    def _get_env_variables_distributed(self):
+        MASTER_ADDR = self._get_env_var("MASTER_ADDR", "127.0.0.1")
+        MASTER_PORT = self._get_env_var("MASTER_PORT", 2000)
+        RANK = self._get_env_var("RANK", 0)
+        return MASTER_ADDR, MASTER_PORT, RANK
+
+    def test_get_torchrun_args_local(self):
+        number_of_processes = 5
+        EXPECTED_TORCHRUN_ARGS_LOCAL = ["--standalone", "--nnodes=1"]
+        EXPECTED_PROCESSES_PER_NODE_LOCAL = number_of_processes
+        (
+            get_local_mode_torchrun_args,
+            process_per_node,
+        ) = DeepspeedTorchDistributor._get_torchrun_args(True, 
number_of_processes)
+        self.assertEqual(get_local_mode_torchrun_args, 
EXPECTED_TORCHRUN_ARGS_LOCAL)
+        self.assertEqual(EXPECTED_PROCESSES_PER_NODE_LOCAL, process_per_node)
+
+    def test_get_torchrun_args_distributed(self):
+        number_of_processes = 5
+        MASTER_ADDR, MASTER_PORT, RANK = self._get_env_variables_distributed()
+        EXPECTED_TORCHRUN_ARGS_DISTRIBUTED = [
+            f"--nnodes={number_of_processes}",
+            f"--node_rank={RANK}",
+            f"--rdzv_endpoint={MASTER_ADDR}:{MASTER_PORT}",
+            "--rdzv_id=0",
+        ]
+        torchrun_args_distributed, process_per_node = 
DeepspeedTorchDistributor._get_torchrun_args(
+            False, number_of_processes
+        )
+        self.assertEqual(torchrun_args_distributed, 
EXPECTED_TORCHRUN_ARGS_DISTRIBUTED)
+        self.assertEqual(process_per_node, 1)
+
+    def test_create_torchrun_command_local(self):
+        DEEPSPEED_CONF = "path/to/deepspeed"
+        TRAIN_FILE_PATH = "path/to/exec"
+        NUM_PROCS = 10
+        input_params = {}
+        input_params["local_mode"] = True
+        input_params["num_processes"] = NUM_PROCS
+        input_params["deepspeed_config"] = DEEPSPEED_CONF
+
+        # get the arguments for no argument, local run
+        torchrun_local_args_expected = ["--standalone", "--nnodes=1"]
+        with self.subTest(msg="Testing local training with no extra args"):
+            LOCAL_CMD_NO_ARGS_EXPECTED = [
+                sys.executable,
+                "-m",
+                "torch.distributed.run",
+                *torchrun_local_args_expected,
+                f"--nproc_per_node={NUM_PROCS}",
+                TRAIN_FILE_PATH,
+                "-deepspeed",
+                "--deepspeed_config",
+                DEEPSPEED_CONF,
+            ]
+            local_cmd = DeepspeedTorchDistributor._create_torchrun_command(
+                input_params, TRAIN_FILE_PATH
+            )
+            self.assertEqual(local_cmd, LOCAL_CMD_NO_ARGS_EXPECTED)
+        with self.subTest(msg="Testing local training with extra args for the 
training script"):
+            local_mode_version_args = ["--arg1", "--arg2"]
+            LOCAL_CMD_ARGS_EXPECTED = [
+                sys.executable,
+                "-m",
+                "torch.distributed.run",
+                *torchrun_local_args_expected,
+                f"--nproc_per_node={NUM_PROCS}",
+                TRAIN_FILE_PATH,
+                *local_mode_version_args,
+                "-deepspeed",
+                "--deepspeed_config",
+                DEEPSPEED_CONF,
+            ]
+
+            local_cmd_with_args = 
DeepspeedTorchDistributor._create_torchrun_command(
+                input_params, TRAIN_FILE_PATH, *local_mode_version_args
+            )
+            self.assertEqual(local_cmd_with_args, LOCAL_CMD_ARGS_EXPECTED)
+
+    def test_create_torchrun_command_distributed(self):
+        DEEPSPEED_CONF = "path/to/deepspeed"
+        TRAIN_FILE_PATH = "path/to/exec"
+        NUM_PROCS = 10
+        input_params = {}
+        input_params["local_mode"] = True
+        input_params["num_processes"] = NUM_PROCS
+        input_params["deepspeed_config"] = DEEPSPEED_CONF
+        # distributed training environment
+        (
+            distributed_master_address,
+            distributed_master_port,
+            distributed_rank,
+        ) = self._get_env_variables_distributed()
+        distributed_torchrun_args = [
+            f"--nnodes={NUM_PROCS}",
+            f"--node_rank={distributed_rank}",
+            
f"--rdzv_endpoint={distributed_master_address}:{distributed_master_port}",
+            "--rdzv_id=0",
+        ]
+        with self.subTest(msg="Distributed training command verification with 
no extra args"):
+            DISTRIBUTED_CMD_NO_ARGS_EXPECTED = [
+                sys.executable,
+                "-m",
+                "torch.distributed.run",
+                *distributed_torchrun_args,
+                "--nproc_per_node=1",
+                TRAIN_FILE_PATH,
+                "-deepspeed",
+                "--deepspeed_config",
+                DEEPSPEED_CONF,
+            ]
+            # test distributed training without arguments

Review Comment:
   Can remove this comment



##########
python/pyspark/ml/torch/deepspeed/tests/test_deepspeed_distributor.py:
##########
@@ -0,0 +1,180 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import os
+import sys
+from typing import List, Any, Callable, Dict
+import unittest
+
+from pyspark.ml.torch.deepspeed.deepspeed_distributor import 
DeepspeedTorchDistributor
+
+
+class DeepspeedTorchDistributorUnitTests(unittest.TestCase):
+    def _get_env_var(self, var_name: str, default_value: Any) -> Any:
+        value = os.getenv(var_name)
+        if value:
+            return value
+        os.environ[var_name] = str(default_value)
+        return default_value
+
+    def _get_env_variables_distributed(self):
+        MASTER_ADDR = self._get_env_var("MASTER_ADDR", "127.0.0.1")
+        MASTER_PORT = self._get_env_var("MASTER_PORT", 2000)
+        RANK = self._get_env_var("RANK", 0)
+        return MASTER_ADDR, MASTER_PORT, RANK
+
+    def test_get_torchrun_args_local(self):
+        number_of_processes = 5
+        EXPECTED_TORCHRUN_ARGS_LOCAL = ["--standalone", "--nnodes=1"]
+        EXPECTED_PROCESSES_PER_NODE_LOCAL = number_of_processes
+        (
+            get_local_mode_torchrun_args,
+            process_per_node,
+        ) = DeepspeedTorchDistributor._get_torchrun_args(True, 
number_of_processes)
+        self.assertEqual(get_local_mode_torchrun_args, 
EXPECTED_TORCHRUN_ARGS_LOCAL)
+        self.assertEqual(EXPECTED_PROCESSES_PER_NODE_LOCAL, process_per_node)
+
+    def test_get_torchrun_args_distributed(self):
+        number_of_processes = 5
+        MASTER_ADDR, MASTER_PORT, RANK = self._get_env_variables_distributed()
+        EXPECTED_TORCHRUN_ARGS_DISTRIBUTED = [
+            f"--nnodes={number_of_processes}",
+            f"--node_rank={RANK}",
+            f"--rdzv_endpoint={MASTER_ADDR}:{MASTER_PORT}",
+            "--rdzv_id=0",
+        ]
+        torchrun_args_distributed, process_per_node = 
DeepspeedTorchDistributor._get_torchrun_args(
+            False, number_of_processes
+        )
+        self.assertEqual(torchrun_args_distributed, 
EXPECTED_TORCHRUN_ARGS_DISTRIBUTED)
+        self.assertEqual(process_per_node, 1)
+
+    def test_create_torchrun_command_local(self):
+        DEEPSPEED_CONF = "path/to/deepspeed"
+        TRAIN_FILE_PATH = "path/to/exec"
+        NUM_PROCS = 10
+        input_params = {}
+        input_params["local_mode"] = True
+        input_params["num_processes"] = NUM_PROCS
+        input_params["deepspeed_config"] = DEEPSPEED_CONF
+
+        # get the arguments for no argument, local run
+        torchrun_local_args_expected = ["--standalone", "--nnodes=1"]
+        with self.subTest(msg="Testing local training with no extra args"):
+            LOCAL_CMD_NO_ARGS_EXPECTED = [
+                sys.executable,
+                "-m",
+                "torch.distributed.run",
+                *torchrun_local_args_expected,
+                f"--nproc_per_node={NUM_PROCS}",
+                TRAIN_FILE_PATH,
+                "-deepspeed",
+                "--deepspeed_config",
+                DEEPSPEED_CONF,
+            ]
+            local_cmd = DeepspeedTorchDistributor._create_torchrun_command(
+                input_params, TRAIN_FILE_PATH
+            )
+            self.assertEqual(local_cmd, LOCAL_CMD_NO_ARGS_EXPECTED)
+        with self.subTest(msg="Testing local training with extra args for the 
training script"):
+            local_mode_version_args = ["--arg1", "--arg2"]
+            LOCAL_CMD_ARGS_EXPECTED = [
+                sys.executable,
+                "-m",
+                "torch.distributed.run",
+                *torchrun_local_args_expected,
+                f"--nproc_per_node={NUM_PROCS}",
+                TRAIN_FILE_PATH,
+                *local_mode_version_args,
+                "-deepspeed",
+                "--deepspeed_config",
+                DEEPSPEED_CONF,
+            ]
+
+            local_cmd_with_args = 
DeepspeedTorchDistributor._create_torchrun_command(
+                input_params, TRAIN_FILE_PATH, *local_mode_version_args
+            )
+            self.assertEqual(local_cmd_with_args, LOCAL_CMD_ARGS_EXPECTED)
+
+    def test_create_torchrun_command_distributed(self):
+        DEEPSPEED_CONF = "path/to/deepspeed"
+        TRAIN_FILE_PATH = "path/to/exec"
+        NUM_PROCS = 10
+        input_params = {}
+        input_params["local_mode"] = True
+        input_params["num_processes"] = NUM_PROCS
+        input_params["deepspeed_config"] = DEEPSPEED_CONF
+        # distributed training environment

Review Comment:
   Can remove this comment



##########
python/pyspark/ml/torch/deepspeed/tests/test_deepspeed_distributor.py:
##########
@@ -0,0 +1,180 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import os
+import sys
+from typing import List, Any, Callable, Dict
+import unittest
+
+from pyspark.ml.torch.deepspeed.deepspeed_distributor import 
DeepspeedTorchDistributor
+
+
+class DeepspeedTorchDistributorUnitTests(unittest.TestCase):
+    def _get_env_var(self, var_name: str, default_value: Any) -> Any:
+        value = os.getenv(var_name)
+        if value:
+            return value
+        os.environ[var_name] = str(default_value)
+        return default_value
+
+    def _get_env_variables_distributed(self):
+        MASTER_ADDR = self._get_env_var("MASTER_ADDR", "127.0.0.1")
+        MASTER_PORT = self._get_env_var("MASTER_PORT", 2000)
+        RANK = self._get_env_var("RANK", 0)
+        return MASTER_ADDR, MASTER_PORT, RANK
+
+    def test_get_torchrun_args_local(self):
+        number_of_processes = 5
+        EXPECTED_TORCHRUN_ARGS_LOCAL = ["--standalone", "--nnodes=1"]
+        EXPECTED_PROCESSES_PER_NODE_LOCAL = number_of_processes
+        (
+            get_local_mode_torchrun_args,
+            process_per_node,
+        ) = DeepspeedTorchDistributor._get_torchrun_args(True, 
number_of_processes)
+        self.assertEqual(get_local_mode_torchrun_args, 
EXPECTED_TORCHRUN_ARGS_LOCAL)
+        self.assertEqual(EXPECTED_PROCESSES_PER_NODE_LOCAL, process_per_node)
+
+    def test_get_torchrun_args_distributed(self):
+        number_of_processes = 5
+        MASTER_ADDR, MASTER_PORT, RANK = self._get_env_variables_distributed()
+        EXPECTED_TORCHRUN_ARGS_DISTRIBUTED = [
+            f"--nnodes={number_of_processes}",
+            f"--node_rank={RANK}",
+            f"--rdzv_endpoint={MASTER_ADDR}:{MASTER_PORT}",
+            "--rdzv_id=0",
+        ]
+        torchrun_args_distributed, process_per_node = 
DeepspeedTorchDistributor._get_torchrun_args(
+            False, number_of_processes
+        )
+        self.assertEqual(torchrun_args_distributed, 
EXPECTED_TORCHRUN_ARGS_DISTRIBUTED)
+        self.assertEqual(process_per_node, 1)
+
+    def test_create_torchrun_command_local(self):
+        DEEPSPEED_CONF = "path/to/deepspeed"
+        TRAIN_FILE_PATH = "path/to/exec"
+        NUM_PROCS = 10
+        input_params = {}
+        input_params["local_mode"] = True
+        input_params["num_processes"] = NUM_PROCS
+        input_params["deepspeed_config"] = DEEPSPEED_CONF
+
+        # get the arguments for no argument, local run

Review Comment:
   Can remove this comment



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to