|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | +"""Minimal tests for example configuration files with dry_run.""" |
| 17 | + |
| 18 | +import pathlib |
| 19 | + |
| 20 | +import pytest |
| 21 | +from hydra.core.global_hydra import GlobalHydra |
| 22 | + |
| 23 | +from nemo_evaluator_launcher.api.functional import RunConfig, run_eval |
| 24 | + |
| 25 | +# Get the examples directory path |
| 26 | +EXAMPLES_DIR = (pathlib.Path(__file__).parent.parent.parent / "examples").absolute() |
| 27 | + |
| 28 | +# Discover all YAML example files |
| 29 | +EXAMPLE_YAMLS = [f.stem for f in EXAMPLES_DIR.glob("*.yaml") if f.is_file()] |
| 30 | + |
| 31 | + |
| 32 | +class TestExampleConfigs: |
| 33 | + """Test that all example configuration files can be initialized with dry_run.""" |
| 34 | + |
| 35 | + @pytest.mark.parametrize("config_name", EXAMPLE_YAMLS) |
| 36 | + def test_example_config_dry_run(self, config_name, mock_execdb, setup_env_vars): |
| 37 | + """Test that example configs can be loaded and run in dry_run mode.""" |
| 38 | + # Skip lepton configs with deployment (they try to create real endpoints even in dry_run) |
| 39 | + if ( |
| 40 | + config_name.startswith("lepton_") |
| 41 | + and config_name != "lepton_none_llama_3_1_8b_instruct" |
| 42 | + ): |
| 43 | + pytest.skip( |
| 44 | + "Lepton configs with deployment try to create endpoints even in dry_run mode" |
| 45 | + ) |
| 46 | + |
| 47 | + # Clear Hydra instance |
| 48 | + GlobalHydra.instance().clear() |
| 49 | + |
| 50 | + try: |
| 51 | + # Build overrides: output_dir for all, plus slurm-specific overrides |
| 52 | + overrides = ["execution.output_dir=/tmp/test_output"] |
| 53 | + |
| 54 | + # Add slurm-specific overrides for configs starting with "slurm_" |
| 55 | + if config_name.startswith("slurm_"): |
| 56 | + overrides.extend( |
| 57 | + [ |
| 58 | + "++execution.type=slurm", |
| 59 | + "++execution.hostname=test-slurm-host", |
| 60 | + "++execution.account=test-account", |
| 61 | + ] |
| 62 | + ) |
| 63 | + |
| 64 | + # Load configuration using RunConfig.from_hydra (same as CLI) |
| 65 | + cfg = RunConfig.from_hydra( |
| 66 | + config_name=config_name, |
| 67 | + hydra_overrides=overrides, |
| 68 | + config_dir=str(EXAMPLES_DIR), |
| 69 | + ) |
| 70 | + |
| 71 | + # Run with dry_run - should not raise |
| 72 | + invocation_id = run_eval(cfg, dry_run=True) |
| 73 | + assert invocation_id is not None |
| 74 | + assert len(invocation_id) == 16 # Standard invocation ID length |
| 75 | + finally: |
| 76 | + GlobalHydra.instance().clear() |
0 commit comments