Skip to content

Commit 3a4ffce

Browse files
committed
Merge remote-tracking branch 'origin/main' into start-pos-api-llava-7-9
2 parents d62be5a + 02fafa8 commit 3a4ffce

File tree

1,296 files changed

+56966
-22037
lines changed

Some content is hidden

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

1,296 files changed

+56966
-22037
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
40b02a2dc61bbf901a2df91719f47c98d65368ec
1+
828ae02053a6e0e20a2dfd6e737ba10c6f4dee6b
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e7152ff8a6a929a0db7f3f4a72a5b6d471769cd3
1+
53a2908a10f414a2f85caa06703a26a40e873869

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set -ex
1111

1212
download_ai_lite_core() {
1313
API_BASE="https://soc-developer.semiconductor.samsung.com/api/v1/resource/ai-litecore/download"
14-
API_KEY="kn10SoSY3hkC-9Qny5TqD2mnqVrlupv3krnjLeBt5cY"
14+
API_KEY=$SAMSUNG_AI_LITECORE_KEY
1515

1616
VERSION="0.5"
1717
OS_NAME="Ubuntu 22.04"
@@ -54,15 +54,6 @@ install_enn_backend() {
5454
rm -rf "${NDK_INSTALLATION_DIR}" && sudo mkdir -p "${NDK_INSTALLATION_DIR}"
5555
ANDROID_NDK_VERSION=r27b
5656

57-
pushd .
58-
cd /tmp
59-
curl -Os --retry 3 "https://ossci-android.s3.amazonaws.com/android-ndk-${ANDROID_NDK_VERSION}-linux.zip"
60-
unzip -qo "android-ndk-${ANDROID_NDK_VERSION}-linux.zip"
61-
62-
# Print the content for manual verification
63-
ls -lah "android-ndk-${ANDROID_NDK_VERSION}"
64-
sudo mv "android-ndk-${ANDROID_NDK_VERSION}"/* "${NDK_INSTALLATION_DIR}"
65-
popd
6657
# build Exynos backend
6758
export ANDROID_NDK_ROOT=${ANDROID_NDK_ROOT:-/opt/ndk}
6859
bash backends/samsung/build.sh --build all

.ci/scripts/setup-windows.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
param (
2-
[string]$editable = $false
2+
[string]$editable = "false"
33
)
44

55
conda create --yes --quiet -n et python=3.12

.ci/scripts/test-cuda-build.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
set -exu
9+
10+
CUDA_VERSION=${1:-"12.6"}
11+
12+
echo "=== Testing ExecutorTorch CUDA ${CUDA_VERSION} Build ==="
13+
14+
# Function to build and test ExecutorTorch with CUDA support
15+
test_executorch_cuda_build() {
16+
local cuda_version=$1
17+
18+
echo "Building ExecutorTorch with CUDA ${cuda_version} support..."
19+
echo "ExecutorTorch will automatically detect CUDA and install appropriate PyTorch wheel"
20+
21+
# Check available resources before starting
22+
echo "=== System Information ==="
23+
echo "Available memory: $(free -h | grep Mem | awk '{print $2}')"
24+
echo "Available disk space: $(df -h . | tail -1 | awk '{print $4}')"
25+
echo "CPU cores: $(nproc)"
26+
echo "CUDA version check:"
27+
nvcc --version || echo "nvcc not found"
28+
nvidia-smi || echo "nvidia-smi not found"
29+
30+
# Set CMAKE_ARGS to enable CUDA build - ExecutorTorch will handle PyTorch installation automatically
31+
export CMAKE_ARGS="-DEXECUTORCH_BUILD_CUDA=ON"
32+
33+
echo "=== Starting ExecutorTorch Installation ==="
34+
# Install ExecutorTorch with CUDA support with timeout and error handling
35+
timeout 5400 ./install_executorch.sh || {
36+
local exit_code=$?
37+
echo "ERROR: install_executorch.sh failed with exit code: $exit_code"
38+
if [ $exit_code -eq 124 ]; then
39+
echo "ERROR: Installation timed out after 90 minutes"
40+
fi
41+
exit $exit_code
42+
}
43+
44+
echo "SUCCESS: ExecutorTorch CUDA build completed"
45+
46+
# Verify the installation
47+
echo "=== Verifying ExecutorTorch CUDA Installation ==="
48+
49+
# Test that ExecutorTorch was built successfully
50+
python -c "
51+
import executorch
52+
print('SUCCESS: ExecutorTorch imported successfully')
53+
"
54+
55+
# Test CUDA availability and show details
56+
python -c "
57+
try:
58+
import torch
59+
print('INFO: PyTorch version:', torch.__version__)
60+
print('INFO: CUDA available:', torch.cuda.is_available())
61+
62+
if torch.cuda.is_available():
63+
print('SUCCESS: CUDA is available for ExecutorTorch')
64+
print('INFO: CUDA version:', torch.version.cuda)
65+
print('INFO: GPU device count:', torch.cuda.device_count())
66+
print('INFO: Current GPU device:', torch.cuda.current_device())
67+
print('INFO: GPU device name:', torch.cuda.get_device_name())
68+
69+
# Test basic CUDA tensor operation
70+
device = torch.device('cuda')
71+
x = torch.randn(10, 10).to(device)
72+
y = torch.randn(10, 10).to(device)
73+
z = torch.mm(x, y)
74+
print('SUCCESS: CUDA tensor operation completed on device:', z.device)
75+
print('INFO: Result tensor shape:', z.shape)
76+
77+
print('SUCCESS: ExecutorTorch CUDA integration verified')
78+
else:
79+
print('WARNING: CUDA not detected, but ExecutorTorch built successfully')
80+
exit(1)
81+
except Exception as e:
82+
print('ERROR: ExecutorTorch CUDA test failed:', e)
83+
exit(1)
84+
"
85+
86+
echo "SUCCESS: ExecutorTorch CUDA ${cuda_version} build and verification completed successfully"
87+
}
88+
89+
# Main execution
90+
echo "Current working directory: $(pwd)"
91+
echo "Directory contents:"
92+
ls -la
93+
94+
# Run the CUDA build test
95+
test_executorch_cuda_build "${CUDA_VERSION}"

.ci/scripts/test_backend_linux.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ if [[ "$FLOW" == *qnn* ]]; then
3939
fi
4040

4141
if [[ "$FLOW" == *vulkan* ]]; then
42-
# Setup swiftshader and Vulkan SDK which are required to build the Vulkan delegate
42+
# Setup swiftshader and Vulkan SDK which are required to build the Vulkan delegate.
4343
source .ci/scripts/setup-vulkan-linux-deps.sh
4444

4545
EXTRA_BUILD_ARGS+=" -DEXECUTORCH_BUILD_VULKAN=ON"
4646
fi
4747

48+
if [[ "$FLOW" == *arm* ]]; then
49+
# Setup ARM deps.
50+
.ci/scripts/setup-arm-baremetal-tools.sh
51+
fi
52+
4853
# We need the runner to test the built library.
4954
PYTHON_EXECUTABLE=python CMAKE_ARGS="$EXTRA_BUILD_ARGS" .ci/scripts/setup-linux.sh --build-tool cmake --build-mode Release --editable true
5055

.ci/scripts/test_llava.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ run_and_verify() {
149149

150150
# verify result.txt
151151
RESULT=$(cat result.txt)
152-
EXPECTED_PREFIX="ASSISTANT: image captures a basketball game in progress, with"
152+
EXPECTED_PREFIX="ASSISTANT: The image captures a basketball game in progress, with"
153153

154154
if [[ "${RESULT}" == *"${EXPECTED_PREFIX}"* ]]; then
155155
echo "Expected result prefix: ${EXPECTED_PREFIX}"

.ci/scripts/test_model.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function ExportModel-Xnnpack {
3434
[bool]$quantize
3535
)
3636

37-
if $(quantize) {
37+
if ($quantize) {
3838
python -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate --quantize | Write-Host
3939
$modelFile = "$($modelName)_xnnpack_q8.pte"
4040
} else {

.ci/scripts/test_model.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ test_model_with_xnnpack() {
131131
return 0
132132
fi
133133

134-
# Delegation
134+
# Delegation and test with pybindings
135135
if [[ ${WITH_QUANTIZATION} == true ]]; then
136136
SUFFIX="q8"
137-
"${PYTHON_EXECUTABLE}" -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate --quantize
137+
"${PYTHON_EXECUTABLE}" -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate --quantize --test_after_export
138138
else
139139
SUFFIX="fp32"
140-
"${PYTHON_EXECUTABLE}" -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate
140+
"${PYTHON_EXECUTABLE}" -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate --test_after_export
141141
fi
142142

143143
OUTPUT_MODEL_PATH="${MODEL_NAME}_xnnpack_${SUFFIX}.pte"
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
# -------------------------
5+
# Args / flags
6+
# -------------------------
7+
TEST_WITH_RUNNER=0
8+
MODEL_NAME=""
9+
10+
# Parse args
11+
if [[ $# -lt 1 ]]; then
12+
echo "Usage: $0 <model_name> [--test_with_runner]"
13+
echo "Supported model_name values: qwen3_4b, phi_4_mini"
14+
exit 1
15+
fi
16+
17+
MODEL_NAME="$1"
18+
shift
19+
20+
while [[ $# -gt 0 ]]; do
21+
case "$1" in
22+
--test_with_runner)
23+
TEST_WITH_RUNNER=1
24+
;;
25+
-h|--help)
26+
echo "Usage: $0 <model_name> [--test_with_runner]"
27+
echo " model_name: qwen3_4b | phi_4_mini"
28+
echo " --test_with_runner: build ET + run llama_main to sanity-check the export"
29+
exit 0
30+
;;
31+
*)
32+
echo "Unknown option: $1"
33+
exit 1
34+
;;
35+
esac
36+
shift
37+
done
38+
39+
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
40+
PYTHON_EXECUTABLE=python3
41+
fi
42+
43+
MODEL_OUT=model.pte
44+
45+
case "$MODEL_NAME" in
46+
qwen3_4b)
47+
echo "Running Qwen3-4B export..."
48+
HF_MODEL_DIR=$(hf download pytorch/Qwen3-4B-INT8-INT4)
49+
EXPECTED_MODEL_SIZE_UPPER_BOUND=$((3 * 1024 * 1024 * 1024)) # 3GB
50+
$PYTHON_EXECUTABLE -m executorch.examples.models.qwen3.convert_weights \
51+
$HF_MODEL_DIR \
52+
pytorch_model_converted.bin
53+
54+
$PYTHON_EXECUTABLE -m executorch.examples.models.llama.export_llama \
55+
--model "qwen3_4b" \
56+
--checkpoint pytorch_model_converted.bin \
57+
--params examples/models/qwen3/config/4b_config.json \
58+
--output_name $MODEL_OUT \
59+
-kv \
60+
--use_sdpa_with_kv_cache \
61+
-X \
62+
--xnnpack-extended-ops \
63+
--max_context_length 1024 \
64+
--max_seq_length 1024 \
65+
--dtype fp32 \
66+
--metadata '{"get_bos_id":199999, "get_eos_ids":[200020,199999]}'
67+
;;
68+
69+
phi_4_mini)
70+
echo "Running Phi-4-mini export..."
71+
HF_MODEL_DIR=$(hf download pytorch/Phi-4-mini-instruct-INT8-INT4)
72+
EXPECTED_MODEL_SIZE_UPPER_BOUND=$((3 * 1024 * 1024 * 1024)) # 3GB
73+
$PYTHON_EXECUTABLE -m executorch.examples.models.phi_4_mini.convert_weights \
74+
$HF_MODEL_DIR \
75+
pytorch_model_converted.bin
76+
77+
$PYTHON_EXECUTABLE -m executorch.examples.models.llama.export_llama \
78+
--model "phi_4_mini" \
79+
--checkpoint pytorch_model_converted.bin \
80+
--params examples/models/phi_4_mini/config/config.json \
81+
--output_name $MODEL_OUT \
82+
-kv \
83+
--use_sdpa_with_kv_cache \
84+
-X \
85+
--xnnpack-extended-ops \
86+
--max_context_length 1024 \
87+
--max_seq_length 1024 \
88+
--dtype fp32 \
89+
--metadata '{"get_bos_id":199999, "get_eos_ids":[200020,199999]}'
90+
;;
91+
92+
*)
93+
echo "Error: unsupported model_name '$MODEL_NAME'"
94+
echo "Supported values: qwen3_4b, phi_4_mini"
95+
exit 1
96+
;;
97+
esac
98+
99+
# Check file size
100+
MODEL_SIZE=$(stat --printf="%s" $MODEL_OUT 2>/dev/null || stat -f%z $MODEL_OUT)
101+
if [[ $MODEL_SIZE -gt $EXPECTED_MODEL_SIZE_UPPER_BOUND ]]; then
102+
echo "Error: model size $MODEL_SIZE is greater than expected upper bound $EXPECTED_MODEL_SIZE_UPPER_BOUND"
103+
exit 1
104+
fi
105+
106+
# Install ET with CMake
107+
if [[ "$TEST_WITH_RUNNER" -eq 1 ]]; then
108+
echo "[runner] Building and testing llama_main ..."
109+
cmake -DPYTHON_EXECUTABLE=python \
110+
-DCMAKE_INSTALL_PREFIX=cmake-out \
111+
-DEXECUTORCH_ENABLE_LOGGING=1 \
112+
-DCMAKE_BUILD_TYPE=Release \
113+
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
114+
-DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \
115+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
116+
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
117+
-DEXECUTORCH_BUILD_XNNPACK=ON \
118+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
119+
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
120+
-DEXECUTORCH_BUILD_EXTENSION_LLM_RUNNER=ON \
121+
-DEXECUTORCH_BUILD_EXTENSION_LLM=ON \
122+
-DEXECUTORCH_BUILD_KERNELS_LLM=ON \
123+
-Bcmake-out .
124+
cmake --build cmake-out -j16 --config Release --target install
125+
126+
127+
# Install llama runner
128+
cmake -DPYTHON_EXECUTABLE=python \
129+
-DCMAKE_BUILD_TYPE=Release \
130+
-Bcmake-out/examples/models/llama \
131+
examples/models/llama
132+
cmake --build cmake-out/examples/models/llama -j16 --config Release
133+
134+
# Run the model
135+
./cmake-out/examples/models/llama/llama_main --model_path=$MODEL_OUT --tokenizer_path="${HF_MODEL_DIR}/tokenizer.json" --prompt="Once upon a time,"
136+
fi
137+
138+
# Clean up
139+
rm -f pytorch_model_converted.bin "$MODEL_OUT"

0 commit comments

Comments
 (0)