diff --git a/src/winml/modelkit/compiler/configs.py b/src/winml/modelkit/compiler/configs.py index dfe4db9e5..a35805418 100644 --- a/src/winml/modelkit/compiler/configs.py +++ b/src/winml/modelkit/compiler/configs.py @@ -269,11 +269,18 @@ def for_vitisai(cls, device: str | None = None) -> WinMLCompileConfig: when available (target=X1, xclbin=/voe-4.0-win_amd64/ xclbins/phoenix/4x4.xclbin, xlnx_enable_py3_round=0). VitisAI EP ignores ``device_type``; the correct device hint is the xclbin path. + The cache is placed under WinML's user-writable cache root instead of + VitisAI's installation-relative default, which may resolve through the + protected WindowsApps directory and fail during model compilation. """ import os from pathlib import Path as _Path - provider_options: dict[str, str] = {} + from ..cache import get_cache_dir + + vaip_cache_dir = (get_cache_dir() / "vitisai").resolve() + vaip_cache_dir.mkdir(parents=True, exist_ok=True) + provider_options: dict[str, str] = {"cache_dir": str(vaip_cache_dir)} ryzen_ai = os.environ.get("RYZEN_AI_INSTALLATION_PATH") if ryzen_ai: xclbin = _Path(ryzen_ai) / "voe-4.0-win_amd64" / "xclbins" / "phoenix" / "4x4.xclbin" diff --git a/tests/unit/compiler/test_compiler_configs.py b/tests/unit/compiler/test_compiler_configs.py index ccfc24ac2..f6f300639 100644 --- a/tests/unit/compiler/test_compiler_configs.py +++ b/tests/unit/compiler/test_compiler_configs.py @@ -99,11 +99,14 @@ def test_for_openvino(self): assert config.ep_config.provider == "openvino" assert config.ep_config.enable_ep_context is True - def test_for_vitisai(self): + def test_for_vitisai(self, tmp_path, monkeypatch): """Test Vitis AI factory method.""" + monkeypatch.setenv("WINML_CACHE_DIR", str(tmp_path)) config = WinMLCompileConfig.for_vitisai() assert config.ep_config.provider == "vitisai" assert config.ep_config.enable_ep_context is True + assert config.ep_config.provider_options["cache_dir"] == str(tmp_path / "vitisai") + assert (tmp_path / "vitisai").is_dir() def test_for_migraphx(self): """Test MIGraphX factory method."""