|
| 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 cast |
| 18 | + |
| 19 | +import pytest |
| 20 | + |
| 21 | +from cloudai._core.test import Test |
| 22 | +from cloudai._core.test_scenario import TestRun |
| 23 | +from cloudai._core.test_template import TestTemplate |
| 24 | +from cloudai.systems.slurm.slurm_system import SlurmSystem |
| 25 | +from cloudai.workloads.nixl_bench.nixl_bench import NIXLBenchCmdArgs, NIXLBenchTestDefinition |
| 26 | +from cloudai.workloads.nixl_bench.slurm_command_gen_strategy import NIXLBenchSlurmCommandGenStrategy |
| 27 | + |
| 28 | + |
| 29 | +@pytest.fixture |
| 30 | +def nixl_bench_tr(slurm_system: SlurmSystem): |
| 31 | + return TestRun( |
| 32 | + name="nixl-bench", |
| 33 | + num_nodes=2, |
| 34 | + nodes=[], |
| 35 | + test=Test( |
| 36 | + test_template=TestTemplate(slurm_system), |
| 37 | + test_definition=NIXLBenchTestDefinition( |
| 38 | + etcd_image_url="docker.io/library/etcd:3.5.1", |
| 39 | + cmd_args=NIXLBenchCmdArgs( |
| 40 | + docker_image_url="docker.io/library/ubuntu:22.04", etcd_endpoint="http://127.0.0.1:2379" |
| 41 | + ), |
| 42 | + name="nixl-bench", |
| 43 | + description="NIXL Bench", |
| 44 | + test_template_name="NIXLBench", |
| 45 | + ), |
| 46 | + ), |
| 47 | + ) |
| 48 | + |
| 49 | + |
| 50 | +class TestNIXLBenchCommand: |
| 51 | + def test_default(self, nixl_bench_tr: TestRun, slurm_system: SlurmSystem): |
| 52 | + strategy = NIXLBenchSlurmCommandGenStrategy(slurm_system, {}) |
| 53 | + cmd = strategy.gen_nixlbench_command(nixl_bench_tr) |
| 54 | + assert cmd == ["./nixlbench", "--etcd-endpoints http://127.0.0.1:2379"] |
| 55 | + |
| 56 | + def test_can_set_any_cmd_arg(self, nixl_bench_tr: TestRun, slurm_system: SlurmSystem): |
| 57 | + in_args = {"backend": "MPI", "dashed-opt": "DRAM", "under_score_opt": "VRAM"} |
| 58 | + cmd_args = NIXLBenchCmdArgs.model_validate( |
| 59 | + {"docker_image_url": "docker.io/library/ubuntu:22.04", "etcd_endpoint": "http://127.0.0.1:2379", **in_args} |
| 60 | + ) |
| 61 | + strategy = NIXLBenchSlurmCommandGenStrategy(slurm_system, {}) |
| 62 | + nixl_bench_tr.test.test_definition.cmd_args = cmd_args |
| 63 | + |
| 64 | + cmd = " ".join(strategy.gen_nixlbench_command(nixl_bench_tr)) |
| 65 | + |
| 66 | + for k, v in in_args.items(): |
| 67 | + assert f"--{k} {v}" in cmd |
| 68 | + |
| 69 | + |
| 70 | +def test_gen_etcd_srun_command(nixl_bench_tr: TestRun, slurm_system: SlurmSystem): |
| 71 | + strategy = NIXLBenchSlurmCommandGenStrategy(slurm_system, {}) |
| 72 | + cmd = " ".join(strategy.gen_etcd_srun_command(nixl_bench_tr)) |
| 73 | + assert ( |
| 74 | + "/usr/local/bin/etcd --listen-client-urls http://0.0.0.0:2379 " |
| 75 | + "--advertise-client-urls http://$(hostname -I | awk '{print $1}'):2379" |
| 76 | + ) in cmd |
| 77 | + |
| 78 | + tdef: NIXLBenchTestDefinition = cast(NIXLBenchTestDefinition, nixl_bench_tr.test.test_definition) |
| 79 | + assert f"--container-image={tdef.etcd_image.installed_path}" in cmd |
| 80 | + assert "--container-mounts" in cmd |
| 81 | + assert "--overlap" in cmd |
| 82 | + assert "--ntasks-per-node=1" in cmd |
| 83 | + assert "--ntasks=1" in cmd |
| 84 | + assert "--nodelist=$SLURM_JOB_MASTER_NODE" in cmd |
| 85 | + assert "-N1" in cmd |
| 86 | + |
| 87 | + |
| 88 | +def test_gen_nixl_srun_command(nixl_bench_tr: TestRun, slurm_system: SlurmSystem): |
| 89 | + strategy = NIXLBenchSlurmCommandGenStrategy(slurm_system, {}) |
| 90 | + cmd = " ".join(strategy.gen_nixl_srun_command(nixl_bench_tr)) |
| 91 | + tdef: NIXLBenchTestDefinition = cast(NIXLBenchTestDefinition, nixl_bench_tr.test.test_definition) |
| 92 | + assert f"--container-image={tdef.docker_image.installed_path}" in cmd |
| 93 | + assert "--overlap" in cmd |
| 94 | + assert "--ntasks-per-node=1" in cmd |
| 95 | + assert f"--ntasks={nixl_bench_tr.num_nodes}" in cmd |
| 96 | + assert f"-N{nixl_bench_tr.num_nodes}" in cmd |
| 97 | + |
| 98 | + |
| 99 | +def test_gen_srun_command(nixl_bench_tr: TestRun, slurm_system: SlurmSystem): |
| 100 | + strategy = NIXLBenchSlurmCommandGenStrategy(slurm_system, {}) |
| 101 | + cmd = strategy._gen_srun_command({}, {}, nixl_bench_tr) |
| 102 | + assert "sleep 5" in cmd |
0 commit comments