Skip to content
Closed
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
12 changes: 10 additions & 2 deletions src/winml/modelkit/commands/perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,16 +1051,24 @@ def _load_model(self) -> None:
),
}

# VitisAI's compiler can hang during InferenceSession creation when
# native stderr points to a pipe, even when that pipe is drained
# concurrently. Keep its native handle untouched; other EPs retain the
# default warning filtering.
filter_native_warnings = (
self._ep_device.device.ep_name != "VitisAIExecutionProvider"
)

if is_onnx:
with suppress_native_warnings(enabled=True):
with suppress_native_warnings(enabled=filter_native_warnings):
self._model = WinMLAutoModel.from_onnx(
onnx_path=model_path,
skip_build=self.config.skip_build,
compile_provider_options=self.config.compile_ep_options,
**common_kwargs,
)
else:
with suppress_native_warnings(enabled=True):
with suppress_native_warnings(enabled=filter_native_warnings):
self._model = WinMLAutoModel.from_pretrained(
model_id,
**common_kwargs,
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/commands/test_perf_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,44 @@ def resolve_ep_device(self: PerfBenchmark) -> None:
assert all(import_observed)
assert load_observed == [True]

def test_load_model_does_not_redirect_native_stderr_for_vitisai(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
"""VitisAI session creation keeps the process native stderr handle."""
suppression_enabled: list[bool] = []

@contextmanager
def record_native_suppression(*_args: object, **kwargs: object):
suppression_enabled.append(bool(kwargs.get("enabled")))
yield

class FakeWinMLAutoModel:
@staticmethod
def from_pretrained(*args: object, **kwargs: object) -> MagicMock:
return MagicMock()

def resolve_ep_device(self: PerfBenchmark) -> None:
self._ep_device = MagicMock()
self._ep_device.device.ep_name = "VitisAIExecutionProvider"
self._resolved_device = "npu"
self._resolved_ep = "VitisAIExecutionProvider"

fake_models_pkg = ModuleType("winml.modelkit.models")
fake_models_pkg.WinMLAutoModel = FakeWinMLAutoModel
monkeypatch.setitem(sys.modules, "winml.modelkit.models", fake_models_pkg)
monkeypatch.setattr(
"winml.modelkit.commands.perf.suppress_native_warnings",
record_native_suppression,
)
monkeypatch.setattr(PerfBenchmark, "_resolve_device_ep", resolve_ep_device)

benchmark = PerfBenchmark(
BenchmarkConfig(model_id="microsoft/resnet-50", task="image-classification")
)
benchmark._load_model()

assert suppression_enabled == [True, False]

def test_resolve_device_ep_filters_native_warnings_and_preserves_errors(
self,
monkeypatch: pytest.MonkeyPatch,
Expand Down
Loading