-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Peng Wang <pengwang@nvidia.com>
- Loading branch information
1 parent
a9effd6
commit e8c1139
Showing
8 changed files
with
222 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES | ||
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed 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. | ||
|
||
from abc import abstractmethod | ||
from pathlib import Path | ||
from typing import Any, Dict, List | ||
|
||
from .test_template_strategy import TestTemplateStrategy | ||
|
||
|
||
class JsonGenStrategy(TestTemplateStrategy): | ||
""" | ||
Abstract base class for generating Kubernetes job specifications based on system and test parameters. | ||
It specifies how to generate JSON job specifications based on system and test parameters. | ||
""" | ||
|
||
@abstractmethod | ||
def gen_json( | ||
self, | ||
env_vars: Dict[str, str], | ||
cmd_args: Dict[str, str], | ||
extra_env_vars: Dict[str, str], | ||
extra_cmd_args: str, | ||
output_path: Path, | ||
job_name: str, | ||
num_nodes: int, | ||
nodes: List[str], | ||
) -> Dict[Any, Any]: | ||
""" | ||
Generate the Kubernetes job specification based on the given parameters. | ||
Args: | ||
env_vars (Dict[str, str]): Environment variables for the job. | ||
cmd_args (Dict[str, str]): Command-line arguments for the job. | ||
extra_env_vars (Dict[str, str]): Additional environment variables. | ||
extra_cmd_args (str): Additional command-line arguments. | ||
output_path (Path): Path to the output directory. | ||
job_name (str): The name of the job. | ||
num_nodes (int): The number of nodes to be used for job execution. | ||
nodes (List[str]): List of nodes for job execution, optional. | ||
Returns: | ||
Dict[Any, Any]: The generated Kubernetes job specification in JSON format. | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES | ||
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES | ||
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed 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 logging | ||
from typing import cast | ||
|
||
from cloudai import BaseJob, BaseRunner, Test | ||
from cloudai.systems import KubernetesSystem | ||
|
||
from .kubernetes_job import KubernetesJob | ||
|
||
|
||
class KubernetesRunner(BaseRunner): | ||
"""Implementation of the Runner for a system using Kubernetes.""" | ||
|
||
def _submit_test(self, test: Test) -> KubernetesJob: | ||
""" | ||
Submit a test for execution on Kubernetes and return a KubernetesJob object. | ||
Args: | ||
test (Test): The test to be executed. | ||
Returns: | ||
KubernetesJob: A KubernetesJob object containing job details. | ||
""" | ||
logging.info(f"Running test: {test.section_name}") | ||
job_output_path = self.get_job_output_path(test) | ||
job_name = test.section_name.replace(".", "-").lower() | ||
job_spec = test.gen_json(job_output_path, job_name) | ||
job_kind = job_spec.get("kind", "").lower() | ||
logging.info(f"Generated JSON string for test {test.section_name}: {job_spec}") | ||
job_namespace = "" | ||
|
||
if self.mode == "run": | ||
k8s_system: KubernetesSystem = cast(KubernetesSystem, self.system) | ||
job_name, job_namespace = k8s_system.create_job(job_spec) | ||
|
||
return KubernetesJob(self.mode, self.system, test, job_namespace, job_name, job_kind, job_output_path) | ||
|
||
def kill_job(self, job: BaseJob) -> None: | ||
""" | ||
Terminate a Kubernetes job. | ||
Args: | ||
job (BaseJob): The job to be terminated, casted to KubernetesJob. | ||
""" | ||
k8s_system = cast(KubernetesSystem, self.system) | ||
k_job = cast(KubernetesJob, job) | ||
k8s_system: KubernetesSystem = cast(KubernetesSystem, self.system) | ||
k8s_system.delete_job(k_job.get_namespace(), k_job.get_name(), k_job.get_kind()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters