diff --git a/src/winml/modelkit/commands/perf.py b/src/winml/modelkit/commands/perf.py index 35035cf6e..59ff6b216 100644 --- a/src/winml/modelkit/commands/perf.py +++ b/src/winml/modelkit/commands/perf.py @@ -538,6 +538,7 @@ def generate_random_inputs( symbolic_shapes = io_config.get("input_symbolic_shapes") or [ [None] * len(s) for s in io_config["input_shapes"] ] + value_ranges = io_config.get("input_value_ranges") or {} overrides = shape_config or {} specs: dict[str, dict[str, Any]] = {} @@ -566,6 +567,8 @@ def generate_random_inputs( "dtype": gen_dtype, "shape": list(resolved_shape), } + if name in value_ranges: + specs[name]["range"] = value_ranges[name] return generate_dummy_inputs_from_specs(specs) diff --git a/src/winml/modelkit/session/session.py b/src/winml/modelkit/session/session.py index d62a74fe5..527486040 100644 --- a/src/winml/modelkit/session/session.py +++ b/src/winml/modelkit/session/session.py @@ -1676,7 +1676,7 @@ def io_config(self) -> dict: self._io_config["precision"] = self._get_precision(model) return self._io_config - def _load_input_value_ranges(self) -> dict[str, list[int]]: + def _load_input_value_ranges(self) -> dict[str, list[float]]: """Load input value ranges from the winml_build_config.json. Searches for the build config file in the same directory as the @@ -1688,7 +1688,7 @@ def _load_input_value_ranges(self) -> dict[str, list[int]]: """ import json - value_ranges: dict[str, list[int]] = {} + value_ranges: dict[str, list[float]] = {} model_dir = self._onnx_path.parent # Try exact name first, then glob for prefixed variants diff --git a/tests/unit/commands/test_perf_cli.py b/tests/unit/commands/test_perf_cli.py index c829a5850..a336a5b56 100644 --- a/tests/unit/commands/test_perf_cli.py +++ b/tests/unit/commands/test_perf_cli.py @@ -36,6 +36,7 @@ PerfBenchmark, display_console_report, generate_output_path, + generate_random_inputs, perf, ) from winml.modelkit.utils.console import SafeConsole @@ -255,6 +256,21 @@ def test_path_is_under_user_home(self) -> None: assert self._cache_root in result.parents +class TestGenerateRandomInputs: + def test_uses_persisted_floating_value_range(self) -> None: + io_config = { + "input_names": ["image"], + "input_shapes": [[1, 3, 8, 8]], + "input_types": ["float32"], + "input_value_ranges": {"image": [-2.1179039478302, 2.640000343322754]}, + } + + inputs = generate_random_inputs(io_config) + + assert inputs["image"].min() >= io_config["input_value_ranges"]["image"][0] + assert inputs["image"].max() < io_config["input_value_ranges"]["image"][1] + + # ============================================================================= # UNIFIED PIPELINE TESTS (ONNX and HF both through PerfBenchmark) # =============================================================================