Skip to content

Commit 587285b

Browse files
authored
Merge branch 'cuda-int4-int6-metadata-opt' into gguf-cuda-int5
2 parents b02be86 + 7560591 commit 587285b

257 files changed

Lines changed: 10383 additions & 2880 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

.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; }

.ci/scripts/test-cadence-xtensa.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
#
8+
# Build the Cadence Xtensa op-level gtest tests for the configured backend and
9+
# run them on the Instruction Set Simulator (xt-run).
10+
#
11+
# Requires the Xtensa toolchain env to already be set (run
12+
# .ci/scripts/setup-xtensa-tools.sh <backend> first): XTENSA_TOOLCHAIN,
13+
# TOOLCHAIN_VER, XTENSA_CORE, CADENCE_OPT_FLAG, and xt-clang/xt-run on PATH.
14+
#
15+
# Unlike build-cadence-xtensa.sh (the runner, built -fno-exceptions -fno-rtti),
16+
# the gtest tests need exceptions + RTTI, so those flags are NOT set here.
17+
18+
set -euo pipefail
19+
20+
: "${XTENSA_TOOLCHAIN:?run setup-xtensa-tools.sh first}"
21+
: "${TOOLCHAIN_VER:?run setup-xtensa-tools.sh first}"
22+
: "${XTENSA_CORE:?run setup-xtensa-tools.sh first}"
23+
: "${CADENCE_OPT_FLAG:?run setup-xtensa-tools.sh first}"
24+
25+
# Map the optimized-kernel flag to the backend dir + gtest target name.
26+
case "${CADENCE_OPT_FLAG}" in
27+
EXECUTORCH_NNLIB_OPT) TARGET_DIR=hifi ;;
28+
EXECUTORCH_VISION_OPT) TARGET_DIR=vision ;;
29+
EXECUTORCH_FUSION_G3_OPT) TARGET_DIR=fusion_g3 ;;
30+
*)
31+
echo "ERROR: unknown CADENCE_OPT_FLAG='${CADENCE_OPT_FLAG}'" >&2
32+
exit 1
33+
;;
34+
esac
35+
TEST_TARGET="cadence_${TARGET_DIR}_op_tests"
36+
TEST_ELF="cmake-out/backends/cadence/${TARGET_DIR}/operators/tests/${TEST_TARGET}"
37+
38+
NPROC=$(nproc)
39+
echo "=== building ${TEST_TARGET} for ${XTENSA_CORE} (${CADENCE_OPT_FLAG}) ==="
40+
xt-clang --version | head -1
41+
42+
rm -rf cmake-out
43+
cmake \
44+
-DCMAKE_TOOLCHAIN_FILE=./backends/cadence/cadence.cmake \
45+
-DCMAKE_INSTALL_PREFIX=cmake-out \
46+
-DCMAKE_BUILD_TYPE=Release \
47+
-DEXECUTORCH_BUILD_CADENCE=ON \
48+
"-D${CADENCE_OPT_FLAG}=ON" \
49+
-DEXECUTORCH_BUILD_PORTABLE_OPS=ON \
50+
-DEXECUTORCH_BUILD_CADENCE_OP_TESTS=ON \
51+
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \
52+
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
53+
-DEXECUTORCH_ENABLE_LOGGING=ON \
54+
-DEXECUTORCH_BUILD_PTHREADPOOL=OFF \
55+
-DEXECUTORCH_BUILD_CPUINFO=OFF \
56+
-DEXECUTORCH_USE_DL=OFF \
57+
-DEXECUTORCH_BUILD_KERNELS_LLM=OFF \
58+
-DEXECUTORCH_BUILD_DEVTOOLS=OFF \
59+
-DHAVE_FNMATCH_H=OFF \
60+
-DFLATCC_ALLOW_WERROR=OFF \
61+
-DPYTHON_EXECUTABLE="$(which python3)" \
62+
-Bcmake-out .
63+
64+
cmake --build cmake-out --target "${TEST_TARGET}" -j"${NPROC}"
65+
66+
if [[ ! -f "${TEST_ELF}" ]]; then
67+
echo "ERROR: ${TEST_ELF} was not produced" >&2
68+
exit 1
69+
fi
70+
71+
echo "=== running ${TEST_TARGET} on xt-run ==="
72+
LOG=$(mktemp)
73+
# --exit_with_target_code propagates gtest_main's exit code, so a failing test
74+
# fails this step; also assert on the gtest summary lines as a backstop.
75+
xt-run --turbo --exit_with_target_code "${TEST_ELF}" 2>&1 | tee "${LOG}"
76+
if grep -q "\[ FAILED \]" "${LOG}"; then
77+
echo "ERROR: gtest reported failures for ${TEST_TARGET}" >&2
78+
exit 1
79+
fi
80+
if ! grep -q "\[ PASSED \]" "${LOG}"; then
81+
echo "ERROR: ${TEST_TARGET} did not report a gtest PASSED summary" >&2
82+
exit 1
83+
fi
84+
echo "Cadence ${TARGET_DIR} op tests passed on ${XTENSA_CORE}."

.ci/scripts/unittest-linux-cmake.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@ set -eux
1111
# Install from a local tosa-tools checkout when available. If absent in this
1212
# checkout layout, clone the pinned upstream tag and install from there.
1313
if ! python -c "import tosa_serializer" >/dev/null 2>&1; then
14-
TOSA_SERIALIZATION_DIR="./examples/arm/arm-scratch/tosa-tools/serialization"
15-
if [[ ! -d "${TOSA_SERIALIZATION_DIR}" ]]; then
14+
TOSA_TOOLS_DIR="./examples/arm/arm-scratch/tosa-tools"
15+
if [[ ! -d "${TOSA_TOOLS_DIR}" ]]; then
1616
TOSA_TOOLS_DIR="$(mktemp -d /tmp/tosa-tools.XXXXXX)"
17-
git clone --depth 1 --branch v2025.11.2 \
17+
git clone --depth 1 --branch v2026.05.0 \
1818
https://git.gitlab.arm.com/tosa/tosa-tools.git "${TOSA_TOOLS_DIR}"
19-
TOSA_SERIALIZATION_DIR="${TOSA_TOOLS_DIR}/serialization"
2019
fi
2120

2221
# NOTE: Will be removed when tosa-tools is installed via pypi
2322
python -m pip install pybind11==2.10.4
2423
CMAKE_POLICY_VERSION_MINIMUM=3.5 BUILD_PYBIND=1 \
2524
python -m pip install --no-dependencies \
26-
"${TOSA_SERIALIZATION_DIR}"
25+
"${TOSA_TOOLS_DIR}"
2726
python -c "import tosa_serializer"
2827
fi
2928

.ci/scripts/wheel/pre_build_script.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,8 @@ if [[ "${EXECUTORCH_BUILD_VULKAN:-0}" != "0" \
122122
echo "${_glslc_prefix}/bin" >> "${GITHUB_PATH}"
123123
echo "glslc installed: $(command -v glslc)"
124124
fi
125+
else
126+
# This is the Vulkan equivalent of the Windows CUDA force-off above (#20527).
127+
export CMAKE_ARGS="${CMAKE_ARGS:-} -DEXECUTORCH_BUILD_VULKAN=OFF"
128+
echo "CMAKE_ARGS=${CMAKE_ARGS}" >> "${GITHUB_ENV}"
125129
fi

.claude/skills/building/SKILL.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@ conda activate executorch
2323

2424
**Path B — no conda (fall back to venv):**
2525
```bash
26-
# Find a compatible Python (3.10–3.13). On macOS with only Homebrew Python 3.14+,
27-
# install a compatible version first: brew install python@3.12
28-
python3.12 -m venv .executorch-venv # or python3.11, python3.10, python3.13
26+
# Find a compatible Python (3.10–3.14).
27+
python3.12 -m venv .executorch-venv # or python3.11, python3.10, python3.13, python3.14
2928
source .executorch-venv/bin/activate
3029
pip install --upgrade pip
3130
```
3231

3332
**Then verify (either path):**
3433

3534
Run `python --version` and `cmake --version`. Fix automatically:
36-
- **Python not 3.10–3.13**: recreate the env with a correct Python version.
35+
- **Python not 3.10–3.14**: recreate the env with a correct Python version.
3736
- **cmake missing or < 3.24**: run `pip install 'cmake>=3.24'` inside the env.
3837
- **cmake >= 4.0**: works in practice, no action needed.
3938

.claude/skills/qualcomm/new_op_development.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class MyOpVisitor(NodeVisitor):
6666
- Static params: `weight = get_parameter(self.get_node(node.args[1]), self.edge_program)`
6767
- Scalar params → `AddScalarParam`; Array params → `AddTensorParam`
6868
- Data types: axis/dims=`UINT_32`, epsilon=`FLOAT_32`, booleans=`BOOL_8`
69-
- Int64 index tensors: use `.to(torch.int32)` in builder + add op to `I64_IN_OPS` in `_passes/i64_to_i32.py` for CPU fallback safety (see `op_gather.py` pattern)
69+
- Int64 index tensors: If the op **requires** int64 for PyTorch tracing validation (like `gather`, `scatter`), add to `I64_IN_OPS` in `i64_to_i32.py` + `.to(torch.int32)` in builder. If the op **accepts** int32 (like `index_select`), produce int32 directly via `dtype=torch.int32` — no `I64_IN_OPS` entry needed.
7070

7171
## Step 5: Register Builder (`builders/__init__.py`)
7272

@@ -237,7 +237,7 @@ class DecomposeMyOp(ExportPass):
237237
- **Multi-output ops**: Use `wrapper_idx=i` + `getitem` skip op
238238
- **Negative dims**: QNN needs positive → `dim = dim % len(shape)`
239239
- **QCOM_AXIS_ORDER**: `LayoutTransform` permutes NCHW→NHWC; remap axis with `.index(dim)`. `get_tensor()` auto-permutes data.
240-
- **Int64 indices**: Add to `I64_IN_OPS` in `i64_to_i32.py` + `.to(torch.int32)` in builder (see `op_gather.py`)
240+
- **Int64 indices**: Only add to `I64_IN_OPS` if the op **requires** int64 at tracing time (e.g., `gather`, `scatter`). If the op accepts int32 (e.g., `index_select`), produce int32 directly in the decomposition pass. Check PyTorch docs for actual dtype requirements.
241241
- **Recompose passes**: Detect primitive sequences and replace with single native op. Ref: `recompose_pixel_unshuffle.py`
242242
- **`partition/common_defs.py`**: Remove op from `to_be_implemented_operator` when adding support
243243
- **HTP doc bugs**: If runtime fails but docs say supported → test on-device always.

.github/workflows/_xtensa_test.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Reusable: build + run the Cadence Xtensa op-level gtest tests for one core on
2+
# the Instruction Set Simulator (xt-run). Mirrors _xtensa_build.yml's native
3+
# OIDC + docker-run skeleton (running xt-run needs the same licensed toolchain),
4+
# then builds the gtest op-test ELF and runs it on the simulator. The runner
5+
# cross-compile and these op tests are separate build configs (the tests need
6+
# exceptions/RTTI that the runner build disables), so this is a self-contained
7+
# job rather than consuming the runner artifact.
8+
name: xtensa-test
9+
10+
on:
11+
workflow_call:
12+
inputs:
13+
backend:
14+
description: "Cadence backend to test (hifi4 | vision | fusion_g3)"
15+
required: true
16+
type: string
17+
ref:
18+
description: "Git ref to check out"
19+
required: false
20+
type: string
21+
default: ""
22+
23+
jobs:
24+
test:
25+
name: ${{ inputs.backend }}
26+
runs-on: linux.2xlarge
27+
environment: cadence
28+
permissions:
29+
id-token: write
30+
contents: read
31+
steps:
32+
- name: Checkout executorch
33+
uses: actions/checkout@v4
34+
with:
35+
submodules: recursive
36+
ref: ${{ inputs.ref }}
37+
38+
- name: Calculate docker image
39+
id: calculate-docker-image
40+
uses: pytorch/test-infra/.github/actions/calculate-docker-image@main
41+
with:
42+
docker-image-name: ci-image:executorch-ubuntu-22.04-clang12
43+
44+
- name: Pull docker image
45+
run: docker pull "${{ steps.calculate-docker-image.outputs.docker-image }}"
46+
47+
- name: Assume Cadence artifacts role (host OIDC)
48+
uses: aws-actions/configure-aws-credentials@v4
49+
with:
50+
role-to-assume: ${{ vars.CADENCE_CI_AWS_ROLE }}
51+
aws-region: ${{ vars.CADENCE_CI_AWS_REGION }}
52+
53+
- name: Build and run op tests on xt-run
54+
env:
55+
DOCKER_IMAGE: ${{ steps.calculate-docker-image.outputs.docker-image }}
56+
BACKEND: ${{ inputs.backend }}
57+
XTENSA_S3_BUCKET: ${{ vars.CADENCE_CI_S3_BUCKET }}
58+
shell: bash
59+
run: |
60+
set -eux
61+
# OIDC/role assumption already happened on the host above; pass the
62+
# resulting AWS creds and the store/backend into the CI image, where
63+
# the toolchain download + op-test build + xt-run happen.
64+
docker run --rm \
65+
-e BACKEND -e XTENSA_S3_BUCKET \
66+
-e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN \
67+
-e AWS_DEFAULT_REGION -e AWS_REGION \
68+
-v "${GITHUB_WORKSPACE}:/work/executorch" -w /work/executorch \
69+
"${DOCKER_IMAGE}" \
70+
bash -c '
71+
set -exo pipefail
72+
eval "$(/opt/conda/bin/conda shell.bash hook)"
73+
conda activate "$(conda env list --json | jq -r ".envs | .[-1]")"
74+
./install_requirements.sh > /dev/null
75+
pip install --quiet awscli
76+
# hifi4/fusion_g3 optimized kernels need the foss-xtensa nnlib
77+
# sources, which are not vendored in executorch; the cadence
78+
# installer clones them. vision has no nnlib dependency.
79+
if [ "${BACKEND}" != "vision" ]; then
80+
backends/cadence/install_requirements.sh
81+
fi
82+
source .ci/scripts/setup-xtensa-tools.sh "${BACKEND}"
83+
.ci/scripts/test-cadence-xtensa.sh
84+
'

.github/workflows/add-unanswered-to-project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
6464
// List of organization logins (lowercased) to exclude members of
6565
const excludedOrgs = new Set([
66-
"meta", "facebook", "pytorch", "arm", "apple", "qualcomm", "nxp", "mediatek", "cadence", "intel", "samsung",
66+
"meta", "facebook", "pytorch", "arm", "apple", "qualcomm", "nxp", "mediatek", "cadence", "intel", "samsung", "arm ltd.",
6767
"@meta", "@facebook", "@pytorch", "@arm", "@apple", "@qualcomm", "@nxp", "@mediatek", "@cadence", "@intel", "@samsung"
6868
]);
6969

.github/workflows/build-cadence-runner.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@ jobs:
8787
backend: hifi4
8888
ref: ${{ (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.pull_request.head.sha || github.sha }}
8989

90+
# Op-level gtest tests on the Xtensa ISS, mirroring cpu-build -> cpu-test. The
91+
# op tests are a self-contained cross-compile (the gtests need exceptions and
92+
# RTTI that the runner build disables), so this does not consume hifi-build's
93+
# artifact; needs: hifi-build only to fail fast when the backend cannot build.
94+
hifi-op-test:
95+
needs: hifi-build
96+
if: >-
97+
github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' ||
98+
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
99+
(github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository &&
100+
contains(github.event.pull_request.labels.*.name, 'CLA Signed') && contains(github.event.pull_request.labels.*.name, 'meta-exported'))
101+
permissions:
102+
id-token: write
103+
contents: read
104+
uses: ./.github/workflows/_xtensa_test.yml
105+
with:
106+
backend: hifi4
107+
ref: ${{ (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.pull_request.head.sha || github.sha }}
108+
90109
vision-build:
91110
if: >-
92111
github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' ||

0 commit comments

Comments
 (0)