From e54f3d8da4c4b97d405f7e60749547c3d91c30c1 Mon Sep 17 00:00:00 2001 From: Anson Qian Date: Sat, 17 Jan 2026 16:11:46 -0500 Subject: [PATCH 1/4] fix: update values for gpu operator network operator --- modules/python/gpu/cfg/{gpu => gpu-operator}/values.yaml | 0 .../gpu/cfg/{net => network-operator}/nfd-network-rule.yaml | 0 .../gpu/cfg/{net => network-operator}/nic-cluster-policy.yaml | 0 modules/python/gpu/cfg/{net => network-operator}/values.yaml | 0 modules/python/gpu/pkg/net.py | 4 ++-- 5 files changed, 2 insertions(+), 2 deletions(-) rename modules/python/gpu/cfg/{gpu => gpu-operator}/values.yaml (100%) rename modules/python/gpu/cfg/{net => network-operator}/nfd-network-rule.yaml (100%) rename modules/python/gpu/cfg/{net => network-operator}/nic-cluster-policy.yaml (100%) rename modules/python/gpu/cfg/{net => network-operator}/values.yaml (100%) diff --git a/modules/python/gpu/cfg/gpu/values.yaml b/modules/python/gpu/cfg/gpu-operator/values.yaml similarity index 100% rename from modules/python/gpu/cfg/gpu/values.yaml rename to modules/python/gpu/cfg/gpu-operator/values.yaml diff --git a/modules/python/gpu/cfg/net/nfd-network-rule.yaml b/modules/python/gpu/cfg/network-operator/nfd-network-rule.yaml similarity index 100% rename from modules/python/gpu/cfg/net/nfd-network-rule.yaml rename to modules/python/gpu/cfg/network-operator/nfd-network-rule.yaml diff --git a/modules/python/gpu/cfg/net/nic-cluster-policy.yaml b/modules/python/gpu/cfg/network-operator/nic-cluster-policy.yaml similarity index 100% rename from modules/python/gpu/cfg/net/nic-cluster-policy.yaml rename to modules/python/gpu/cfg/network-operator/nic-cluster-policy.yaml diff --git a/modules/python/gpu/cfg/net/values.yaml b/modules/python/gpu/cfg/network-operator/values.yaml similarity index 100% rename from modules/python/gpu/cfg/net/values.yaml rename to modules/python/gpu/cfg/network-operator/values.yaml diff --git a/modules/python/gpu/pkg/net.py b/modules/python/gpu/pkg/net.py index bdfe2db6de..9fac527b3c 100644 --- a/modules/python/gpu/pkg/net.py +++ b/modules/python/gpu/pkg/net.py @@ -54,9 +54,9 @@ def install_network_operator( operation_timeout_in_minutes=5, ) - nfd_file = f"{config_dir}/net/nfd-network-rule.yaml" + nfd_file = f"{config_dir}/network-operator/nfd-network-rule.yaml" KUBERNETES_CLIENT.apply_manifest_from_file(nfd_file) - nic_file = f"{config_dir}/net/nic-cluster-policy.yaml" + nic_file = f"{config_dir}/network-operator/nic-cluster-policy.yaml" KUBERNETES_CLIENT.apply_manifest_from_file(nic_file) execute_with_retries( KUBERNETES_CLIENT.wait_for_pods_ready, From 9f4a1a7614473d2407742432f51f9785add00432 Mon Sep 17 00:00:00 2001 From: Anson Qian Date: Sat, 17 Jan 2026 17:08:08 -0500 Subject: [PATCH 2/4] refactor MPI operator configuration and add new job templates --- .../gpu/cfg/{mpi => mpi-operator}/aws-job.yaml | 0 .../{mpi => mpi-operator}/azure-job-hostpath.yaml | 0 .../{mpi => mpi-operator}/azure-job-sriov.yaml | 0 .../{mpi => mpi-operator}/azure-job-topology.yaml | 0 modules/python/gpu/cfg/mpi-operator/values.yaml | 2 ++ modules/python/gpu/main.py | 8 ++++---- modules/python/gpu/pkg/mpi.py | 15 ++++++++++++--- 7 files changed, 18 insertions(+), 7 deletions(-) rename modules/python/gpu/cfg/{mpi => mpi-operator}/aws-job.yaml (100%) rename modules/python/gpu/cfg/{mpi => mpi-operator}/azure-job-hostpath.yaml (100%) rename modules/python/gpu/cfg/{mpi => mpi-operator}/azure-job-sriov.yaml (100%) rename modules/python/gpu/cfg/{mpi => mpi-operator}/azure-job-topology.yaml (100%) create mode 100644 modules/python/gpu/cfg/mpi-operator/values.yaml diff --git a/modules/python/gpu/cfg/mpi/aws-job.yaml b/modules/python/gpu/cfg/mpi-operator/aws-job.yaml similarity index 100% rename from modules/python/gpu/cfg/mpi/aws-job.yaml rename to modules/python/gpu/cfg/mpi-operator/aws-job.yaml diff --git a/modules/python/gpu/cfg/mpi/azure-job-hostpath.yaml b/modules/python/gpu/cfg/mpi-operator/azure-job-hostpath.yaml similarity index 100% rename from modules/python/gpu/cfg/mpi/azure-job-hostpath.yaml rename to modules/python/gpu/cfg/mpi-operator/azure-job-hostpath.yaml diff --git a/modules/python/gpu/cfg/mpi/azure-job-sriov.yaml b/modules/python/gpu/cfg/mpi-operator/azure-job-sriov.yaml similarity index 100% rename from modules/python/gpu/cfg/mpi/azure-job-sriov.yaml rename to modules/python/gpu/cfg/mpi-operator/azure-job-sriov.yaml diff --git a/modules/python/gpu/cfg/mpi/azure-job-topology.yaml b/modules/python/gpu/cfg/mpi-operator/azure-job-topology.yaml similarity index 100% rename from modules/python/gpu/cfg/mpi/azure-job-topology.yaml rename to modules/python/gpu/cfg/mpi-operator/azure-job-topology.yaml diff --git a/modules/python/gpu/cfg/mpi-operator/values.yaml b/modules/python/gpu/cfg/mpi-operator/values.yaml new file mode 100644 index 0000000000..ca4e6d2bc4 --- /dev/null +++ b/modules/python/gpu/cfg/mpi-operator/values.yaml @@ -0,0 +1,2 @@ +# MPI Operator Helm Chart Values +# Add custom values here if needed diff --git a/modules/python/gpu/main.py b/modules/python/gpu/main.py index 67d7473c74..cf40551713 100644 --- a/modules/python/gpu/main.py +++ b/modules/python/gpu/main.py @@ -57,7 +57,7 @@ def configure( enable_nfd=gpu_enable_nfd, ) if mpi_operator_version: - install_mpi_operator(chart_version=mpi_operator_version) + install_mpi_operator(chart_version=mpi_operator_version, config_dir=config_dir) def execute( @@ -123,21 +123,21 @@ def execute( logger.info("No SR-IOV device plugin found, using hostPath for InfiniBand") job_type = "hostpath" - nccl_file = f"{config_dir}/mpi/azure-job-{job_type}.yaml" + nccl_file = f"{config_dir}/mpi-operator/azure-job-{job_type}.yaml" logger.info(f"Running nccl-tests with {replacements} using {nccl_file}") nccl_template = KUBERNETES_CLIENT.create_template(nccl_file, replacements) nccl_dict = yaml.safe_load(nccl_template) KUBERNETES_CLIENT.apply_manifest_from_file(manifest_dict=nccl_dict) elif provider.lower() == "aws": replacements["efa_allocatable"] = efa_allocatable - nccl_file = f"{config_dir}/mpi/{provider}-job.yaml" + nccl_file = f"{config_dir}/mpi-operator/{provider}-job.yaml" logger.info(f"Running nccl-tests with {replacements} using {nccl_file}") nccl_template = KUBERNETES_CLIENT.create_template(nccl_file, replacements) nccl_dict = yaml.safe_load(nccl_template) KUBERNETES_CLIENT.apply_manifest_from_file(manifest_dict=nccl_dict) else: - nccl_file = f"{config_dir}/mpi/{provider}-job.yaml" + nccl_file = f"{config_dir}/mpi-operator/{provider}-job.yaml" logger.info(f"Running nccl-tests with {replacements} using {nccl_file}") nccl_template = KUBERNETES_CLIENT.create_template(nccl_file, replacements) diff --git a/modules/python/gpu/pkg/mpi.py b/modules/python/gpu/pkg/mpi.py index 31b74cc418..2e69191fd7 100644 --- a/modules/python/gpu/pkg/mpi.py +++ b/modules/python/gpu/pkg/mpi.py @@ -7,6 +7,7 @@ from utils.logger_config import get_logger, setup_logging from utils.retries import execute_with_retries from clients.kubernetes_client import KubernetesClient +from .utils import install_operator # Configure logging setup_logging() @@ -16,15 +17,23 @@ def install_mpi_operator( chart_version: str, + config_dir: str, ) -> None: """ Install MPI Operator using Helm Args: - chart_version: Specific chart version to install + chart_version: Specific chart version to install (e.g., "0.5.0") + config_dir: Directory containing custom configuration files """ - mpi_file = f"https://raw.githubusercontent.com/kubeflow/mpi-operator/{chart_version}/deploy/v2beta1/mpi-operator.yaml" - KUBERNETES_CLIENT.apply_manifest_from_url(mpi_file) + install_operator( + chart_version=chart_version, + operator_name="mpi-operator", + config_dir=config_dir, + namespace="mpi-operator", + repo_name="v3io-stable", + repo_url="https://v3io.github.io/helm-charts/stable", + ) execute_with_retries( KUBERNETES_CLIENT.wait_for_pods_ready, label_selector="app.kubernetes.io/name=mpi-operator", From f81a82d4a4dcfb0551d905de5e6fa10159e4e54e Mon Sep 17 00:00:00 2001 From: Anson Qian Date: Wed, 4 Feb 2026 01:56:43 +0000 Subject: [PATCH 3/4] fix unit test --- modules/python/tests/gpu/test_gpu.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/modules/python/tests/gpu/test_gpu.py b/modules/python/tests/gpu/test_gpu.py index bcbf046efe..e98a92850e 100644 --- a/modules/python/tests/gpu/test_gpu.py +++ b/modules/python/tests/gpu/test_gpu.py @@ -216,18 +216,25 @@ def test_install_gpu_operator_success( self.assertEqual(_mock_execute_with_retries.call_count, 4) @patch("gpu.pkg.mpi.execute_with_retries") - @patch("gpu.pkg.mpi.KUBERNETES_CLIENT") + @patch("gpu.pkg.mpi.install_operator") def test_install_mpi_operator_success( - self, mock_k8s_client, _mock_execute_with_retries + self, mock_install, _mock_execute_with_retries ): """Test successful MPI operator installation.""" - mock_k8s_client.apply_manifest_from_url.return_value = None _mock_execute_with_retries.return_value = None - install_mpi_operator(chart_version=self.test_chart_version) + install_mpi_operator( + chart_version=self.test_chart_version, config_dir=self.test_config_dir + ) - expected_url = f"https://raw.githubusercontent.com/kubeflow/mpi-operator/{self.test_chart_version}/deploy/v2beta1/mpi-operator.yaml" - mock_k8s_client.apply_manifest_from_url.assert_called_once_with(expected_url) + mock_install.assert_called_once_with( + chart_version=self.test_chart_version, + operator_name="mpi-operator", + config_dir=self.test_config_dir, + namespace="mpi-operator", + repo_name="v3io-stable", + repo_url="https://v3io.github.io/helm-charts/stable", + ) # Verify execute_with_retries is called once for the wait operation _mock_execute_with_retries.assert_called_once() @@ -285,7 +292,9 @@ def test_configure_all_operators(self, mock_network, mock_gpu, mock_mpi, mock_ef install_driver=True, enable_nfd=False, ) - mock_mpi.assert_called_once_with(chart_version=self.test_chart_version) + mock_mpi.assert_called_once_with( + chart_version=self.test_chart_version, config_dir=self.test_config_dir + ) @patch("gpu.main.install_efa_operator") @patch("gpu.main.install_mpi_operator") @@ -338,7 +347,9 @@ def test_configure_both_network_and_mpi_operator( chart_version=self.test_chart_version, config_dir=self.test_config_dir ) mock_gpu.assert_not_called() - mock_mpi.assert_called_once_with(chart_version=self.test_chart_version) + mock_mpi.assert_called_once_with( + chart_version=self.test_chart_version, config_dir=self.test_config_dir + ) @patch("gpu.main.install_efa_operator") @patch("gpu.main.install_mpi_operator") From 699e45cf7632bbf1b589c5242fb0b980d20ea87a Mon Sep 17 00:00:00 2001 From: Anson Qian Date: Thu, 5 Feb 2026 03:54:06 +0000 Subject: [PATCH 4/4] fix: update MPI operator configuration to use v1 API and correct namespaces --- .../python/gpu/cfg/mpi-operator/aws-job.yaml | 2 +- .../cfg/mpi-operator/azure-job-hostpath.yaml | 2 +- .../gpu/cfg/mpi-operator/azure-job-sriov.yaml | 2 +- .../cfg/mpi-operator/azure-job-topology.yaml | 2 +- .../python/gpu/cfg/mpi-operator/values.yaml | 2 -- modules/python/gpu/main.py | 7 +++--- modules/python/gpu/pkg/mpi.py | 15 +++--------- modules/python/gpu/pkg/utils.py | 12 +++++++++- modules/python/tests/gpu/test_gpu.py | 23 ++++++++----------- 9 files changed, 32 insertions(+), 35 deletions(-) delete mode 100644 modules/python/gpu/cfg/mpi-operator/values.yaml diff --git a/modules/python/gpu/cfg/mpi-operator/aws-job.yaml b/modules/python/gpu/cfg/mpi-operator/aws-job.yaml index 17e84e9e67..bad5de401a 100644 --- a/modules/python/gpu/cfg/mpi-operator/aws-job.yaml +++ b/modules/python/gpu/cfg/mpi-operator/aws-job.yaml @@ -1,7 +1,7 @@ apiVersion: kubeflow.org/v2beta1 kind: MPIJob metadata: - namespace: default + namespace: mpi-operator name: nccl-tests labels: app: nccl-tests diff --git a/modules/python/gpu/cfg/mpi-operator/azure-job-hostpath.yaml b/modules/python/gpu/cfg/mpi-operator/azure-job-hostpath.yaml index 8278c8a0a6..dc66b55bf2 100644 --- a/modules/python/gpu/cfg/mpi-operator/azure-job-hostpath.yaml +++ b/modules/python/gpu/cfg/mpi-operator/azure-job-hostpath.yaml @@ -1,7 +1,7 @@ apiVersion: kubeflow.org/v2beta1 kind: MPIJob metadata: - namespace: default + namespace: mpi-operator name: nccl-tests labels: app: nccl-tests diff --git a/modules/python/gpu/cfg/mpi-operator/azure-job-sriov.yaml b/modules/python/gpu/cfg/mpi-operator/azure-job-sriov.yaml index b676fe898f..9895b5fabd 100644 --- a/modules/python/gpu/cfg/mpi-operator/azure-job-sriov.yaml +++ b/modules/python/gpu/cfg/mpi-operator/azure-job-sriov.yaml @@ -1,7 +1,7 @@ apiVersion: kubeflow.org/v2beta1 kind: MPIJob metadata: - namespace: default + namespace: mpi-operator name: nccl-tests labels: app: nccl-tests diff --git a/modules/python/gpu/cfg/mpi-operator/azure-job-topology.yaml b/modules/python/gpu/cfg/mpi-operator/azure-job-topology.yaml index 542086949f..a6b9e1cc27 100644 --- a/modules/python/gpu/cfg/mpi-operator/azure-job-topology.yaml +++ b/modules/python/gpu/cfg/mpi-operator/azure-job-topology.yaml @@ -1,7 +1,7 @@ apiVersion: kubeflow.org/v2beta1 kind: MPIJob metadata: - namespace: default + namespace: mpi-operator name: nccl-tests labels: app: nccl-tests diff --git a/modules/python/gpu/cfg/mpi-operator/values.yaml b/modules/python/gpu/cfg/mpi-operator/values.yaml deleted file mode 100644 index ca4e6d2bc4..0000000000 --- a/modules/python/gpu/cfg/mpi-operator/values.yaml +++ /dev/null @@ -1,2 +0,0 @@ -# MPI Operator Helm Chart Values -# Add custom values here if needed diff --git a/modules/python/gpu/main.py b/modules/python/gpu/main.py index cf40551713..a47cb3845a 100644 --- a/modules/python/gpu/main.py +++ b/modules/python/gpu/main.py @@ -57,7 +57,7 @@ def configure( enable_nfd=gpu_enable_nfd, ) if mpi_operator_version: - install_mpi_operator(chart_version=mpi_operator_version, config_dir=config_dir) + install_mpi_operator(chart_version=mpi_operator_version) def execute( @@ -93,7 +93,7 @@ def execute( try: subprocess.run( - ["kubectl", "delete", "mpijob", "nccl-tests", "-n", "default", "--ignore-not-found=true"], + ["kubectl", "delete", "mpijob", "nccl-tests", "-n", "mpi-operator", "--ignore-not-found=true"], check=True, capture_output=True, text=True @@ -147,9 +147,10 @@ def execute( KUBERNETES_CLIENT.wait_for_pods_completed, label_selector="component=launcher", pod_count=1, + namespace="mpi-operator", ) pod_name = pods[0].metadata.name - raw_logs = KUBERNETES_CLIENT.get_pod_logs(pod_name) + raw_logs = KUBERNETES_CLIENT.get_pod_logs(pod_name, namespace="mpi-operator") logs = raw_logs.decode("utf-8") logger.info(f"Getting logs for pod {pod_name}:\n{logs}") result_path = f"{result_dir}/raw.log" diff --git a/modules/python/gpu/pkg/mpi.py b/modules/python/gpu/pkg/mpi.py index 2e69191fd7..affc33547c 100644 --- a/modules/python/gpu/pkg/mpi.py +++ b/modules/python/gpu/pkg/mpi.py @@ -7,7 +7,6 @@ from utils.logger_config import get_logger, setup_logging from utils.retries import execute_with_retries from clients.kubernetes_client import KubernetesClient -from .utils import install_operator # Configure logging setup_logging() @@ -17,26 +16,18 @@ def install_mpi_operator( chart_version: str, - config_dir: str, ) -> None: """ Install MPI Operator using Helm Args: chart_version: Specific chart version to install (e.g., "0.5.0") - config_dir: Directory containing custom configuration files """ - install_operator( - chart_version=chart_version, - operator_name="mpi-operator", - config_dir=config_dir, - namespace="mpi-operator", - repo_name="v3io-stable", - repo_url="https://v3io.github.io/helm-charts/stable", - ) + mpi_file = f"https://raw.githubusercontent.com/kubeflow/mpi-operator/{chart_version}/deploy/v2beta1/mpi-operator.yaml" + KUBERNETES_CLIENT.apply_manifest_from_url(mpi_file) execute_with_retries( KUBERNETES_CLIENT.wait_for_pods_ready, - label_selector="app.kubernetes.io/name=mpi-operator", + label_selector="app=mpi-operator", namespace="mpi-operator", operation_timeout_in_minutes=5, ) diff --git a/modules/python/gpu/pkg/utils.py b/modules/python/gpu/pkg/utils.py index bf600d8ba5..b3eb8fd1fc 100644 --- a/modules/python/gpu/pkg/utils.py +++ b/modules/python/gpu/pkg/utils.py @@ -265,12 +265,22 @@ def create_topology_configmap( # Create ConfigMap configmap_name = "nvidia-topology" + namespace = "mpi-operator" + + # Delete existing ConfigMap if it exists + try: + v1_api.delete_namespaced_config_map(name=configmap_name, namespace=namespace) + logger.info(f"Deleted existing ConfigMap '{configmap_name}'") + except client.ApiException as e: + if e.status != 404: + logger.warning(f"Error deleting ConfigMap: {e}") + logger.info(f"Creating ConfigMap from content:\n{topology_content}") configmap = client.V1ConfigMap( metadata=client.V1ObjectMeta(name=configmap_name), data={"topo.xml": topology_content}, ) - v1_api.create_namespaced_config_map(namespace="default", body=configmap) + v1_api.create_namespaced_config_map(namespace=namespace, body=configmap) logger.info(f"ConfigMap '{configmap_name}' created successfully") except requests.RequestException as e: diff --git a/modules/python/tests/gpu/test_gpu.py b/modules/python/tests/gpu/test_gpu.py index e98a92850e..f4ae74a626 100644 --- a/modules/python/tests/gpu/test_gpu.py +++ b/modules/python/tests/gpu/test_gpu.py @@ -216,25 +216,22 @@ def test_install_gpu_operator_success( self.assertEqual(_mock_execute_with_retries.call_count, 4) @patch("gpu.pkg.mpi.execute_with_retries") - @patch("gpu.pkg.mpi.install_operator") + @patch("gpu.pkg.mpi.KUBERNETES_CLIENT") def test_install_mpi_operator_success( - self, mock_install, _mock_execute_with_retries + self, mock_k8s_client, _mock_execute_with_retries ): """Test successful MPI operator installation.""" _mock_execute_with_retries.return_value = None + mock_k8s_client.apply_manifest_from_url.return_value = None install_mpi_operator( - chart_version=self.test_chart_version, config_dir=self.test_config_dir + chart_version=self.test_chart_version ) - mock_install.assert_called_once_with( - chart_version=self.test_chart_version, - operator_name="mpi-operator", - config_dir=self.test_config_dir, - namespace="mpi-operator", - repo_name="v3io-stable", - repo_url="https://v3io.github.io/helm-charts/stable", - ) + # Verify the manifest is applied from the correct URL + expected_url = f"https://raw.githubusercontent.com/kubeflow/mpi-operator/{self.test_chart_version}/deploy/v2beta1/mpi-operator.yaml" + mock_k8s_client.apply_manifest_from_url.assert_called_once_with(expected_url) + # Verify execute_with_retries is called once for the wait operation _mock_execute_with_retries.assert_called_once() @@ -293,7 +290,7 @@ def test_configure_all_operators(self, mock_network, mock_gpu, mock_mpi, mock_ef enable_nfd=False, ) mock_mpi.assert_called_once_with( - chart_version=self.test_chart_version, config_dir=self.test_config_dir + chart_version=self.test_chart_version ) @patch("gpu.main.install_efa_operator") @@ -348,7 +345,7 @@ def test_configure_both_network_and_mpi_operator( ) mock_gpu.assert_not_called() mock_mpi.assert_called_once_with( - chart_version=self.test_chart_version, config_dir=self.test_config_dir + chart_version=self.test_chart_version ) @patch("gpu.main.install_efa_operator")