Skip to content

Commit cd7fb98

Browse files
authored
Merge branch 'main' into baris/1286838-keep-internal-shared-qspec-uint8
2 parents 9245362 + c2b273e commit cd7fb98

1,192 files changed

Lines changed: 55954 additions & 10250 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.ci/docker/requirements-ci.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sympy>=1.13.3
66
timm==0.6.13
77
tomli==2.0.1
88
torchsr==1.0.4
9-
transformers==4.56.1
9+
transformers==5.3.0
1010
zstd==1.5.5.1
1111
pandas>=2.2.2; python_version >= '3.10'
1212
pytest==7.2.0
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright (c) Qualcomm Innovation Center, Inc.
2+
# All rights reserved
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
$ErrorActionPreference = "Stop"
8+
9+
conda create --yes --quiet -n et python=3.12
10+
conda activate et
11+
12+
# Install CI requirements
13+
pip install -r .ci/docker/requirements-ci.txt
14+
15+
# Provision the QNN SDK
16+
if ($env:QNN_SDK_ROOT -and (Test-Path -Path $env:QNN_SDK_ROOT)) {
17+
Write-Host "Using existing QNN SDK at $env:QNN_SDK_ROOT"
18+
} else {
19+
# Resolve the QNN_VERSION and QNN_ZIP_URL
20+
$qnnInfo = python -c "import sys; sys.path.insert(0, r'backends\qualcomm\scripts'); import download_qnn_sdk as d; print(d.QNN_VERSION); print(d.QNN_ZIP_URL)"
21+
if ($LASTEXITCODE -ne 0 -or $qnnInfo.Count -lt 2) {
22+
Write-Error "Failed to read QNN_VERSION and QNN_ZIP_URL from download_qnn_sdk.py."
23+
exit 1
24+
}
25+
$qnnVersion = $qnnInfo[0].Trim()
26+
$qnnZipUrl = $qnnInfo[1].Trim()
27+
28+
$qnnInstallDir = Join-Path $env:TEMP "qnn"
29+
New-Item -Path $qnnInstallDir -ItemType Directory -Force | Out-Null
30+
$qnnZip = Join-Path $env:TEMP "qnn_sdk.zip"
31+
Write-Host "Downloading QNN SDK v$qnnVersion ..."
32+
$ProgressPreference = "SilentlyContinue"
33+
Invoke-WebRequest -Uri $qnnZipUrl -OutFile $qnnZip
34+
Write-Host "Extracting QNN SDK ..."
35+
Expand-Archive -Path $qnnZip -DestinationPath $qnnInstallDir -Force
36+
Remove-Item -Path $qnnZip -Force
37+
38+
$env:QNN_SDK_ROOT = Join-Path $qnnInstallDir "qairt\$qnnVersion"
39+
Write-Host "Set QNN_SDK_ROOT=$env:QNN_SDK_ROOT"
40+
}
41+
42+
if (-not (Test-Path -Path (Join-Path $env:QNN_SDK_ROOT "include\QNN"))) {
43+
Write-Error "QNN SDK layout unexpected: missing include\QNN under $env:QNN_SDK_ROOT"
44+
exit 1
45+
}
46+
47+
# Test x86_64 Windows host build
48+
.\backends\qualcomm\scripts\build.ps1 -SkipArm64Windows -Release
49+
50+
$x86Artifacts = @(
51+
"build-x86_64-windows\backends\qualcomm\Release\PyQnnManagerAdaptor*.pyd",
52+
"build-x86_64-windows\backends\qualcomm\Release\qnn_executorch_backend.dll",
53+
"build-x86_64-windows\examples\qualcomm\executor_runner\Release\qnn_executor_runner.exe"
54+
)
55+
foreach ($artifact in $x86Artifacts) {
56+
if (-not (Get-ChildItem -Path $artifact -ErrorAction SilentlyContinue)) {
57+
Write-Error "ERROR: x86_64 artifact not found: $artifact"
58+
exit 1
59+
}
60+
}
61+
62+
# The ARM64 MSVC toolchain is currently not installed in the Windows CI
63+
# environment. Enabling this build configuration results in build failures
64+
# due to the missing ARM64 platform definition.
65+
# `.\backends\qualcomm\scripts\build.ps1 -SkipX86Windows -Release`
66+
#
67+
# Temporarily disable this build option until ARM64 MSVC support is available
68+
# in CI. The configuration can be re-enabled in a future update.
69+
70+
Write-Host "PASSED: QNN backend Windows MSVC build completed"

.ci/scripts/setup-vulkan-linux-deps.sh

Lines changed: 121 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#!/bin/bash
32
# Copyright (c) Meta Platforms, Inc. and affiliates.
43
# All rights reserved.
@@ -22,7 +21,7 @@ install_swiftshader() {
2221
tar -C "${_swiftshader_dir}" -xzf "${_tmp_archive}"
2322

2423
export VK_ICD_FILENAMES="${_swiftshader_dir}/swiftshader/build/Linux/vk_swiftshader_icd.json"
25-
export LD_LIBRARY_PATH="${_swiftshader_dir}/swiftshader/build/Linux/"
24+
export LD_LIBRARY_PATH="${_swiftshader_dir}/swiftshader/build/Linux/:${LD_LIBRARY_PATH:-}"
2625
export ETVK_USING_SWIFTSHADER=1
2726
}
2827

@@ -43,7 +42,125 @@ install_vulkan_sdk() {
4342
export PATH="${PATH}:${_vulkan_sdk_dir}/${VULKAN_SDK_VERSION}/x86_64/bin/"
4443
}
4544

45+
_maybe_sudo() {
46+
if [ "$(id -u)" -eq 0 ]; then
47+
"$@"
48+
else
49+
sudo "$@"
50+
fi
51+
}
52+
53+
install_glslc() {
54+
# The glslc shipped in the LunarG SDK is dynamically linked against a newer
55+
# glibc/libstdc++ than the manylinux_2_28 / AlmaLinux 8 CUDA runner image
56+
# provides (glibc 2.28), where it fails to load with "GLIBC_2.29 not found".
57+
# conda-forge's shaderc is built against an old sysroot, runs there, and is
58+
# recent enough for the GL_EXT_integer_dot_product / GL_KHR_cooperative_matrix
59+
# extensions the Vulkan shaders use. Install it into an isolated prefix so the
60+
# base conda env that builds ExecuTorch is left untouched, then put it on PATH.
61+
_glslc_prefix=/tmp/shaderc
62+
conda create -y -p "${_glslc_prefix}" -c conda-forge shaderc
63+
export PATH="${_glslc_prefix}/bin:${PATH}"
64+
}
65+
66+
install_vulkan_loader() {
67+
# libvulkan.so.1 (the Khronos loader that volk dlopen()s at runtime) is not part
68+
# of the NVIDIA driver and is absent from the CUDA builder image; vulkan-tools
69+
# provides vulkaninfo for the device sanity check. Both ship as native el8 RPMs.
70+
if command -v dnf >/dev/null 2>&1; then
71+
_maybe_sudo dnf install -y vulkan-loader vulkan-tools
72+
fi
73+
}
74+
75+
_find_nvidia_vulkan_library() {
76+
# NVIDIA implements its Vulkan ICD inside libGLX_nvidia.so.0. The NVIDIA
77+
# container runtime mounts this library into the container (it is pulled from
78+
# the driver's ldcache when NVIDIA_DRIVER_CAPABILITIES includes graphics/all),
79+
# so prefer ldconfig and fall back to the usual mount locations.
80+
local lib cand
81+
lib="$(ldconfig -p 2>/dev/null | awk '/libGLX_nvidia\.so\.0/ {print $NF; exit}')"
82+
if [ -z "${lib}" ]; then
83+
for cand in /usr/lib64/libGLX_nvidia.so.0 \
84+
/usr/lib/x86_64-linux-gnu/libGLX_nvidia.so.0 \
85+
/usr/lib/libGLX_nvidia.so.0; do
86+
if [ -e "${cand}" ]; then
87+
lib="${cand}"
88+
break
89+
fi
90+
done
91+
fi
92+
printf '%s' "${lib}"
93+
}
94+
95+
_vulkan_has_real_device() {
96+
# True if the loader enumerates a hardware GPU. vulkaninfo can exit non-zero
97+
# for unrelated reasons (no display/WSI), so key off the reported deviceType.
98+
command -v vulkaninfo >/dev/null 2>&1 || return 0
99+
vulkaninfo --summary 2>/dev/null |
100+
grep -qE 'PHYSICAL_DEVICE_TYPE_(DISCRETE|INTEGRATED|VIRTUAL)_GPU'
101+
}
102+
103+
setup_real_gpu_icd() {
104+
# Select a Vulkan ICD so the runtime exercises the real GPU when one is usable.
105+
# Two quirks of the CUDA CI image make this non-trivial:
106+
# 1. The NVIDIA container runtime mounts the driver's Vulkan library but does
107+
# not register its ICD manifest, so the loader never discovers the GPU on
108+
# its own. We synthesize the manifest and pin the loader to it.
109+
# 2. Installing vulkan-loader/vulkan-tools pulls in mesa-vulkan-drivers,
110+
# which drop Intel/AMD/lavapipe manifests for absent hardware. lavapipe
111+
# fails vkCreateInstance on this image and, because the loader walks every
112+
# manifest in icd.d, that poisons device enumeration for the whole
113+
# process. Pinning VK_ICD_FILENAMES makes the loader ignore icd.d, so the
114+
# broken stubs cannot interfere.
115+
local nvidia_lib
116+
nvidia_lib="$(_find_nvidia_vulkan_library)"
117+
if [ -n "${nvidia_lib}" ]; then
118+
local icd=/tmp/nvidia_icd.json
119+
cat >"${icd}" <<JSON
120+
{
121+
"file_format_version": "1.0.0",
122+
"ICD": {
123+
"library_path": "${nvidia_lib}",
124+
"api_version": "1.3.0"
125+
}
126+
}
127+
JSON
128+
export VK_ICD_FILENAMES="${icd}"
129+
unset ETVK_USING_SWIFTSHADER || true
130+
if _vulkan_has_real_device; then
131+
echo "Real NVIDIA GPU selected; pinned Vulkan ICD to ${nvidia_lib}"
132+
return
133+
fi
134+
echo "WARNING: ${nvidia_lib} present but no GPU enumerated; using SwiftShader."
135+
# Surface why the NVIDIA driver did not enumerate (e.g. a missing dependency
136+
# of libGLX_nvidia, or no render node) so the fallback is diagnosable in CI.
137+
if command -v vulkaninfo >/dev/null 2>&1; then
138+
echo "--- NVIDIA Vulkan ICD diagnostic ---"
139+
VK_LOADER_DEBUG=warn vulkaninfo --summary 2>&1 | head -40 || true
140+
echo "--- end diagnostic ---"
141+
fi
142+
unset VK_ICD_FILENAMES
143+
else
144+
echo "WARNING: no NVIDIA Vulkan driver library found; using SwiftShader."
145+
fi
146+
install_swiftshader
147+
}
148+
46149
VULKAN_SDK_VERSION="1.4.321.1"
47150

48-
install_swiftshader
49-
install_vulkan_sdk "${VULKAN_SDK_VERSION}"
151+
# The no-argument default installs SwiftShader so the existing CPU-runner CI is
152+
# unchanged. Pass "real-gpu" to prefer a real system ICD when one is present.
153+
case "${1:-swiftshader}" in
154+
real-gpu)
155+
# Do not download the LunarG SDK here: its prebuilt glslc cannot run on the
156+
# old-glibc CUDA image. glslc comes from conda-forge and the loader from the
157+
# system package manager instead.
158+
install_vulkan_loader
159+
install_glslc
160+
setup_real_gpu_icd
161+
;;
162+
swiftshader | *)
163+
install_swiftshader
164+
install_vulkan_sdk "${VULKAN_SDK_VERSION}"
165+
;;
166+
esac
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Install glslc (the Vulkan shader compiler) on Windows via conda-forge's
8+
# shaderc package, and make sure it is on PATH. glslc is the only build-time
9+
# Vulkan dependency -- the Vulkan headers and the volk loader come from the
10+
# in-tree submodules -- so this avoids depending on the heavyweight LunarG SDK
11+
# installer. Requires conda to be available (the callers create/activate an env).
12+
13+
$ErrorActionPreference = "Stop"
14+
15+
Write-Host "Installing shaderc (provides glslc) from conda-forge..."
16+
conda install -y -c conda-forge shaderc
17+
if ($LASTEXITCODE -ne 0) {
18+
Write-Error "Failed to install shaderc from conda-forge (exit ${LASTEXITCODE})"
19+
exit 1
20+
}
21+
22+
$glslc = Get-Command glslc -ErrorAction SilentlyContinue
23+
if (-not $glslc) {
24+
Write-Error "glslc not found on PATH after installing shaderc"
25+
exit 1
26+
}
27+
28+
# Expose glslc to the current process and, when running as a GitHub Actions step,
29+
# to subsequent steps.
30+
$glslcDir = Split-Path -Parent $glslc.Source
31+
$env:PATH = "${glslcDir};${env:PATH}"
32+
if ($env:GITHUB_PATH) {
33+
Add-Content -Path $env:GITHUB_PATH -Value $glslcDir
34+
}
35+
36+
Write-Host "glslc available at $($glslc.Source)"
37+
& glslc --version

.ci/scripts/setup-webgpu-linux-deps.sh

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
# * Dawn : Google's official nightly prebuilt, downloaded directly from
1111
# github.com/google/dawn/releases (pinned tag+rev+sha256) -- the same
1212
# "fetch a pinned upstream prebuilt" pattern used for other CI deps.
13-
# * SwiftShader : built from source at a pinned rev compatible with the Dawn
14-
# above (the ossci prebuilt is from 2020, too old for current Dawn). No S3.
13+
# * SwiftShader : a cached prebuilt (gha-artifacts, keyed by rev) when present,
14+
# else built from source at a pinned rev compatible with the Dawn above
15+
# (the ossci prebuilt is from 2020, too old for current Dawn).
1516
# Dawn (Chrome's WebGPU impl; its WGSL compiler Tint is the spec reference) on
1617
# SwiftShader gives a headless, deterministic, spec-faithful CLI backend.
1718
#
@@ -75,17 +76,30 @@ fi
7576
# current Dawn; build a matching modern SwiftShader instead. Self-contained
7677
# cmake build (vendored LLVM); the ICD lands under build/<OS>/.
7778
if [[ ! -d "${_ss_dir}/build" ]]; then
78-
if [[ ! -d "${_ss_dir}/.git" ]]; then
79-
git clone https://github.com/google/swiftshader "${_ss_dir}"
79+
# Try a cached prebuilt (keyed by rev) before the expensive from-source build;
80+
# mirrors the gha-artifacts download-or-build pattern in .ci/scripts/utils.sh.
81+
_ss_key="swiftshader-${SWIFTSHADER_REV}-ubuntu-latest"
82+
_ss_cache_url="https://gha-artifacts.s3.us-east-1.amazonaws.com/cached_artifacts/pytorch/executorch/webgpu/${_ss_key}.tar.gz"
83+
if curl --silent --show-error --location --fail --retry 3 --retry-all-errors \
84+
--output "/tmp/${_ss_key}.tar.gz" "${_ss_cache_url}"; then
85+
# Cache hit: restore the prebuilt build/ tree (ICD + libs).
86+
mkdir -p "${_ss_dir}/build"
87+
tar -C "${_ss_dir}/build" -xzf "/tmp/${_ss_key}.tar.gz"
88+
else
89+
# Cache miss: build from source. After a rev bump, seed the key in S3
90+
# (tar -C build/ . -> the cache URL above) to skip this next run.
91+
if [[ ! -d "${_ss_dir}/.git" ]]; then
92+
git clone https://github.com/google/swiftshader "${_ss_dir}"
93+
fi
94+
git -C "${_ss_dir}" checkout "${SWIFTSHADER_REV}"
95+
# vk_swiftshader's deps are vendored in-tree; tolerate unreachable
96+
# disabled-feature submodules (angle, test-only) failing to fetch.
97+
git -C "${_ss_dir}" submodule update --init --recursive || true
98+
cmake -S "${_ss_dir}" -B "${_ss_dir}/build" -DCMAKE_BUILD_TYPE=Release \
99+
-DSWIFTSHADER_BUILD_TESTS=OFF -DSWIFTSHADER_BUILD_PVR=OFF \
100+
-DSWIFTSHADER_BUILD_BENCHMARKS=OFF
101+
cmake --build "${_ss_dir}/build" --parallel "$(nproc)" --target vk_swiftshader
80102
fi
81-
git -C "${_ss_dir}" checkout "${SWIFTSHADER_REV}"
82-
# vk_swiftshader's deps are vendored in-tree; tolerate unreachable
83-
# disabled-feature submodules (angle, test-only) failing to fetch.
84-
git -C "${_ss_dir}" submodule update --init --recursive || true
85-
cmake -S "${_ss_dir}" -B "${_ss_dir}/build" -DCMAKE_BUILD_TYPE=Release \
86-
-DSWIFTSHADER_BUILD_TESTS=OFF -DSWIFTSHADER_BUILD_PVR=OFF \
87-
-DSWIFTSHADER_BUILD_BENCHMARKS=OFF
88-
cmake --build "${_ss_dir}/build" --parallel "$(nproc)" --target vk_swiftshader
89103
fi
90104
_ss_icd="$(find "${_ss_dir}/build" -name vk_swiftshader_icd.json 2>/dev/null | head -1)"
91105
[[ -n "${_ss_icd}" ]] || { echo "ERROR: SwiftShader ICD not found after build" >&2; exit 1; }
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Build-validation for the Vulkan backend under MSVC on Windows. Mirrors
8+
# setup-windows-msvc.ps1 but installs glslc (the Vulkan shader compiler) and
9+
# configures/builds the vulkan_backend target. This is a bring-up job: it exists
10+
# to surface MSVC portability issues in the Vulkan/volk/VMA code, so it may need
11+
# iteration.
12+
13+
conda create --yes --quiet -n et python=3.12
14+
conda activate et
15+
16+
# Install cmake
17+
conda install -y cmake
18+
19+
# Activate the VS environment - this is required for MSVC to work.
20+
& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64
21+
22+
# Install glslc (via conda-forge shaderc) and put it on PATH in this process.
23+
.ci/scripts/setup-vulkan-windows-deps.ps1
24+
25+
# Install CI requirements
26+
pip install -r .ci/docker/requirements-ci.txt
27+
28+
$buildDir = "cmake-out-vulkan"
29+
if (Test-Path -Path $buildDir) {
30+
Remove-Item -Path $buildDir -Recurse -Force
31+
}
32+
New-Item -Path $buildDir -ItemType Directory
33+
34+
cmake -S . -B $buildDir `
35+
-DCMAKE_BUILD_TYPE=Release `
36+
-DEXECUTORCH_BUILD_VULKAN=ON `
37+
-DPYTHON_EXECUTABLE=python
38+
39+
if ($LASTEXITCODE -ne 0) {
40+
Write-Host "CMake configuration failed. Exit code: $LASTEXITCODE."
41+
exit $LASTEXITCODE
42+
}
43+
44+
cmake --build $buildDir --config Release --target vulkan_backend -j16
45+
46+
if ($LASTEXITCODE -ne 0) {
47+
Write-Host "Vulkan backend MSVC build failed. Exit code: $LASTEXITCODE."
48+
exit $LASTEXITCODE
49+
}
50+
51+
Write-Host "Vulkan backend MSVC build completed successfully!"

.ci/scripts/setup-windows.ps1

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
param (
2-
[string]$editable = "false"
2+
[string]$editable = "false",
3+
[string]$cpuOnly = "false"
34
)
45

56
conda create --yes --quiet -n et python=3.12
@@ -13,6 +14,16 @@ conda activate et
1314
# Install test dependencies
1415
pip install -r .ci/docker/requirements-ci.txt
1516

17+
# The Windows CI image ships CUDA toolkits on PATH, so install_executorch
18+
# (setup.py) auto-enables EXECUTORCH_BUILD_CUDA whenever the detected nvcc
19+
# version is in SUPPORTED_CUDA_VERSIONS. CPU-only jobs install CPU torch, so a
20+
# CUDA build of _portable_lib then fails to load its CUDA DLLs at import time
21+
# ("DLL load failed while importing _portable_lib"). Force a CPU-only build
22+
# when the caller asks for it.
23+
if ($cpuOnly -eq 'true') {
24+
$env:CMAKE_ARGS = "$env:CMAKE_ARGS -DEXECUTORCH_BUILD_CUDA=OFF"
25+
}
26+
1627
if ($editable -eq 'true') {
1728
install_executorch.bat --editable
1829
} else {

0 commit comments

Comments
 (0)