From 925b5716872ad961b150f89b6a05134b7f301e89 Mon Sep 17 00:00:00 2001 From: hualxie Date: Thu, 9 Apr 2026 15:53:12 +0800 Subject: [PATCH 1/4] fix(compile): derive Device label from resolved EP instead of CLI default Use _EP_TO_DEVICE[provider] to display the correct device when --ep overrides the default device (e.g. --ep dml shows 'gpu' not 'npu'). Co-Authored-By: Claude Sonnet 4.6 --- src/winml/modelkit/commands/compile.py | 4 +-- .../commands/test_compile_quantize_flags.py | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/winml/modelkit/commands/compile.py b/src/winml/modelkit/commands/compile.py index 142b57155..8ecf470a2 100644 --- a/src/winml/modelkit/commands/compile.py +++ b/src/winml/modelkit/commands/compile.py @@ -25,7 +25,7 @@ import click from rich.console import Console -from ..config.precision import _DEVICE_TO_PROVIDER, VALID_EPS +from ..config.precision import _DEVICE_TO_PROVIDER, _EP_TO_DEVICE, VALID_EPS from ..onnx import is_compiled_onnx from ..utils.logging import configure_logging @@ -191,7 +191,7 @@ def compile( # Show info console.print(f"[bold blue]Input:[/bold blue] {model}") - console.print(f"[bold blue]Device:[/bold blue] {device}") + console.print(f"[bold blue]Device:[/bold blue] {_EP_TO_DEVICE.get(provider, device)}") if ep: console.print(f"[bold blue]EP:[/bold blue] {ep}") console.print(f"[bold blue]Provider:[/bold blue] {provider}") diff --git a/tests/unit/commands/test_compile_quantize_flags.py b/tests/unit/commands/test_compile_quantize_flags.py index 2c8b43ce5..7cba77d87 100644 --- a/tests/unit/commands/test_compile_quantize_flags.py +++ b/tests/unit/commands/test_compile_quantize_flags.py @@ -6,6 +6,8 @@ from __future__ import annotations +from unittest.mock import MagicMock, patch + import pytest from winml.modelkit.commands.compile import _resolve_compile_provider @@ -119,3 +121,35 @@ def test_unknown_precision_uses_defaults(self): w, a = _resolve_quant_types("fp16", None, None) assert w == "uint8" assert a == "uint8" + + +# ============================================================================= +# BUG C: compile summary shows wrong Device when --ep overrides device +# ============================================================================= + + +class TestCompileDeviceDisplayLabel: + """Bug C: Device label in compile summary must reflect the resolved EP, not the CLI default.""" + + def test_dml_ep_shows_gpu_device(self, tmp_path): + from click.testing import CliRunner + + from winml.modelkit.commands.compile import compile + + model_file = tmp_path / "model.onnx" + model_file.write_bytes(b"fake") + + mock_result = MagicMock() + mock_result.success = True + mock_result.output_path = None + mock_result.compile_time = None + mock_result.total_time = None + + with ( + patch("winml.modelkit.compiler.compile_onnx", return_value=mock_result), + patch("winml.modelkit.compiler.WinMLCompileConfig"), + ): + result = CliRunner().invoke(compile, ["-m", str(model_file), "--ep", "dml"]) + + assert "Device: gpu" in result.output + assert "Device: npu" not in result.output From a00d4ea33ac68aed1e857d61250c461e8c8eb32e Mon Sep 17 00:00:00 2001 From: hualxie Date: Mon, 13 Apr 2026 11:23:47 +0800 Subject: [PATCH 2/4] test(compile): fix patch targets and remove Bug C label Co-Authored-By: Claude Sonnet 4.6 --- tests/unit/commands/test_compile_quantize_flags.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/unit/commands/test_compile_quantize_flags.py b/tests/unit/commands/test_compile_quantize_flags.py index 7cba77d87..a2984c532 100644 --- a/tests/unit/commands/test_compile_quantize_flags.py +++ b/tests/unit/commands/test_compile_quantize_flags.py @@ -123,13 +123,8 @@ def test_unknown_precision_uses_defaults(self): assert a == "uint8" -# ============================================================================= -# BUG C: compile summary shows wrong Device when --ep overrides device -# ============================================================================= - - class TestCompileDeviceDisplayLabel: - """Bug C: Device label in compile summary must reflect the resolved EP, not the CLI default.""" + """Device label in compile summary must reflect the resolved EP, not the CLI default.""" def test_dml_ep_shows_gpu_device(self, tmp_path): from click.testing import CliRunner @@ -146,8 +141,8 @@ def test_dml_ep_shows_gpu_device(self, tmp_path): mock_result.total_time = None with ( - patch("winml.modelkit.compiler.compile_onnx", return_value=mock_result), - patch("winml.modelkit.compiler.WinMLCompileConfig"), + patch("winml.modelkit.commands.compile.compile_onnx", return_value=mock_result), + patch("winml.modelkit.commands.compile.WinMLCompileConfig"), ): result = CliRunner().invoke(compile, ["-m", str(model_file), "--ep", "dml"]) From eb7a4d2b2b788327e69fb37941ff135de50f0afd Mon Sep 17 00:00:00 2001 From: hualxie Date: Mon, 13 Apr 2026 11:36:00 +0800 Subject: [PATCH 3/4] test(compile): revert patch targets to source module for lazy imports compile_onnx and WinMLCompileConfig are imported inside the function body, so they're never bound at the commands.compile module level. The correct patch target for lazy imports is the source module (winml.modelkit.compiler). Co-Authored-By: Claude Sonnet 4.6 --- tests/unit/commands/test_compile_quantize_flags.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/commands/test_compile_quantize_flags.py b/tests/unit/commands/test_compile_quantize_flags.py index a2984c532..caa21ffa6 100644 --- a/tests/unit/commands/test_compile_quantize_flags.py +++ b/tests/unit/commands/test_compile_quantize_flags.py @@ -141,8 +141,8 @@ def test_dml_ep_shows_gpu_device(self, tmp_path): mock_result.total_time = None with ( - patch("winml.modelkit.commands.compile.compile_onnx", return_value=mock_result), - patch("winml.modelkit.commands.compile.WinMLCompileConfig"), + patch("winml.modelkit.compiler.compile_onnx", return_value=mock_result), + patch("winml.modelkit.compiler.WinMLCompileConfig"), ): result = CliRunner().invoke(compile, ["-m", str(model_file), "--ep", "dml"]) From 686f29c34469810e69bb253e5f38d7f2e8649ba5 Mon Sep 17 00:00:00 2001 From: hualxie Date: Mon, 13 Apr 2026 11:51:59 +0800 Subject: [PATCH 4/4] test(compile): mock is_compiled_onnx to avoid real ONNX parsing is_compiled_onnx is a module-level import that parses the ONNX file before the Device label is printed; patch it so the test doesn't need a valid model. Co-Authored-By: Claude Sonnet 4.6 --- tests/unit/commands/test_compile_quantize_flags.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/commands/test_compile_quantize_flags.py b/tests/unit/commands/test_compile_quantize_flags.py index caa21ffa6..7f5274a9b 100644 --- a/tests/unit/commands/test_compile_quantize_flags.py +++ b/tests/unit/commands/test_compile_quantize_flags.py @@ -141,6 +141,7 @@ def test_dml_ep_shows_gpu_device(self, tmp_path): mock_result.total_time = None with ( + patch("winml.modelkit.commands.compile.is_compiled_onnx", return_value=False), patch("winml.modelkit.compiler.compile_onnx", return_value=mock_result), patch("winml.modelkit.compiler.WinMLCompileConfig"), ):