From 982ddef6da0f1d75ef4c58445cb4ca0f614f957d Mon Sep 17 00:00:00 2001 From: Raghav Date: Mon, 3 Aug 2026 17:28:27 -0700 Subject: [PATCH] [ci] Validate run_config.gpu_types at discovery (list of non-empty strings) Addresses review feedback: an accidental string or non-string entry in gpu_types would iterate characters or raise TypeError mid-run. Validate it in _validate_benchmark_config so a malformed config fails at collection, not during a benchmark. Adds tests for the rejected and accepted shapes. --- .../test_benchmark_config_validation.py | 16 ++++++++++++++++ .../performance/test_inference_performance.py | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/fastvideo/tests/performance/test_benchmark_config_validation.py b/fastvideo/tests/performance/test_benchmark_config_validation.py index ce5aa5027..c335ce1f0 100644 --- a/fastvideo/tests/performance/test_benchmark_config_validation.py +++ b/fastvideo/tests/performance/test_benchmark_config_validation.py @@ -152,3 +152,19 @@ def test_gpu_type_gate_absent_field_runs_everywhere(): # No gpu_types key, and an empty list, both run on any device. assert _gpu_type_skip_reason(cfg, {}, "NVIDIA H100 80GB HBM3") is None assert _gpu_type_skip_reason(cfg, {"gpu_types": []}, "NVIDIA H100") is None + + +def test_gpu_types_must_be_list_of_nonempty_strings(): + # A bare string (would iterate characters), non-string entries, and empty + # strings are all rejected at config-discovery time. + for bad in ("GB10", ["GB10", 3], [""], [None]): + cfg = {"benchmark_id": "x", "run_config": {"gpu_types": bad}} + with pytest.raises(ValueError, match="gpu_types"): + _validate_benchmark_config(cfg, "x.json") + + # A valid list, an absent field, and an empty list all pass. + _validate_benchmark_config( + {"benchmark_id": "x", "run_config": {"gpu_types": ["GB10"]}}, "x.json") + _validate_benchmark_config({"benchmark_id": "x"}, "x.json") + _validate_benchmark_config( + {"benchmark_id": "x", "run_config": {"gpu_types": []}}, "x.json") diff --git a/fastvideo/tests/performance/test_inference_performance.py b/fastvideo/tests/performance/test_inference_performance.py index a56923e56..865d83894 100644 --- a/fastvideo/tests/performance/test_inference_performance.py +++ b/fastvideo/tests/performance/test_inference_performance.py @@ -98,6 +98,15 @@ def _validate_benchmark_config(cfg, path=""): if field in cfg and not isinstance(cfg[field], Mapping): raise ValueError(f"{path}: benchmark config field {field!r} must be an object") + run_config = cfg.get("run_config") + if isinstance(run_config, Mapping): + gpu_types = run_config.get("gpu_types") + if gpu_types is not None and ( + not isinstance(gpu_types, (list, tuple)) + or any(not isinstance(g, str) or not g for g in gpu_types)): + raise ValueError( + f"{path}: run_config.gpu_types must be a list of non-empty strings") + schema_version = cfg.get("config_schema_version") if schema_version is None: if _has_v2_fields(cfg):