Skip to content

Commit 64793fe

Browse files
committed
[Windows] Add model run CI
ghstack-source-id: aad5178 ghstack-comment-id: 3239691798 Pull-Request: #13836
1 parent 18cecb7 commit 64793fe

File tree

4 files changed

+122
-21
lines changed

4 files changed

+122
-21
lines changed

.ci/scripts/setup-windows.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
param (
2+
[string]$editable = $false
3+
)
4+
5+
conda create --yes --quiet -n et python=3.12
6+
conda activate et
7+
8+
# Activate the VS environment - this is required for Dynamo to work, as it uses MSVC.
9+
# There are a bunch of environment variables that it requires.
10+
# See https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line.
11+
& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64
12+
13+
# Install test dependencies
14+
pip install -r .ci/docker/requirements-ci.txt
15+
16+
if ($editable -eq 'true') {
17+
install_executorch.bat --editable
18+
} else {
19+
install_executorch.bat
20+
}
21+
if ($LASTEXITCODE -ne 0) {
22+
Write-Host "Installation was unsuccessful. Exit code: $LASTEXITCODE."
23+
exit $LASTEXITCODE
24+
}

.ci/scripts/test_model.ps1

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
param (
2+
[string]$modelName,
3+
[string]$backend,
4+
[string]$buildDir = "cmake-out",
5+
[bool]$strict = $false
6+
)
7+
8+
Set-PSDebug -Trace 1
9+
$ErrorActionPreference = 'Stop'
10+
$PSNativeCommandUseErrorActionPreference = $true
11+
12+
function ExportModel-Portable {
13+
param (
14+
[string]$model_name,
15+
[bool]$strict
16+
)
17+
18+
$exportParams = "--model_name", "$modelName"
19+
if ($strict) {
20+
$exportParams += "--strict"
21+
}
22+
python -m examples.portable.scripts.export @exportParams | Write-Host
23+
if ($LASTEXITCODE -ne 0) {
24+
Write-Host "Model export failed. Exit code: $LASTEXITCODE."
25+
exit $LASTEXITCODE
26+
}
27+
28+
"$modelName.pte"
29+
}
30+
31+
function ExportModel-Xnnpack {
32+
param (
33+
[string]$model_name
34+
)
35+
36+
python -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate | Write-Host
37+
if ($LASTEXITCODE -ne 0) {
38+
Write-Host "Model export failed. Exit code: $LASTEXITCODE."
39+
exit $LASTEXITCODE
40+
}
41+
42+
"$($modelName)_xnnpack_fp32.pte"
43+
}
44+
45+
.ci/scripts/setup-windows.ps1
46+
47+
# Build the runner
48+
if (Test-Path -Path $buildDir) {
49+
Remove-Item -Path $buildDir -Recurse -Force
50+
}
51+
New-Item -Path $buildDir -ItemType Directory
52+
Push-Location $buildDir
53+
cmake .. --preset windows
54+
cmake --build . -t executor_runner -j16 --config Release
55+
if ($LASTEXITCODE -ne 0) {
56+
Write-Host "Runner build failed. Exit code: $LASTEXITCODE."
57+
exit $LASTEXITCODE
58+
}
59+
$executorBinaryPath = Join-Path -Path $buildDir -ChildPath "Release\executor_runner.exe"
60+
Pop-Location
61+
62+
# Export the model
63+
switch ($backend) {
64+
"portable" {
65+
$model_path = ExportModel-Portable -model_name $modelName -strict $strict
66+
}
67+
"xnnpack" {
68+
$model_path = ExportModel-Xnnpack -model_name $modelName
69+
}
70+
default {
71+
Write-Host "Unknown backend $backend."
72+
exit 1
73+
}
74+
}
75+
76+
# Run the runner
77+
& "$executorBinaryPath" --model_path="$model_path"
78+
if ($LASTEXITCODE -ne 0) {
79+
Write-Host "Model execution failed. Exit code: $LASTEXITCODE."
80+
exit $LASTEXITCODE
81+
}

.ci/scripts/unittest-windows.ps1

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
11
param (
2-
[string]$editable
2+
[string]$editable = $false
33
)
44

55
Set-PSDebug -Trace 1
66
$ErrorActionPreference = 'Stop'
77
$PSNativeCommandUseErrorActionPreference = $true
88

9-
conda create --yes --quiet -n et python=3.12
10-
conda activate et
11-
12-
# Activate the VS environment - this is required for Dynamo to work, as it uses MSVC.
13-
# There are a bunch of environment variables that it requires.
14-
# See https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line.
15-
& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64
16-
17-
# Install test dependencies
18-
pip install -r .ci/docker/requirements-ci.txt
19-
20-
if ($editable -eq 'true') {
21-
install_executorch.bat --editable
22-
} else {
23-
install_executorch.bat
24-
}
25-
if ($LASTEXITCODE -ne 0) {
26-
Write-Host "Installation was unsuccessful. Exit code: $LASTEXITCODE."
27-
exit $LASTEXITCODE
28-
}
9+
.ci/scripts/setup-windows.ps1 -editable $editable
2910

3011
# Run pytest with coverage
3112
# pytest -n auto --cov=./ --cov-report=xml

.github/workflows/trunk.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,3 +979,18 @@ jobs:
979979
# Run MCU models
980980
chmod +x examples/arm/run_mcu_models_fvp.sh
981981
examples/arm/run_mcu_models_fvp.sh --target=cortex-m55
982+
983+
test-models-windows:
984+
uses: pytorch/test-infra/.github/workflows/windows_job.yml@main
985+
strategy:
986+
fail-fast: false
987+
matrix:
988+
model: [linear, add, add_mul, ic3, ic4, mv2, mv3, resnet18, resnet50, vit, w2l, mobilebert, emformer_join, emformer_transcribe]
989+
backend: [portable, xnnpack]
990+
with:
991+
submodules: 'recursive'
992+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
993+
timeout: 60
994+
script: |
995+
conda init powershell
996+
powershell .ci/scripts/test_model.ps1 -modelName ${{ matrix.model }} -backend ${{ matrix.backend }}

0 commit comments

Comments
 (0)