|
| 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 | + [bool]$quantize |
| 35 | + ) |
| 36 | + |
| 37 | + if $(quantize) { |
| 38 | + python -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate --quantize | Write-Host |
| 39 | + $modelFile = "$($modelName)_xnnpack_q8.pte" |
| 40 | + } else { |
| 41 | + python -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate | Write-Host |
| 42 | + $modelFile = "$($modelName)_xnnpack_fp32.pte" |
| 43 | + } |
| 44 | + if ($LASTEXITCODE -ne 0) { |
| 45 | + Write-Host "Model export failed. Exit code: $LASTEXITCODE." |
| 46 | + exit $LASTEXITCODE |
| 47 | + } |
| 48 | + |
| 49 | + $modelFile |
| 50 | +} |
| 51 | + |
| 52 | +# Build the runner |
| 53 | +if (Test-Path -Path $buildDir) { |
| 54 | + Remove-Item -Path $buildDir -Recurse -Force |
| 55 | +} |
| 56 | +New-Item -Path $buildDir -ItemType Directory |
| 57 | +Push-Location $buildDir |
| 58 | +cmake .. --preset windows |
| 59 | +cmake --build . -t executor_runner -j16 --config Release |
| 60 | +if ($LASTEXITCODE -ne 0) { |
| 61 | + Write-Host "Runner build failed. Exit code: $LASTEXITCODE." |
| 62 | + exit $LASTEXITCODE |
| 63 | +} |
| 64 | +$executorBinaryPath = Join-Path -Path $buildDir -ChildPath "Release\executor_runner.exe" |
| 65 | +Pop-Location |
| 66 | + |
| 67 | +# Export the model |
| 68 | +switch ($backend) { |
| 69 | + "portable" { |
| 70 | + $model_path = ExportModel-Portable -model_name $modelName -strict $strict |
| 71 | + } |
| 72 | + "xnnpack-f32" { |
| 73 | + $model_path = ExportModel-Xnnpack -model_name $modelName -quantize $false |
| 74 | + } |
| 75 | + "xnnpack-q8" { |
| 76 | + $model_path = ExportModel-Xnnpack -model_name $modelName -quantize $true |
| 77 | + } |
| 78 | + default { |
| 79 | + Write-Host "Unknown backend $backend." |
| 80 | + exit 1 |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +# Run the runner |
| 85 | +& "$executorBinaryPath" --model_path="$model_path" |
| 86 | +if ($LASTEXITCODE -ne 0) { |
| 87 | + Write-Host "Model execution failed. Exit code: $LASTEXITCODE." |
| 88 | + exit $LASTEXITCODE |
| 89 | +} |
0 commit comments