diff --git a/.ci/scripts/setup-windows.ps1 b/.ci/scripts/setup-windows.ps1 new file mode 100644 index 00000000000..20d29e4f558 --- /dev/null +++ b/.ci/scripts/setup-windows.ps1 @@ -0,0 +1,24 @@ +param ( + [string]$editable = $false +) + +conda create --yes --quiet -n et python=3.12 +conda activate et + +# Activate the VS environment - this is required for Dynamo to work, as it uses MSVC. +# There are a bunch of environment variables that it requires. +# See https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line. +& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64 + +# Install test dependencies +pip install -r .ci/docker/requirements-ci.txt + +if ($editable -eq 'true') { + install_executorch.bat --editable +} else { + install_executorch.bat +} +if ($LASTEXITCODE -ne 0) { + Write-Host "Installation was unsuccessful. Exit code: $LASTEXITCODE." + exit $LASTEXITCODE +} diff --git a/.ci/scripts/test_model.ps1 b/.ci/scripts/test_model.ps1 new file mode 100644 index 00000000000..2ff2e7c890d --- /dev/null +++ b/.ci/scripts/test_model.ps1 @@ -0,0 +1,89 @@ +param ( + [string]$modelName, + [string]$backend, + [string]$buildDir = "cmake-out", + [bool]$strict = $false +) + +Set-PSDebug -Trace 1 +$ErrorActionPreference = 'Stop' +$PSNativeCommandUseErrorActionPreference = $true + +function ExportModel-Portable { + param ( + [string]$model_name, + [bool]$strict + ) + + $exportParams = "--model_name", "$modelName" + if ($strict) { + $exportParams += "--strict" + } + python -m examples.portable.scripts.export @exportParams | Write-Host + if ($LASTEXITCODE -ne 0) { + Write-Host "Model export failed. Exit code: $LASTEXITCODE." + exit $LASTEXITCODE + } + + "$modelName.pte" +} + +function ExportModel-Xnnpack { + param ( + [string]$model_name, + [bool]$quantize + ) + + if $(quantize) { + python -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate --quantize | Write-Host + $modelFile = "$($modelName)_xnnpack_q8.pte" + } else { + python -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate | Write-Host + $modelFile = "$($modelName)_xnnpack_fp32.pte" + } + if ($LASTEXITCODE -ne 0) { + Write-Host "Model export failed. Exit code: $LASTEXITCODE." + exit $LASTEXITCODE + } + + $modelFile +} + +# Build the runner +if (Test-Path -Path $buildDir) { + Remove-Item -Path $buildDir -Recurse -Force +} +New-Item -Path $buildDir -ItemType Directory +Push-Location $buildDir +cmake .. --preset windows +cmake --build . -t executor_runner -j16 --config Release +if ($LASTEXITCODE -ne 0) { + Write-Host "Runner build failed. Exit code: $LASTEXITCODE." + exit $LASTEXITCODE +} +$executorBinaryPath = Join-Path -Path $buildDir -ChildPath "Release\executor_runner.exe" +Pop-Location + +# Export the model +switch ($backend) { + "portable" { + $model_path = ExportModel-Portable -model_name $modelName -strict $strict + } + "xnnpack-f32" { + $model_path = ExportModel-Xnnpack -model_name $modelName -quantize $false + } + "xnnpack-q8" { + $model_path = ExportModel-Xnnpack -model_name $modelName -quantize $true + } + default { + Write-Host "Unknown backend $backend." + exit 1 + } +} + +# Run the runner +& "$executorBinaryPath" --model_path="$model_path" +if ($LASTEXITCODE -ne 0) { + Write-Host "Model execution failed. Exit code: $LASTEXITCODE." + exit $LASTEXITCODE +} diff --git a/.ci/scripts/unittest-windows.ps1 b/.ci/scripts/unittest-windows.ps1 index d99e87edf67..65ed303051b 100644 --- a/.ci/scripts/unittest-windows.ps1 +++ b/.ci/scripts/unittest-windows.ps1 @@ -1,32 +1,11 @@ param ( - [string]$editable + [string]$editable = $false ) Set-PSDebug -Trace 1 $ErrorActionPreference = 'Stop' $PSNativeCommandUseErrorActionPreference = $true -conda create --yes --quiet -n et python=3.12 -conda activate et - -# Activate the VS environment - this is required for Dynamo to work, as it uses MSVC. -# There are a bunch of environment variables that it requires. -# See https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line. -& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64 - -# Install test dependencies -pip install -r .ci/docker/requirements-ci.txt - -if ($editable -eq 'true') { - install_executorch.bat --editable -} else { - install_executorch.bat -} -if ($LASTEXITCODE -ne 0) { - Write-Host "Installation was unsuccessful. Exit code: $LASTEXITCODE." - exit $LASTEXITCODE -} - # Run pytest with coverage # pytest -n auto --cov=./ --cov-report=xml pytest -v --full-trace -c pytest-windows.ini diff --git a/.github/workflows/_unittest.yml b/.github/workflows/_unittest.yml index 783f69df5b7..a619b33dd2e 100644 --- a/.github/workflows/_unittest.yml +++ b/.github/workflows/_unittest.yml @@ -63,4 +63,13 @@ jobs: timeout: 120 script: | conda init powershell - powershell .ci/scripts/unittest-windows.ps1 -editable "${{ inputs.editable }}" + + powershell -Command "& { + Set-PSDebug -Trace 1 + \$ErrorActionPreference = 'Stop' + \$PSNativeCommandUseErrorActionPreference = \$true + + .ci/scripts/setup-windows.ps1 + + powershell .ci/scripts/unittest-windows.ps1 -editable "${{ inputs.editable }}" + }" diff --git a/.github/workflows/trunk.yml b/.github/workflows/trunk.yml index f03f3736588..8eecf950e61 100644 --- a/.github/workflows/trunk.yml +++ b/.github/workflows/trunk.yml @@ -979,3 +979,27 @@ jobs: # Run MCU models chmod +x examples/arm/run_mcu_models_fvp.sh examples/arm/run_mcu_models_fvp.sh --target=cortex-m55 + + test-models-windows: + uses: pytorch/test-infra/.github/workflows/windows_job.yml@main + strategy: + fail-fast: false + matrix: + model: [linear, add, add_mul, ic3, ic4, mv2, mv3, resnet18, resnet50, vit, w2l, mobilebert, emformer_join, emformer_transcribe] + backend: [portable, xnnpack-f32, xnnpack-q8] + with: + submodules: 'recursive' + ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + timeout: 60 + script: | + conda init powershell + + powershell -Command "& { + Set-PSDebug -Trace 1 + \$ErrorActionPreference = 'Stop' + \$PSNativeCommandUseErrorActionPreference = \$true + + .ci/scripts/setup-windows.ps1 + + powershell .ci/scripts/test_model.ps1 -modelName ${{ matrix.model }} -backend ${{ matrix.backend }} + }" \ No newline at end of file