Skip to content

Commit 696dbea

Browse files
Merge branch 'main' into svnew
2 parents 2e585e7 + 0e76a97 commit 696dbea

File tree

206 files changed

+6787
-1168
lines changed

Some content is hidden

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

206 files changed

+6787
-1168
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ install_swiftshader() {
2323

2424
export VK_ICD_FILENAMES="${_swiftshader_dir}/swiftshader/build/Linux/vk_swiftshader_icd.json"
2525
export LD_LIBRARY_PATH="${_swiftshader_dir}/swiftshader/build/Linux/"
26+
export ETVK_USING_SWIFTSHADER=1
2627
}
2728

2829
install_vulkan_sdk() {

.ci/scripts/test_llama_lora.sh

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,17 @@ DOWNLOADED_PATH=$(
4848
--model_id "${HF_MODEL_REPO}" \
4949
--files "adapter_config.json" "adapter_model.pt" "consolidated.00.pth" "params.json" "tokenizer.model"
5050
)
51-
EXPORTED_MODEL_NAME="llama_3_2_1B_lora.pte"
52-
# Export model.
51+
# Build llama runner.
52+
cmake_install_executorch_libraries
53+
cmake_build_llama_runner
54+
55+
# Constants.
56+
RUNTIME_ARGS="--tokenizer_path=${DOWNLOADED_PATH}/tokenizer.model --temperature=0 --seq_len=20 --warmup=1"
57+
PROMPT="What happens if you eat watermelon seeds?"
58+
EXPECTED_PREFIX="What happens if you eat watermelon seeds? Watermelon seeds are a good source of vitamin C,"
59+
60+
# Export LoRA PTE file.
61+
MODEL_NAME="llama_3_2_1B_lora"
5362
$PYTHON_EXECUTABLE -m extension.llm.export.export_llm \
5463
base.checkpoint="${DOWNLOADED_PATH}/consolidated.00.pth" \
5564
base.params="${DOWNLOADED_PATH}/params.json" \
@@ -61,36 +70,64 @@ $PYTHON_EXECUTABLE -m extension.llm.export.export_llm \
6170
model.dtype_override="fp32" \
6271
backend.xnnpack.enabled=true \
6372
backend.xnnpack.extended_ops=true \
64-
export.output_name="${EXPORTED_MODEL_NAME}"
65-
66-
# Build llama runner.
67-
cmake_install_executorch_libraries
68-
cmake_build_llama_runner
73+
export.output_name="${MODEL_NAME}.pte"
6974

70-
PROMPT="What happens if you eat watermelon seeds?"
7175
# Run llama runner
72-
RUNTIME_ARGS="--model_path=${EXPORTED_MODEL_NAME} --tokenizer_path=${DOWNLOADED_PATH}/tokenizer.model --temperature=0 --seq_len=20 --warmup=1"
73-
7476
NOW=$(date +"%H:%M:%S")
7577
echo "Starting to run llama runner at ${NOW}"
7678
# shellcheck source=/dev/null
77-
cmake-out/examples/models/llama/llama_main --prompt="${PROMPT}" ${RUNTIME_ARGS} > result.txt
79+
cmake-out/examples/models/llama/llama_main --model_path=${MODEL_NAME}.pte --prompt="${PROMPT}" ${RUNTIME_ARGS} > result.txt
7880
NOW=$(date +"%H:%M:%S")
7981
echo "Finished at ${NOW}"
8082

8183
RESULT=$(cat result.txt)
82-
EXPECTED_PREFIX="What happens if you eat watermelon seeds? Watermelon seeds are a good source of vitamin C,"
83-
8484
if [[ "${RESULT}" == "${EXPECTED_PREFIX}"* ]]; then
8585
echo "Expected result prefix: ${EXPECTED_PREFIX}"
8686
echo "Actual result: ${RESULT}"
87+
# Do not clean up files if test passes, as they're re-used in the next test.
8788
echo "Success"
88-
cleanup_files
8989
else
9090
echo "Expected result prefix: ${EXPECTED_PREFIX}"
9191
echo "Actual result: ${RESULT}"
9292
echo "Failure; results not the same"
93+
cleanup_files
94+
exit 1
95+
fi
9396

97+
# Export LoRA PTE, PTD file.
98+
MODEL_SEPARATE="${MODEL_NAME}_separate"
99+
$PYTHON_EXECUTABLE -m extension.llm.export.export_llm \
100+
base.checkpoint="${DOWNLOADED_PATH}/consolidated.00.pth" \
101+
base.params="${DOWNLOADED_PATH}/params.json" \
102+
base.adapter_checkpoint="${DOWNLOADED_PATH}/adapter_model.pt" \
103+
base.adapter_config="${DOWNLOADED_PATH}/adapter_config.json" \
104+
base.tokenizer_path="${DOWNLOADED_PATH}/tokenizer.model" \
105+
model.use_kv_cache=true \
106+
model.use_sdpa_with_kv_cache=true \
107+
model.dtype_override="fp32" \
108+
backend.xnnpack.enabled=true \
109+
backend.xnnpack.extended_ops=true \
110+
export.output_name="${MODEL_SEPARATE}.pte" \
111+
export.foundation_weights_file="${MODEL_SEPARATE}.ptd"
112+
113+
# Run llama runner.
114+
NOW=$(date +"%H:%M:%S")
115+
echo "Starting to run llama runner at ${NOW}"
116+
# shellcheck source=/dev/null
117+
cmake-out/examples/models/llama/llama_main --model_path=${MODEL_SEPARATE}.pte --data_path=${MODEL_SEPARATE}.ptd --prompt="${PROMPT}" ${RUNTIME_ARGS} > result2.txt
118+
NOW=$(date +"%H:%M:%S")
119+
echo "Finished at ${NOW}"
120+
121+
RESULT2=$(cat result2.txt)
122+
if [[ "${RESULT2}" == "${EXPECTED_PREFIX}"* ]]; then
123+
echo "Expected result prefix: ${EXPECTED_PREFIX}"
124+
echo "Actual result: ${RESULT2}"
125+
echo "Success"
126+
cleanup_files
127+
else
128+
echo "Expected result prefix: ${EXPECTED_PREFIX}"
129+
echo "Actual result: ${RESULT2}"
130+
echo "Failure; results not the same"
94131
cleanup_files
95132
exit 1
96133
fi

.github/workflows/build-presets.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ on:
66
branches:
77
- main
88
- release/*
9-
paths:
10-
- .github/workflows/build-presets.yml
119
workflow_dispatch:
1210

1311
concurrency:

.github/workflows/pull.yml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,8 @@ jobs:
801801
id-token: write
802802
contents: read
803803
strategy:
804+
matrix:
805+
enable-etdump: ['', '--enable-etdump']
804806
fail-fast: false
805807
with:
806808
runner: linux.2xlarge
@@ -820,7 +822,7 @@ jobs:
820822
source .ci/scripts/setup-emscripten.sh
821823
822824
# Test selective build
823-
bash scripts/build_wasm_tests.sh
825+
bash scripts/build_wasm_tests.sh ${{ matrix.enable-etdump }}
824826
825827
# Install Jest
826828
cd cmake-out-wasm/extension/wasm/test
@@ -862,6 +864,43 @@ jobs:
862864
PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh
863865
864866
867+
test-vulkan-models-linux:
868+
name: test-vulkan-models-linux
869+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
870+
permissions:
871+
id-token: write
872+
contents: read
873+
with:
874+
runner: linux.2xlarge
875+
docker-image: ci-image:executorch-ubuntu-22.04-clang12
876+
submodules: 'recursive'
877+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
878+
timeout: 90
879+
script: |
880+
set -eux
881+
882+
# The generic Linux job chooses to use base env, not the one setup by the image
883+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
884+
conda activate "${CONDA_ENV}"
885+
886+
# Setup swiftshader and Vulkan SDK which are required to build the Vulkan delegate
887+
source .ci/scripts/setup-vulkan-linux-deps.sh
888+
889+
# Setup python
890+
PYTHON_EXECUTABLE=python \
891+
CMAKE_ARGS="-DEXECUTORCH_BUILD_VULKAN=ON" \
892+
.ci/scripts/setup-linux.sh --build-tool "cmake"
893+
894+
PYTHON_EXECUTABLE=python bash backends/vulkan/test/scripts/test_model.sh --build
895+
896+
# Test models serially
897+
models="mv2 mv3 edsr resnet18 resnet50 dl3"
898+
for model in $models; do
899+
python -m examples.vulkan.export --model_name=$model --test
900+
done
901+
902+
903+
865904
nxp-build-test:
866905
name: nxp-build-test
867906
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pip-out/
2424
# Any exported models and profiling outputs
2525
*.bin
2626
*.model
27+
*.etdump
2728
tokenizer.json
2829
*.pte
2930
*.ptd
@@ -58,6 +59,7 @@ xcuserdata/
5859
/include/
5960
/share/
6061
/version.py
62+
*.csv
6163

6264
# Android
6365
*.aar

.lintrunner.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,36 @@ init_command = [
136136
'--requirement=requirements-lintrunner.txt',
137137
]
138138

139+
[[linter]]
140+
code = 'CMAKEFORMAT'
141+
include_patterns = [
142+
"**/*.cmake",
143+
"**/*.cmake.in",
144+
"**/CMakeLists.txt",
145+
]
146+
exclude_patterns = [
147+
'third-party/**',
148+
'**/third-party/**',
149+
]
150+
command = [
151+
'python',
152+
'-m',
153+
'lintrunner_adapters',
154+
'run',
155+
'cmake_format_linter',
156+
'--',
157+
'@{{PATHSFILE}}',
158+
]
159+
init_command = [
160+
'python',
161+
'-m',
162+
'lintrunner_adapters',
163+
'run',
164+
'pip_init',
165+
'--dry-run={{DRYRUN}}',
166+
'--requirement=requirements-lintrunner.txt',
167+
]
168+
139169
[[linter]]
140170
code = 'ETCAPITAL'
141171
include_patterns = [

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,19 @@ if(EXECUTORCH_BUILD_KERNELS_TORCHAO)
284284
set(TORCHAO_BUILD_CPU_AARCH64 ON)
285285
set(TORCHAO_ENABLE_ARM_NEON_DOT ON)
286286

287-
list(APPEND TORCHAO_INCLUDE_DIRS
287+
list(
288+
APPEND
289+
TORCHAO_INCLUDE_DIRS
288290
${EXECUTORCH_ROOT}/backends/xnnpack/third-party/pthreadpool/include
289291
${EXECUTORCH_ROOT}/backends/xnnpack/third-party/cpuinfo/include
290292
${EXECUTORCH_ROOT}/third-party/ao
291293
)
292294

293295
set(EXECUTORCH_INCLUDE_DIRS ${TORCHAO_INCLUDE_DIRS})
294296

295-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third-party/ao/torchao/experimental)
297+
add_subdirectory(
298+
${CMAKE_CURRENT_SOURCE_DIR}/third-party/ao/torchao/experimental
299+
)
296300
executorch_target_link_options_shared_lib(torchao_ops_executorch)
297301
list(APPEND _executorch_kernels torchao_ops_executorch)
298302
endif()
@@ -759,6 +763,10 @@ if(EXECUTORCH_BUILD_PYBIND)
759763
list(APPEND _dep_libs xnnpack_backend XNNPACK xnnpack-microkernels-prod)
760764
endif()
761765

766+
if(EXECUTORCH_BUILD_VULKAN)
767+
list(APPEND _dep_libs vulkan_backend)
768+
endif()
769+
762770
# compile options for pybind
763771
set(_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
764772
-fexceptions

backends/apple/coreml/runtime/delegate/coreml_backend_delegate.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
using executorch::runtime::get_backend_class;
4747
using executorch::runtime::Result;
4848
using executorch::aten::SizesType;
49+
using executorch::runtime::Span;
4950
using executorch::aten::Tensor;
5051
using executorch::runtime::kTensorDimensionLimit;
5152

@@ -197,7 +198,7 @@ ModelLoggingOptions get_logging_options(BackendExecutionContext& context) {
197198

198199
Error CoreMLBackendDelegate::execute(BackendExecutionContext& context,
199200
DelegateHandle* handle,
200-
EValue** args) const {
201+
Span<EValue*> args) const {
201202
const auto& nArgs = impl_->get_num_arguments(handle);
202203
std::vector<MultiArray> delegate_args;
203204
size_t nInputs = nArgs.first;

backends/apple/coreml/runtime/include/coreml_backend/delegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class CoreMLBackendDelegate final : public ::executorch::runtime::BackendInterfa
4848
/// @retval On success, `Error::Ok` otherwise any other `Error` case.
4949
executorch::runtime::Error execute(executorch::runtime::BackendExecutionContext& context,
5050
executorch::runtime::DelegateHandle* handle,
51-
executorch::runtime::EValue** args) const override;
51+
executorch::runtime::Span<executorch::runtime::EValue*> args) const override;
5252

5353
/// Returns `true` if the delegate is available otherwise `false`.
5454
bool is_available() const override;

backends/apple/mps/runtime/MPSBackend.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using executorch::runtime::Error;
3131
using executorch::runtime::FreeableBuffer;
3232
using executorch::runtime::Result;
33+
using executorch::runtime::Span;
3334

3435
class MPSBackend final : public ::executorch::runtime::BackendInterface {
3536
public:
@@ -72,7 +73,7 @@ bool is_available() const override {
7273
Error execute(
7374
ET_UNUSED BackendExecutionContext& context,
7475
DelegateHandle* handle,
75-
EValue** args) const override {
76+
Span<EValue*> args) const override {
7677
auto executor = static_cast<mps::delegate::MPSExecutor*>(handle);
7778
std::vector<const Tensor*> input_pointers;
7879
std::vector<const Tensor*> output_pointers;

0 commit comments

Comments
 (0)