Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/winml/modelkit/commands/perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = {}
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/winml/modelkit/session/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/commands/test_perf_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
PerfBenchmark,
display_console_report,
generate_output_path,
generate_random_inputs,
perf,
)
from winml.modelkit.utils.console import SafeConsole
Expand Down Expand Up @@ -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)
# =============================================================================
Expand Down
Loading