Skip to content

Commit b484ea9

Browse files
committed
Update on " [executorch] Migrate most of extension/... to new namespace"
Migrate these headers to the new `::executorch::extension` namespace. Add temporary aliases from the old `::torch::executor` namespace so we can migrate users incrementally. Differential Revision: [D60938936](https://our.internmc.facebook.com/intern/diff/D60938936/) [ghstack-poisoned]
2 parents a41d36d + 602be10 commit b484ea9

File tree

26 files changed

+457
-235
lines changed

26 files changed

+457
-235
lines changed

.ci/scripts/test_llama.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set -exu
99
# shellcheck source=/dev/null
1010
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
1111

12-
MODEL_NAME=$1 # stories110M.pt
12+
MODEL_NAME=$1 # stories110M
1313
BUILD_TOOL=$2 # buck2 or cmake
1414
DTYPE=$3 # fp16 or fp32
1515
MODE=${4:-"xnnpack+custom"} # portable or xnnpack+custom or xnnpack+custom+qe
@@ -140,7 +140,7 @@ cmake_build_llama_runner() {
140140

141141
cleanup_files() {
142142
echo "Deleting downloaded and generated files"
143-
rm "${MODEL_NAME}"
143+
rm "${CHECKPOINT_FILE_NAME}"
144144
rm tokenizer.model
145145
rm tokenizer.bin
146146
rm "${EXPORTED_MODEL_NAME}"
@@ -159,8 +159,10 @@ prepare_artifacts_upload() {
159159

160160
# Download and create artifacts.
161161
PARAMS="params.json"
162+
CHECKPOINT_FILE_NAME=""
162163
touch "${PARAMS}"
163-
if [[ "${MODEL_NAME}" == "stories110M.pt" ]]; then
164+
if [[ "${MODEL_NAME}" == "stories110M" ]]; then
165+
CHECKPOINT_FILE_NAME="stories110M.pt"
164166
download_stories_model_artifacts
165167
else
166168
echo "Unsupported model name ${MODEL_NAME}"
@@ -181,7 +183,7 @@ fi
181183
# Export model.
182184
EXPORTED_MODEL_NAME="${EXPORTED_MODEL_NAME}.pte"
183185
echo "Exporting ${EXPORTED_MODEL_NAME}"
184-
EXPORT_ARGS="-c stories110M.pt -p ${PARAMS} -d ${DTYPE} -n ${EXPORTED_MODEL_NAME} -kv"
186+
EXPORT_ARGS="-c ${CHECKPOINT_FILE_NAME} -p ${PARAMS} -d ${DTYPE} -n ${EXPORTED_MODEL_NAME} -kv"
185187
if [[ "${XNNPACK}" == "ON" ]]; then
186188
EXPORT_ARGS="${EXPORT_ARGS} -X -qmode 8da4w -G 128"
187189
fi

.github/workflows/android-perf.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ jobs:
156156
BUILD_MODE="cmake"
157157
DTYPE="fp32"
158158
159-
if [[ ${{ matrix.model }} == "llama*" ]]; then
159+
if [[ ${{ matrix.model }} == "stories*"" ]]; then
160160
# Install requirements for export_llama
161161
PYTHON_EXECUTABLE=python bash examples/models/llama2/install_requirements.sh
162162
# Test llama2
163163
if [[ ${{ matrix.delegate }} == "xnnpack" ]]; then
164164
DELEGATE_CONFIG="xnnpack+custom+qe"
165165
fi
166-
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh "${{ matrix.model }}.pt" "${BUILD_MODE}" "${DTYPE}" "${DELEGATE_CONFIG}" "${ARTIFACTS_DIR_NAME}"
166+
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh "${{ matrix.model }}" "${BUILD_MODE}" "${DTYPE}" "${DELEGATE_CONFIG}" "${ARTIFACTS_DIR_NAME}"
167167
else
168168
PYTHON_EXECUTABLE=python bash .ci/scripts/test.sh "${{ matrix.model }}" "${BUILD_MODE}" "${{ matrix.delegate }}" "${ARTIFACTS_DIR_NAME}"
169169
fi

.github/workflows/pull.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ jobs:
112112
# Install requirements for export_llama
113113
PYTHON_EXECUTABLE=python bash examples/models/llama2/install_requirements.sh
114114
# Test llama2
115-
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh stories110M.pt "${BUILD_TOOL}" "${DTYPE}" "${MODE}"
115+
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh stories110M "${BUILD_TOOL}" "${DTYPE}" "${MODE}"
116116
117117
test-llama-runner-linux-android:
118118
name: test-llama-runner-linux-android
@@ -406,4 +406,4 @@ jobs:
406406
# Install requirements for export_llama
407407
PYTHON_EXECUTABLE=python bash examples/models/llama2/install_requirements.sh
408408
# Test llama2
409-
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh stories110M.pt "${BUILD_TOOL}" "${DTYPE}" "${MODE}"
409+
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh stories110M "${BUILD_TOOL}" "${DTYPE}" "${MODE}"

.github/workflows/trunk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ jobs:
269269
# Install requirements for export_llama
270270
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash examples/models/llama2/install_requirements.sh
271271
# Test llama2
272-
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_llama.sh stories110M.pt "${BUILD_TOOL}" "${DTYPE}" "${MODE}"
272+
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_llama.sh stories110M "${BUILD_TOOL}" "${DTYPE}" "${MODE}"
273273
274274
test-qnn-model:
275275
name: test-qnn-model

.github/workflows/update-viablestrict.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ jobs:
2020
with:
2121
repository: pytorch/executorch
2222
stable-branch: viable/strict
23-
requires: '[\"pull\", \"lint\", \"trunk\", \"Build documentation\", "^Android$", "^Apple$"]'
23+
requires: '[\"pull\", \"lint\", \"trunk\", \"Build documentation\", \"^Android$\", \"^Apple$\"]'
2424
secret-bot-token: ${{ secrets.UPDATEBOT_TOKEN }}
2525
rockset-api-key: ${{ secrets.ROCKSET_API_KEY }}

build/build_android_llm_demo.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ build_android_native_library() {
3030
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
3131
-DANDROID_ABI="${ANDROID_ABI}" \
3232
-DANDROID_PLATFORM=android-23 \
33+
-DEXECUTORCH_ENABLE_LOGGING=ON \
34+
-DEXECUTORCH_LOG_LEVEL=Info \
3335
-DEXECUTORCH_BUILD_XNNPACK=ON \
36+
-DEXECUTORCH_XNNPACK_SHARED_WORKSPACE=ON \
3437
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
3538
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
3639
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
@@ -60,11 +63,14 @@ build_android_native_library() {
6063

6164
cmake --build "${CMAKE_OUT}"/examples/models/llama2 -j "${CMAKE_JOBS}" --config Release
6265

66+
6367
cmake extension/android \
6468
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
6569
-DANDROID_ABI="${ANDROID_ABI}" \
6670
-DANDROID_PLATFORM=android-23 \
6771
-DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
72+
-DEXECUTORCH_ENABLE_LOGGING=ON \
73+
-DEXECUTORCH_LOG_LEVEL=Info \
6874
-DEXECUTORCH_BUILD_LLAMA_JNI=ON \
6975
-DEXECUTORCH_USE_TIKTOKEN="${EXECUTORCH_USE_TIKTOKEN}" \
7076
-DCMAKE_BUILD_TYPE=Release \

docs/source/api-life-cycle.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,21 @@ communicate state to developers.
9191
<td>
9292

9393
Use the
94-
<a href="https://typing-extensions.readthedocs.io/en/latest/#typing_extensions.deprecated">typing_extensions.deprecated</a>
95-
decorator
94+
<a href="https://github.com/pytorch/executorch/blob/main/exir/_warnings.py">executorch.exir._warnings.deprecated</a>
95+
decorator.
9696

9797
<p>
98-
Use ExecuTorch's native experimental decorator (TODO not yet implemented)
98+
Use the
99+
<a href="https://github.com/pytorch/executorch/blob/main/exir/_warnings.py">executorch.exir._warnings.experimental</a>
100+
decorator.
99101

100102
</td>
101103
<td>
102104

103105
Use <code>.. warning::</code> in the docstrings of deprecated and experimental
104106
APIs. See
105107
<a href="https://github.com/pytorch/pytorch/blob/cd8bbdc71a0258292381a7d54c8b353988d02ff4/torch/nn/utils/stateless.py#L170">example
106-
usage</a>
108+
usage</a>.
107109

108110
</ul>
109111
</td>
@@ -113,35 +115,35 @@ usage</a>
113115
</td>
114116
<td>
115117

116-
Use <code>ET_DEPRECATED</code> macros. See <a href="https://github.com/pytorch/executorch/blob/8e0f856ee269b319ac4195509cf31e3f548aa0e8/runtime/executor/program.h#L81">example usage</a>
118+
Use the <code>ET_DEPRECATED</code> annotation macro. See <a href="https://github.com/pytorch/executorch/blob/8e0f856ee269b319ac4195509cf31e3f548aa0e8/runtime/executor/program.h#L81">example usage</a>.
117119

118120
<p>
119121
<p>
120-
Use <code>ET_EXPERIMENTAL</code> macros (TODO not yet implemented)
122+
Use the <code>ET_EXPERIMENTAL</code> annotation macro.
121123
</ul>
122124
</td>
123125
<td>
124126

125127
Start Doxygen comments with <code>DEPRECATED:</code> See
126128
<a href="https://github.com/pytorch/executorch/blob/9d859653ae916d0a72f6b2b5c5925bed38832140/runtime/executor/program.h#L139">example
127-
usage</a>
129+
usage</a>.
128130

129131
<p>
130132
<p>
131-
Start Doxygen comments with <code>EXPERIMENTAL:</code>
133+
Start Doxygen comments with <code>EXPERIMENTAL:</code>.
132134
</td>
133135
</tr>
134136
<tr>
135137
<td>Java
136138
</td>
137139
<td>
138140

139-
Use <a href="https://docs.oracle.com/javase/9/docs/api/java/lang/Deprecated.html">java.lang.Deprecated</a>
141+
Use <a href="https://docs.oracle.com/javase/9/docs/api/java/lang/Deprecated.html">java.lang.Deprecated</a>.
140142

141143
<p>
142144
<p>
143145

144-
Use <a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:docs/api_guidelines/annotations.md">androidx.annotation.RequiresOptIn</a>
146+
Use <a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:docs/api_guidelines/annotations.md">androidx.annotation.RequiresOptIn</a>.
145147

146148
</td>
147149
<td>
@@ -164,7 +166,7 @@ Use <a href="https://cs.android.com/androidx/platform/frameworks/support/+/andro
164166
<code>__attribute__((deprecated("Use newMethod instead")));</code>
165167
<p>
166168
<p>
167-
<code>__attribute__((experimental("Use newMethod instead")));</code> (TODO not yet implemented)
169+
<code>__attribute__((deprecated("This API is experimental and may change without notice.")));</code>
168170
</td>
169171
<td>
170172
<p>

examples/models/llama2/install_requirements.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Install snakeviz for cProfile flamegraph
99
# Install sentencepiece for llama tokenizer
1010
pip install snakeviz sentencepiece
11-
pip install torchao==0.4
11+
pip install torchao==0.1
1212

1313
# Install lm-eval for Model Evaluation with lm-evalution-harness
1414
# Install tiktoken for tokenizer

examples/models/llava/runner/llava_image_prefiller.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ class LlavaImagePrefiller : public ImagePrefiller {
2424
* @param start_pos The starting position in KV cache of the input in the LLM
2525
* @return logits of the image prefill.
2626
*/
27-
inline Result<exec_aten::Tensor> prefill(
28-
Image& image,
29-
int64_t start_pos = 0) {
27+
inline Result<exec_aten::Tensor> prefill(Image& image, int64_t start_pos = 0)
28+
override {
3029
ManagedTensor managed_images(
3130
image.data.data(), {3, image.height, image.width}, ScalarType::Byte);
3231
// Run image encoder
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
2+
3+
def define_common_targets():
4+
runtime.cxx_library(
5+
name = "runner",
6+
srcs = ["llava_runner.cpp"],
7+
exported_headers = ["llava_runner.h", "llava_image_prefiller.h", "llava_text_decoder_runner.h"],
8+
visibility = [
9+
"@EXECUTORCH_CLIENTS",
10+
],
11+
exported_deps = [
12+
"//executorch/backends/xnnpack:xnnpack_backend",
13+
"//executorch/extension/llm/runner:runner_lib",
14+
"//executorch/extension/llm/tokenizer:bpe_tokenizer",
15+
"//executorch/extension/evalue_util:print_evalue",
16+
"//executorch/extension/runner_util:managed_tensor",
17+
"//executorch/extension/module:module",
18+
"//executorch/kernels/quantized:generated_lib",
19+
"//executorch/runtime/core/exec_aten:lib",
20+
"//executorch/runtime/core/exec_aten/util:tensor_util",
21+
],
22+
)

exir/tests/TARGETS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ python_unittest(
109109
deps = [
110110
"//caffe2:torch",
111111
"//executorch/exir:lib",
112+
"//executorch/extension/pybindings:portable_lib",
112113
],
113114
)
114115

@@ -209,6 +210,7 @@ python_unittest(
209210
"//executorch/exir/passes:debug_handle_generator_pass",
210211
"//executorch/exir/passes:insert_write_back_for_buffers_pass",
211212
"//executorch/exir/passes:lib",
213+
"//executorch/exir/passes:memory_format_ops_pass",
212214
"//executorch/exir/passes:normalize_view_copy_base_pass",
213215
"//executorch/exir/passes:remove_graph_asserts_pass",
214216
"//executorch/exir/passes:remove_mixed_type_operators",

exir/tests/test_joint_graph.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
import torch._dynamo
1212

1313
from executorch.exir import to_edge
14+
15+
from executorch.extension.pybindings.portable_lib import (
16+
_load_for_executorch_from_buffer,
17+
)
1418
from torch.export._trace import _export
1519
from torch.export.experimental import _export_forward_backward
1620
from torch.export.exported_program import OutputKind
@@ -89,3 +93,18 @@ def forward(self, x, y):
8993
.val.allocation_info.memory_offset_low,
9094
48,
9195
)
96+
97+
loss = m(*example_inputs)
98+
loss.backward()
99+
et_mod = _load_for_executorch_from_buffer(et.buffer)
100+
et_outputs = et_mod.forward(
101+
example_inputs
102+
) # ET outputs are [loss, grads, weights]
103+
104+
self.assertTrue(torch.allclose(loss, et_outputs[0]))
105+
self.assertTrue(
106+
torch.allclose(m.linear.weight.grad, et_outputs[1]) # pyre-ignore[6]
107+
)
108+
self.assertTrue(torch.allclose(m.linear.bias.grad, et_outputs[2]))
109+
self.assertTrue(torch.allclose(m.linear.weight, et_outputs[3]))
110+
self.assertTrue(torch.allclose(m.linear.bias, et_outputs[4]))

extension/android/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ if(EXECUTORCH_BUILD_LLAMA_JNI)
7979
TARGET llama_runner PROPERTY IMPORTED_LOCATION ${LLAMA_RUNNER_PATH}
8080
)
8181

82+
add_subdirectory(
83+
${EXECUTORCH_ROOT}/examples/models/llava/runner
84+
${CMAKE_CURRENT_BINARY_DIR}/../../examples/models/llava/runner
85+
)
86+
8287
set(CUSTOM_OPS_PATH
8388
${CMAKE_CURRENT_BINARY_DIR}/../../extension/llm/custom_ops/libcustom_ops.a
8489
)
@@ -116,6 +121,7 @@ if(EXECUTORCH_BUILD_LLAMA_JNI)
116121
executorch_llama_jni
117122
${link_libraries}
118123
llama_runner
124+
llava_runner
119125
custom_ops
120126
cpublas
121127
eigen_blas

0 commit comments

Comments
 (0)