[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.
This commit is contained in:
Raghav
2026-08-09 15:17:17 -07:00
committed by Satyam Srivastava
parent 0d9d4ad132
commit 982ddef6da
2 changed files with 25 additions and 0 deletions
@@ -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")
@@ -98,6 +98,15 @@ def _validate_benchmark_config(cfg, path="<memory>"):
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):