Skip to content

Commit c640c50

Browse files
xieofxiehualxie
andauthored
fix: update npu pdh, perf UI (#747)
Co-authored-by: hualxie <hualxie@microsoft.com>
1 parent 0eaf711 commit c640c50

4 files changed

Lines changed: 19 additions & 11 deletions

File tree

src/winml/modelkit/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def format_commands(self, ctx: click.Context, formatter: click.HelpFormatter) ->
264264
def main(ctx: click.Context, verbose: int, quiet: bool, debug: bool) -> None:
265265
"""WinML CLI - Accelerate Model Deployment on WinML.
266266
267-
Universal ONNX export with QNN and OpenVINO backend support.
267+
Universal ONNX export with various WinML execution providers support.
268268
"""
269269
# --debug is a backward-compat alias for -vv
270270
if debug:

src/winml/modelkit/commands/perf.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ def run(self) -> BenchmarkResult:
300300
_print_model_info(
301301
self._model.io_config,
302302
task=self._model.task or self.config.task,
303-
device=self._model.device,
303+
req_device=self.config.device,
304+
act_device=self._model.device,
304305
ep_name=self._model.ep_name,
305306
)
306307

@@ -755,6 +756,12 @@ def _perf_modules(
755756
# Report Generation
756757
# =============================================================================
757758

759+
def _device_string(req_device: str, act_device: str, ep_name: EPName | None) -> str:
760+
device_str = f"{req_device} ({act_device})" if req_device != act_device else act_device
761+
if ep_name:
762+
device_str = f"{device_str} / {ep_name}"
763+
return device_str
764+
758765

759766
def display_console_report(result: BenchmarkResult, console: Console) -> None:
760767
"""Display benchmark results in formatted console output."""
@@ -763,9 +770,7 @@ def display_console_report(result: BenchmarkResult, console: Console) -> None:
763770

764771
req_device = result.config.device
765772
act_device = result.actual_device
766-
device_str = f"{req_device} ({act_device})" if req_device != act_device else act_device
767-
if result.actual_ep:
768-
device_str = f"{device_str} / {result.actual_ep}"
773+
device_str = _device_string(req_device, act_device, result.actual_ep)
769774
console.print(f"[dim]Device:[/dim] {device_str}")
770775

771776
# TODO: show resolved precision once WinMLPreTrainedModel.precision
@@ -885,13 +890,14 @@ def _print_model_info(
885890
io_config: dict,
886891
*,
887892
task: str | None = None,
888-
device: str = "auto",
893+
req_device: str = "auto",
894+
act_device: str = "auto",
889895
ep_name: EPName | None = None,
890896
) -> None:
891897
"""Print model I/O metadata before the benchmark starts."""
892898
console = Console(stderr=True)
893899
console.print()
894-
device_line = f"{device} / {ep_name}" if ep_name else device
900+
device_line = _device_string(req_device, act_device, ep_name)
895901
console.print(f"[dim]Device:[/dim] {device_line}")
896902
if task:
897903
console.print(f"[dim]Task:[/dim] {task}")
@@ -1011,7 +1017,7 @@ def _run_onnx_benchmark(
10111017
session.compile()
10121018

10131019
# Print model info before benchmark starts
1014-
_print_model_info(io_cfg, device=session.device, ep_name=session.ep_name)
1020+
_print_model_info(io_cfg, req_device=device, act_device=session.device, ep_name=session.ep_name)
10151021

10161022
# Run benchmark
10171023
total_iterations = warmup + iterations
@@ -1044,7 +1050,7 @@ def _run_onnx_benchmark(
10441050
total_iterations=total_iterations,
10451051
warmup=warmup,
10461052
model_id=str(onnx_path.name),
1047-
device=device,
1053+
device=session.device or device,
10481054
)
10491055
hw_metrics = hw.to_dict()
10501056
else:

src/winml/modelkit/session/monitor/_pdh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ def build_npu_query(npu_luid: str, pid: int | None = None) -> PdhQuery:
329329
Returns:
330330
An opened PdhQuery configured for NPU monitoring.
331331
"""
332-
# Neural: OpenVINO NPU
333-
return build_adapter_query(npu_luid, engine_types=("Compute", "Neural"), pid=pid)
332+
# Neural / 3D: OpenVINO NPU
333+
return build_adapter_query(npu_luid, engine_types=("Compute", "Neural", "3D"), pid=pid)
334334

335335

336336
def build_gpu_query(gpu_luid: str, pid: int | None = None) -> PdhQuery:

tests/e2e/test_perf_e2e.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ def test_benchmark_ep_cpu(self, ep: str, tmp_path: Path, model_arg: str):
484484
def test_benchmark_ep_gpu(self, ep: str, tmp_path: Path, model_arg: str):
485485
"""Benchmark with --ep <ep>."""
486486
require_ep(ep)
487+
_require_gpu()
487488

488489
output_file = tmp_path / f"perf_hf_{ep}_gpu.json"
489490

@@ -507,6 +508,7 @@ def test_benchmark_ep_gpu(self, ep: str, tmp_path: Path, model_arg: str):
507508
def test_benchmark_ep_npu(self, ep: str, tmp_path: Path, model_arg: str):
508509
"""Benchmark with --ep <ep>."""
509510
require_ep(ep)
511+
_require_npu()
510512

511513
output_file = tmp_path / f"perf_hf_{ep}_npu.json"
512514

0 commit comments

Comments
 (0)