-
Notifications
You must be signed in to change notification settings - Fork 410
656 lines (638 loc) · 30.7 KB
/
Copy pathbuild_windows.yml
File metadata and controls
656 lines (638 loc) · 30.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
# Synced from pytorch/test-infra build_wheels_windows.yml at f163b0391bea64ed18dcd577a02d78e74367fa70.
# This workflow is used to build the wheels for the Windows platform
# it should be periodically synced with https://github.com/pytorch/test-infra/blob/main/.github/workflows/build_wheels_windows.yml
name: Build Windows Wheels
on:
workflow_call:
inputs:
repository:
description: 'Repository to checkout, defaults to ""'
default: ""
type: string
ref:
description: 'Reference to checkout, defaults to "nightly"'
default: "nightly"
type: string
test-infra-repository:
description: "Test infra repository to use"
default: "pytorch/test-infra"
type: string
test-infra-ref:
description: "Test infra reference to use"
default: ""
type: string
build-matrix:
description: "Build matrix to utilize"
default: ""
type: string
pre-script:
description: "Pre script to run prior to build"
default: ""
type: string
env-script:
description: "Script to setup environment variables for the build"
default: ""
type: string
wheel-build-params:
description: "Additional parameters for bdist_wheel"
default: ""
type: string
post-script:
description: "Post script to run prior to build"
default: ""
type: string
smoke-test-script:
description: "Script for Smoke Test for a specific domain"
default: ""
type: string
package-name:
description: "Name of the actual python package that is imported"
default: ""
type: string
build-platform:
description: Platform to build wheels, choose from 'python-build-package' or 'setup-py'
required: false
type: string
default: 'setup-py'
build-command:
description: The build command to use if build-platform is python-build-package
required: false
default: "python -m build --wheel --no-isolation"
type: string
trigger-event:
description: "Trigger Event in caller that determines whether or not to upload"
default: ""
type: string
cache-path:
description: "The path(s) on the runner to cache or restore. The path is relative to repository."
default: ""
type: string
cache-key:
description: "The key created when saving a cache and the key used to search for a cache."
default: ""
type: string
submodules:
description: "Works as stated in actions/checkout, but the default value is recursive"
required: false
type: string
default: recursive
timeout:
description: 'Timeout for the job (in minutes)'
default: 60
type: number
use-rtx:
description: "Set to true if use TensorRT-RTX"
default: false
type: boolean
required: false
python-only:
description: "Build the PYTHON_ONLY=1 wheel"
default: false
type: boolean
required: false
build-flavor:
description: "Caller-defined build flavor used to isolate concurrent builds"
default: "default"
type: string
required: false
architecture:
description: 'CPU architecture to build for'
default: "x64"
type: string
is-release-tarball:
description: Set to true if the build is for release tarball
required: false
default: false
type: boolean
is-release-wheel:
description: Set to true if the build is for release wheel
required: false
default: false
type: boolean
cross-compile:
description: 'Build ARM64 from an x64 Windows host'
default: false
type: boolean
skip-binary-upload:
description: 'Skip the test-infra binary upload job'
default: false
type: boolean
secrets:
R2_ACCOUNT_ID:
description: Cloudflare R2 account ID
required: false
R2_ACCESS_KEY_ID:
description: Cloudflare R2 access key ID
required: false
R2_SECRET_ACCESS_KEY:
description: Cloudflare R2 secret access key
required: false
permissions:
id-token: write
contents: read
jobs:
build:
strategy:
fail-fast: false
matrix: ${{ fromJSON(inputs.build-matrix) }}
env:
PYTHON_VERSION: ${{ matrix.python_version }}
PACKAGE_TYPE: wheel
REPOSITORY: ${{ inputs.repository }}
REF: ${{ inputs.ref }}
CU_VERSION: ${{ matrix.desired_cuda }}
UPLOAD_TO_BASE_BUCKET: ${{ matrix.upload_to_base_bucket }}
USE_TRT_RTX: ${{ inputs.use-rtx }}
PYTHON_ONLY: ${{ inputs.python-only && '1' || '0' }}
name: build-${{ matrix.build_name }}
runs-on: ${{ matrix.validation_runner }}
environment: ${{(inputs.trigger-event == 'schedule' || (inputs.trigger-event == 'push' && (startsWith(github.event.ref, 'refs/heads/nightly') || startsWith(github.event.ref, 'refs/tags/v')))) && 'pytorchbot-env' || ''}}
defaults:
run:
shell: bash -l {0}
# If a build is taking longer than 60 minutes on these runners we need
# to have a conversation
timeout-minutes: ${{ inputs.timeout }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
# Support the use case where we need to checkout someone's fork
repository: ${{ inputs.test-infra-repository }}
ref: ${{ inputs.test-infra-ref }}
path: test-infra
- uses: ./test-infra/.github/actions/setup-ssh
name: Setup SSH
with:
github-secret: ${{ secrets.GITHUB_TOKEN }}
activate-with-label: false
instructions: "SSH with rdesktop using ssh -L 3389:localhost:3389 %%username%%@%%hostname%%"
- name: Add Conda scripts to GitHub path
if: inputs.architecture == 'x64'
run: |
echo "C:/Jenkins/Miniconda3/Scripts" >> $GITHUB_PATH
- name: Setup Git for Windows' minimal SDK
env:
DEPENDENCIES_DIR: c:\temp\dependencies\
if: inputs.architecture == 'arm64'
uses: git-for-windows/setup-git-for-windows-sdk@v1
with:
architecture: aarch64
path: "${{env.DEPENDENCIES_DIR}}\\git"
- uses: ./test-infra/.github/actions/setup-windows
with:
cuda-version: ${{ env.CU_VERSION }}
- name: Install CUDA 13.4 toolkit with ARM64 target libraries
if: inputs.cross-compile
shell: powershell
env:
CUDA_INSTALLER_URL: https://packages.nvidia.com/prerelease/cuda/13.4.0/local_installers/cuda_13.4.0_windows_x86_64.exe
CUDA_ROOT: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.4
run: |
$ErrorActionPreference = 'Stop'
$installer = Join-Path $env:RUNNER_TEMP "cuda_13.4.0_windows_x86_64.exe"
$cudaArm64Lib = Join-Path $env:CUDA_ROOT "lib\arm64\cudart.lib"
$maxAttempts = 3
for ($attempt = 1; $attempt -le $maxAttempts; $attempt++) {
try {
# Always redownload: a failed transfer can leave a partial installer behind.
Remove-Item -LiteralPath $installer -Force -ErrorAction SilentlyContinue
Invoke-WebRequest -Uri $env:CUDA_INSTALLER_URL -OutFile $installer
$process = Start-Process -FilePath $installer -ArgumentList "-s" -Wait -PassThru
if ($process.ExitCode -ne 0) { throw "CUDA 13.4 installer failed with exit code $($process.ExitCode)" }
if (-not (Test-Path -LiteralPath $cudaArm64Lib -PathType Leaf)) {
throw "CUDA 13.4 ARM64 target library was not installed: $cudaArm64Lib"
}
break
} catch {
if ($attempt -eq $maxAttempts) { throw }
$delaySeconds = 60 * $attempt
Write-Warning "CUDA 13.4 ARM64 installation attempt $attempt/$maxAttempts failed: $($_.Exception.Message). Retrying in $delaySeconds seconds."
Start-Sleep -Seconds $delaySeconds
}
}
"CUDA_PATH=$env:CUDA_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"CUDA_HOME=$env:CUDA_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"TORCHTRT_CROSS_COMPILE_CUDA_HOME=$env:CUDA_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
(Join-Path $env:CUDA_ROOT "bin") | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- uses: ./test-infra/.github/actions/set-channel
- name: Set PYTORCH_VERSION
if: env.CHANNEL == 'test'
run: |
# When building RC, set the version to be the current candidate version,
# otherwise, leave it alone so nightly will pick up the latest
echo "PYTORCH_VERSION=${{ matrix.stable_version }}" >> "${GITHUB_ENV}"
- uses: ./test-infra/.github/actions/setup-binary-builds
if: inputs.architecture == 'x64'
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
submodules: ${{ inputs.submodules }}
setup-miniconda: false
python-version: ${{ env.PYTHON_VERSION }}
cuda-version: ${{ env.CU_VERSION }}
arch: ${{ inputs.cross-compile && 'arm64' || inputs.architecture }}
# setup-binary-builds supplies the x64 artifact name. Match Linux by
# reserving the unsuffixed name for standard TensorRT and suffixing RTX.
- name: Mark x64 Python-only artifact
if: ${{ inputs.architecture == 'x64' && inputs.cross-compile == false && inputs.python-only }}
run: echo "ARTIFACT_NAME=${ARTIFACT_NAME}_python_only" >> "${GITHUB_ENV}"
- name: Mark x64 TensorRT-RTX artifact
if: ${{ inputs.architecture == 'x64' && inputs.cross-compile == false && inputs.use-rtx }}
run: echo "ARTIFACT_NAME=${ARTIFACT_NAME}_rtx" >> "${GITHUB_ENV}"
- name: Export binary-build version for ARM64 cross build
if: inputs.cross-compile
working-directory: ${{ inputs.repository }}
run: |
source "${BUILD_ENV_FILE}"
: "${BUILD_VERSION:?setup-binary-builds did not provide BUILD_VERSION}"
# The host build environment remains cu132, but the ARM64 target sysroot
# and published wheel target CUDA 13.4.
BUILD_VERSION="${BUILD_VERSION%+*}+cu134"
echo "BUILD_VERSION=${BUILD_VERSION}" >> "${GITHUB_ENV}"
: "${ARTIFACT_NAME:?setup-binary-builds did not provide ARTIFACT_NAME}"
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> "${GITHUB_ENV}"
- name: Shorten Conda environment path
if: inputs.architecture == 'x64'
run: |
bash "${REPOSITORY}/.github/scripts/shorten-conda-env-windows.sh"
- name: Install XPU support package
if: ${{ matrix.gpu_arch_type == 'xpu' }}
env:
XPU_VERSION: '2026.1'
run: |
cmd //c .\\test-infra\\.github\\scripts\\install_xpu.bat
- name: Update NVIDIA driver
if: inputs.architecture == 'x64' && matrix.gpu_arch_type == 'cuda'
run: |
cmd //c .\\test-infra\\.github\\scripts\\driver_update.bat
- name: Checkout Target Repository (${{ env.REPOSITORY }})
if: inputs.architecture == 'arm64'
uses: actions/checkout@v4
with:
repository: ${{ env.REPOSITORY }}
ref: ${{ env.REF }}
path: ${{ env.REPOSITORY }}
submodules: recursive
- name: Bootstrap python
if: inputs.architecture == 'arm64'
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
architecture: arm64
- name: Set BUILD_VERSION for Arm64 RC build
# Arm64 does not run setup-binary-builds (x64-only), so pytorch_pkg_helpers
# never sets BUILD_VERSION. Without it setup.py appends the git sha
# (e.g. torchvision-0.28.0+5a5dd12). For RC (test channel) set BUILD_VERSION
# to "<version.txt>+<arch>" to match what pytorch_pkg_helpers produces for
# x64 (e.g. torchvision-0.28.0+cpu) and torch's own win_arm64 wheels.
if: ${{ inputs.architecture == 'arm64' && env.CHANNEL == 'test' }}
working-directory: ${{ inputs.repository }}
run: |
if [[ -f version.txt ]]; then
echo "BUILD_VERSION=$(cat version.txt)+${CU_VERSION}" >> "${GITHUB_ENV}"
fi
- name: Install torch dependency
if: inputs.architecture == 'x64'
run: |
source "${BUILD_ENV_FILE}"
# shellcheck disable=SC2086
${CONDA_RUN} ${PIP_INSTALL_TORCH}
- name: Run Pre-Script with Caching
if: ${{ inputs.pre-script != '' && inputs.architecture == 'x64' }}
uses: ./test-infra/.github/actions/run-script-with-cache
with:
cache-path: ${{ inputs.cache-path }}
cache-key: ${{ inputs.cache-key }}
repository: ${{ inputs.repository }}
script: ${{ inputs.pre-script }}
is_windows: 'enabled'
- name: Prepare ARM64 target sysroot
if: inputs.cross-compile
working-directory: ${{ inputs.repository }}
shell: powershell
run: |
./packaging/prepare_windows_arm64_cross.ps1 `
-TargetRoot '${{ runner.temp }}\torchtrt-windows-arm64' `
-CudaRoot $env:CUDA_PATH `
-PythonExecutable (Join-Path $env:CONDA_ENV 'python.exe')
- name: Ensure MSVC ARM64 cross tools
if: inputs.cross-compile
shell: powershell
run: |
$vswhere = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio/Installer/vswhere.exe"
if (-not (Test-Path -LiteralPath $vswhere -PathType Leaf)) { throw "Visual Studio locator not found: $vswhere" }
$vsInstall = (& $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath | Select-Object -First 1).Trim()
if ([string]::IsNullOrWhiteSpace($vsInstall)) { throw "No Visual Studio instance with x64 MSVC tools was found" }
$vcvarsall = [IO.Path]::Combine($vsInstall, "VC", "Auxiliary", "Build", "vcvarsall.bat")
if (-not (Test-Path -LiteralPath $vcvarsall -PathType Leaf)) { throw "vcvarsall.bat not found: $vcvarsall" }
$arm64Compiler = Get-ChildItem -Path (Join-Path $vsInstall "VC/Tools/MSVC/*/bin/Hostx64/arm64/cl.exe") -File -ErrorAction SilentlyContinue | Select-Object -First 1
if (-not $arm64Compiler) {
$installStopwatch = [Diagnostics.Stopwatch]::StartNew()
$setup = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio/Installer/setup.exe"
if (-not (Test-Path -LiteralPath $setup -PathType Leaf)) { throw "Visual Studio Installer not found: $setup" }
& $setup modify --installPath $vsInstall --add Microsoft.VisualStudio.Component.VC.Tools.ARM64 --passive --norestart
if ($LASTEXITCODE -ne 0) { throw "Installing the MSVC ARM64 component failed with exit code $LASTEXITCODE" }
$deadline = (Get-Date).AddMinutes(20)
while (-not $arm64Compiler -and (Get-Date) -lt $deadline) {
Write-Host "Waiting for the MSVC ARM64 compiler to be installed ($([Math]::Floor($installStopwatch.Elapsed.TotalSeconds)) seconds elapsed; next check in 30 seconds)..."
Start-Sleep -Seconds 30
$arm64Compiler = Get-ChildItem -Path (Join-Path $vsInstall "VC/Tools/MSVC/*/bin/Hostx64/arm64/cl.exe") -File -ErrorAction SilentlyContinue | Select-Object -First 1
}
$installStopwatch.Stop()
if ($arm64Compiler) { Write-Host "MSVC ARM64 compiler became available after $([Math]::Round($installStopwatch.Elapsed.TotalSeconds, 1)) seconds" }
$arm64Compiler = Get-ChildItem -Path (Join-Path $vsInstall "VC/Tools/MSVC/*/bin/Hostx64/arm64/cl.exe") -File -ErrorAction SilentlyContinue | Select-Object -First 1
}
if (-not $arm64Compiler) { throw "MSVC ARM64 compiler was not installed after $([Math]::Round($installStopwatch.Elapsed.TotalSeconds, 1)) seconds" }
"TORCHTRT_VCVARSALL=$vcvarsall" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Cross-compile Windows ARM64 wheel
if: inputs.cross-compile
working-directory: ${{ inputs.repository }}
shell: cmd
run: |
call "%TORCHTRT_VCVARSALL%" amd64_arm64
%CONDA_RUN% cmd /c packaging\build_windows_arm64_cross.bat
- name: Validate Windows ARM64 wheel
if: inputs.cross-compile
working-directory: ${{ inputs.repository }}
shell: cmd
run: |
call "%TORCHTRT_VCVARSALL%" amd64_arm64
powershell -NoProfile -ExecutionPolicy Bypass -File packaging\validate_windows_arm64_wheel.ps1 -DistDirectory dist -PythonExecutable "%CONDA_ENV%\python.exe"
- name: Run Pre-Script Arm64
if: ${{ inputs.pre-script != '' && inputs.architecture == 'arm64' }}
env:
DOWNLOADS_DIR: c:\temp\downloads\
DEPENDENCIES_DIR: c:\temp\dependencies\
SCRIPTS_DIR: test-infra\\.github\\scripts\\winarm64
SRC_DIR: ${{ inputs.repository }}
PRE_SCRIPT: ${{ inputs.pre-script }}
shell: cmd
run: |
set VS_PATH=C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
set GIT_BASH=%DEPENDENCIES_DIR%\git\usr\bin\bash.exe
cd %SRC_DIR%
call "%VS_PATH%" arm64
"%GIT_BASH%" -c "bash --noprofile --norc %PRE_SCRIPT%"
- name: Install certificates for Arm64 runner
if: ${{ inputs.architecture == 'arm64' }}
working-directory: ${{ inputs.repository }}
shell: cmd
run: |
call .\.venv\Scripts\activate.bat
pip install --upgrade certifi==2025.04.26
for /f "delims=" %%A in ('python -m certifi') do set CERT_PATH=%%A
echo Using cert bundle at: %CERT_PATH%
set SSL_CERT_FILE=%CERT_PATH%
set REQUESTS_CA_BUNDLE=%CERT_PATH%
echo SSL_CERT_FILE=%CERT_PATH% >> %GITHUB_ENV%
echo REQUESTS_CA_BUNDLE=%CERT_PATH% >> %GITHUB_ENV%
- name: Build clean
# Only relevant for setup-py builds; python-build-package projects may
# not have a setup.py (e.g. scikit-build-core based builds).
if: inputs.build-platform == 'setup-py' && inputs.architecture == 'x64' && inputs.cross-compile == false
working-directory: ${{ inputs.repository }}
env:
ENV_SCRIPT: ${{ inputs.env-script }}
run: |
source "${BUILD_ENV_FILE}"
if [[ -z "${ENV_SCRIPT}" ]]; then
${CONDA_RUN} python setup.py clean
else
if [[ ! -f ${ENV_SCRIPT} ]]; then
echo "::error::Specified env-script file (${ENV_SCRIPT}) not found"
exit 1
else
${CONDA_RUN} ${ENV_SCRIPT} python setup.py clean
fi
fi
- name: Set PYTORCH_VERSION on x64
if: inputs.architecture == 'x64' && inputs.cross-compile == false
working-directory: ${{ inputs.repository }}
run: |
source "${BUILD_ENV_FILE}"
if [[ "$CU_VERSION" == "cpu" ]]; then
# CUDA and CPU are ABI compatible on the CPU-only parts, so strip
# in this case
export PYTORCH_VERSION="$(${CONDA_RUN} pip show torch | grep ^Version: | sed 's/Version: *//' | sed 's/+.\+//')"
else
export PYTORCH_VERSION="$(${CONDA_RUN} pip show torch | grep ^Version: | sed 's/Version: *//')"
fi
- name: Build the wheel (python-build-package) X64
if: ${{ inputs.build-platform == 'python-build-package' && inputs.architecture == 'x64' && inputs.cross-compile == false }}
working-directory: ${{ inputs.repository }}
env:
ENV_SCRIPT: ${{ inputs.env-script }}
BUILD_PARAMS: ${{ inputs.wheel-build-params }}
run: |
source "${BUILD_ENV_FILE}"
${CONDA_RUN} python -m pip install build==1.2.2
echo "Successfully installed Python build package"
if [[ -z "${ENV_SCRIPT}" ]]; then
${CONDA_RUN} ${{ inputs.build-command }}
else
${CONDA_RUN} ${ENV_SCRIPT} ${{ inputs.build-command }}
fi
- name: Build the wheel (setup-py) X64
if: ${{ inputs.build-platform == 'setup-py' && inputs.architecture == 'x64' && inputs.cross-compile == false }}
working-directory: ${{ inputs.repository }}
env:
ENV_SCRIPT: ${{ inputs.env-script }}
BUILD_PARAMS: ${{ inputs.wheel-build-params }}
run: |
source "${BUILD_ENV_FILE}"
# commented out due to still failed with the following error:
# C:\actions-runner\_work\_temp\conda_environment_18042354682\lib\site-packages\torch\include\torch/csrc/utils/python_arg_parser.h(42): fatal error C1083: Cannot open include file: 'fmt/format.h': No such file or directory
# workaround: download fmt and copy to torch include path in pre_build_script_windows.sh
# conda update -n base -c defaults conda
# conda install -c conda-forge fmt -y
# conda list fmt
# echo "path: $PATH"
${CONDA_RUN} python -m pip install fmt
if [[ ${{ inputs.is-release-wheel }} == true || ${{ inputs.is-release-tarball }} == true ]]; then
# release version for upload to pypi
# BUILD_VERSION example: 2.4.0+cu121, we don't want the +cu121 part, so remove +cu121
BUILD_VERSION=${BUILD_VERSION%+*}
if [[ ${{ inputs.is-release-tarball }} == true ]]; then
mkdir -p release/tarball
TRT_VERSION=$(cat dev_dep_versions.yml | grep __tensorrt_version__ | sed 's/__tensorrt_version__: //g' | sed 's/"//g')
bazel build //:libtorchtrt --compilation_mode opt --config=windows
ls -lart bazel-bin/
cp bazel-bin/libtorchtrt.zip\
release/tarball/libtorchtrt-${BUILD_VERSION}-tensorrt${TRT_VERSION}-cuda${CU_VERSION:2}-libtorch${PYTORCH_VERSION}-x86_64-windows.zip
return 0
fi
fi
if [[ -z "${ENV_SCRIPT}" ]]; then
${CONDA_RUN} python setup.py bdist_wheel
else
${CONDA_RUN} ${ENV_SCRIPT} python setup.py bdist_wheel ${BUILD_PARAMS}
fi
- name: Build the wheel (python-build-package) Arm64
if: ${{ inputs.build-platform == 'python-build-package' && inputs.architecture == 'arm64' }}
env:
SRC_DIR: ${{ inputs.repository }}
DEPENDENCIES_DIR: c:\temp\dependencies\
shell: cmd
run: |
set CONDA_PREFIX=%DEPENDENCIES_DIR%
set PATH=%PATH%;%DEPENDENCIES_DIR%\Library\bin
set DISTUTILS_USE_SDK=1
set VS_PATH=C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
call "%VS_PATH%" arm64
cd %SRC_DIR%
call .venv\Scripts\activate.bat
pip install --upgrade setuptools==72.1.0 build==1.2.2 wheel
${{ inputs.build-command }}
- name: Build the wheel (setup-py) Arm64
if: ${{ inputs.build-platform == 'setup-py' && inputs.architecture == 'arm64' }}
env:
SRC_DIR: ${{ inputs.repository }}
DEPENDENCIES_DIR: c:\temp\dependencies\
shell: cmd
run: |
set CONDA_PREFIX=%DEPENDENCIES_DIR%
set PATH=%PATH%;%DEPENDENCIES_DIR%\Library\bin
set DISTUTILS_USE_SDK=1
set VS_PATH=C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
call "%VS_PATH%" arm64
cd %SRC_DIR%
call .venv\Scripts\activate.bat
pip install --upgrade setuptools==72.1.0
python setup.py bdist_wheel
- name: Run post-script
working-directory: ${{ inputs.repository }}
env:
POST_SCRIPT: ${{ inputs.post-script }}
ENV_SCRIPT: ${{ inputs.env-script }}
if: ${{ inputs.post-script != '' && inputs.architecture == 'x64' && inputs.cross-compile == false }}
run: |
set -euxo pipefail
source "${BUILD_ENV_FILE}"
${CONDA_RUN} ${ENV_SCRIPT} ${POST_SCRIPT}
- name: Smoke Test X64
if: ${{ inputs.architecture == 'x64' && inputs.cross-compile == false && inputs.is-release-tarball == false }}
env:
ENV_SCRIPT: ${{ inputs.env-script }}
PACKAGE_NAME: ${{ inputs.package-name }}
USE_TRT_RTX: ${{ inputs.use-rtx }}
SMOKE_TEST_SCRIPT: ${{ inputs.smoke-test-script }}
run: |
source "${BUILD_ENV_FILE}"
set -x
WHEEL_NAME=$(ls "${{ inputs.repository }}/dist/")
echo "$WHEEL_NAME"
nvidia-smi
nvcc --version
${CONDA_RUN} pip install "${{ inputs.repository }}/dist/$WHEEL_NAME"
${CONDA_RUN} python -m pip list
if [[ $USE_TRT_RTX == true ]]; then
# TODO: lan to remove this once we have a better way to do a smoke test
echo "Smoke test for TensorRT-RTX is not skipped for now"
else
echo "Skip smoke test in windows"
# if [[ ! -f "${{ inputs.repository }}"/${SMOKE_TEST_SCRIPT} ]]; then
# echo "${{ inputs.repository }}/${SMOKE_TEST_SCRIPT} not found"
# ${CONDA_RUN} "${{ inputs.repository }}/${ENV_SCRIPT}" python -c "import ${PACKAGE_NAME}; print('package version is ', ${PACKAGE_NAME}.__version__)"
# else
# echo "${{ inputs.repository }}/${SMOKE_TEST_SCRIPT} found"
# ${CONDA_RUN} "${{ inputs.repository }}/${ENV_SCRIPT}" python "${{ inputs.repository }}/${SMOKE_TEST_SCRIPT}"
# fi
fi
- name: Smoke Test ARM64
if: inputs.architecture == 'arm64'
env:
PACKAGE_NAME: ${{ inputs.package-name }}
SMOKE_TEST_SCRIPT: ${{ inputs.smoke-test-script }}
SRC_DIR: ${{ inputs.repository }}
run: |
cd $SRC_DIR
source .venv/Scripts/activate
whl=$(find dist -name "${{env.PACKAGE_NAME}}-*.whl" | head -n 1)
pip install $whl
if [[ ! -f ${SMOKE_TEST_SCRIPT} ]]; then
echo "${SMOKE_TEST_SCRIPT} not found"
python -c "import ${PACKAGE_NAME}; print('package version is ', ${PACKAGE_NAME}.__version__)"
else
echo "${SMOKE_TEST_SCRIPT} found"
python "$SMOKE_TEST_SCRIPT"
fi
# NB: Only upload to GitHub after passing smoke tests
- name: Get Artifact name
if: inputs.architecture == 'arm64' || inputs.cross-compile
env:
REPOSITORY: ${{ inputs.repository }}
REF: ${{ inputs.ref }}
PYTHON_VERSION: ${{ matrix.python_version }}
CU_VERSION: ${{ env.CU_VERSION }}
ARCH: ${{ inputs.cross-compile && 'arm64' || inputs.architecture }}
run: |
artifact_cuda_version="${CU_VERSION}"
# The cross-compiled ARM64 sysroot is CUDA 13.4; retain the host CUDA label otherwise.
if [[ "${{ inputs.cross-compile }}" == "true" ]]; then
artifact_cuda_version="cu134"
artifact_name="${ARTIFACT_NAME/_${CU_VERSION}_/_${artifact_cuda_version}_}"
artifact_name="${artifact_name}${{ inputs.python-only && '_python_only' || '' }}${{ inputs.use-rtx && '_rtx' || '' }}"
else
# Standard and RTX builds share the same Python/CUDA matrix. Include
# the backend so their concurrent uploads cannot overwrite or merge
# into one artifact that a test from either channel may download.
artifact_name="${REPOSITORY//\//_}_${REF//\//_}_${PYTHON_VERSION}_${artifact_cuda_version}_${ARCH}${{ inputs.python-only && '_python_only' || '' }}${{ inputs.use-rtx && '_rtx' || '' }}"
fi
echo "ARTIFACT_NAME=${artifact_name}" >> "${GITHUB_ENV}"
- name: Upload wheel to GitHub
if: ${{ inputs.is-release-tarball == false }}
continue-on-error: true
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ inputs.repository }}/dist/
- name: Upload zip artifact to GitHub
if: ${{ inputs.is-release-tarball == true }}
continue-on-error: true
uses: actions/upload-artifact@v6
with:
name: cxx11-zip-${{ env.PYTHON_VERSION }}-${{ env.CU_VERSION }}
path: ${{ inputs.repository }}/release/tarball/
- uses: ./test-infra/.github/actions/teardown-windows
if: inputs.architecture == 'x64' || inputs.cross-compile
name: Teardown Windows
upload:
needs: [build, prepare-upload]
uses: pytorch/test-infra/.github/workflows/_binary_upload.yml@main
# if it is the release wheel or tarball, then skip upload to pytorch index(release wheel are uploaded to pypi)
if: ${{ inputs.python-only == false && inputs.skip-binary-upload == false && inputs.is-release-wheel == false && inputs.is-release-tarball == false }}
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
test-infra-repository: ${{ inputs.test-infra-repository }}
test-infra-ref: ${{ inputs.test-infra-ref }}
build-matrix: ${{ needs.prepare-upload.outputs.build-matrix }}
trigger-event: ${{ inputs.trigger-event }}
# setup-binary-upload builds its artifact name from this input. RTX wheels
# use the same suffix as the build and test jobs; keep the actual build
# architecture above unchanged.
architecture: ${{ inputs.cross-compile && 'arm64' || inputs.architecture }}${{ inputs.use-rtx && '_rtx' || '' }}
secrets:
R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
prepare-upload:
needs: build
runs-on: ubuntu-latest
outputs:
build-matrix: ${{ steps.build-matrix.outputs.value }}
steps:
- id: build-matrix
env:
BUILD_MATRIX: ${{ inputs.build-matrix }}
run: |
if [[ "${{ inputs.cross-compile }}" == "true" ]]; then
# ARM64 cross builds use CUDA 13.4 target libraries and publish a cu134 artifact.
build_matrix="$(jq -c '.include |= map(.desired_cuda = "cu134")' <<< "${BUILD_MATRIX}")"
else
build_matrix="${BUILD_MATRIX}"
fi
echo "value=${build_matrix}" >> "${GITHUB_OUTPUT}"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ inputs.repository }}-${{ inputs.is-release-wheel }}-${{ inputs.is-release-tarball }}-${{ github.event_name == 'workflow_dispatch' }}-${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || 'no-tag' }}-${{ inputs.use-rtx }}-${{ inputs.build-flavor }}
cancel-in-progress: true