|
| 1 | +# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES |
| 2 | +# Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +from typing import Optional, Union |
| 18 | + |
| 19 | +from cloudai.core import DockerImage, Installable, JobStatusResult, TestRun |
| 20 | +from cloudai.models.workload import CmdArgs, TestDefinition |
| 21 | + |
| 22 | + |
| 23 | +class DDLBCmdArgs(CmdArgs): |
| 24 | + """DDLB test command arguments.""" |
| 25 | + |
| 26 | + docker_image_url: str |
| 27 | + primitive: str |
| 28 | + m: Union[int, list[int]] = 1024 |
| 29 | + n: Union[int, list[int]] = 128 |
| 30 | + k: Union[int, list[int]] = 1024 |
| 31 | + dtype: str |
| 32 | + num_iterations: int = 50 |
| 33 | + num_warmups: int = 5 |
| 34 | + impl: Union[str, list[str]] = "pytorch;backend=nccl;order=AG_before" |
| 35 | + |
| 36 | + |
| 37 | +class DDLBTestDefinition(TestDefinition): |
| 38 | + """Test object for DDLB.""" |
| 39 | + |
| 40 | + cmd_args: DDLBCmdArgs |
| 41 | + _docker_image: Optional[DockerImage] = None |
| 42 | + |
| 43 | + @property |
| 44 | + def extra_args_str(self) -> str: |
| 45 | + parts = [] |
| 46 | + for k, v in self.extra_cmd_args.items(): |
| 47 | + parts.append(f"{k} {v}" if v else k) |
| 48 | + return " ".join(parts) |
| 49 | + |
| 50 | + @property |
| 51 | + def docker_image(self) -> DockerImage: |
| 52 | + if not self._docker_image: |
| 53 | + self._docker_image = DockerImage(url=self.cmd_args.docker_image_url) |
| 54 | + return self._docker_image |
| 55 | + |
| 56 | + @property |
| 57 | + def installables(self) -> list[Installable]: |
| 58 | + return [self.docker_image] |
| 59 | + |
| 60 | + def was_run_successful(self, tr: TestRun) -> JobStatusResult: |
| 61 | + stdout_path = tr.output_path / "stdout.txt" |
| 62 | + if stdout_path.is_file(): |
| 63 | + with stdout_path.open("r") as file: |
| 64 | + content = file.read() |
| 65 | + |
| 66 | + # Check for specific error patterns |
| 67 | + if "Error" in content: |
| 68 | + return JobStatusResult( |
| 69 | + is_successful=False, |
| 70 | + error_message=( |
| 71 | + f"DDLB test failure detected in {stdout_path}. " |
| 72 | + "Possible reasons include network errors or remote process exits. " |
| 73 | + "Please review the DDLB test output and errors in the file first. " |
| 74 | + "If the issue persists, contact the system administrator." |
| 75 | + ), |
| 76 | + ) |
| 77 | + |
| 78 | + # Identify missing success indicators |
| 79 | + if "Benchmark Results" not in content: |
| 80 | + error_message = ( |
| 81 | + f"Missing success indicators in {stdout_path}: 'Benchmark Results'. " |
| 82 | + "These keywords are expected to be present in stdout.txt, usually towards the end of the file. " |
| 83 | + "Please review the DDLB test output and errors in the file. " |
| 84 | + "Ensure the DDLB test ran to completion. You can run the generated sbatch script manually " |
| 85 | + f"and check if {stdout_path} is created and contains the expected keywords. " |
| 86 | + "If the issue persists, contact the system administrator." |
| 87 | + ) |
| 88 | + |
| 89 | + return JobStatusResult(is_successful=False, error_message=error_message) |
| 90 | + |
| 91 | + return JobStatusResult(is_successful=True) |
| 92 | + |
| 93 | + return JobStatusResult( |
| 94 | + is_successful=False, |
| 95 | + error_message=( |
| 96 | + f"stdout.txt file not found in the specified output directory {tr.output_path}. " |
| 97 | + "This file is expected to be created as a result of the DDLB test run. " |
| 98 | + "Please ensure the DDLB test was executed properly and that stdout.txt is generated. " |
| 99 | + f"You can run the generated DDLB test command manually and verify the creation of {stdout_path}. " |
| 100 | + "If the issue persists, contact the system administrator." |
| 101 | + ), |
| 102 | + ) |
0 commit comments