Skip to content

Commit ad54e4e

Browse files
committed
Update on "[Executorch][llama] Enable quantized sdpa"
Enable leveraging quantized sdpa op when quantized kv cache is used. Instead of adding yet another arg, at the moment I have chosen to leverage quantize_kv_cache option. Differential Revision: [D71833064](https://our.internmc.facebook.com/intern/diff/D71833064/) [ghstack-poisoned]
2 parents 6c4cbe4 + abfd63a commit ad54e4e

File tree

126 files changed

+865
-611
lines changed

Some content is hidden

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

126 files changed

+865
-611
lines changed

.ci/scripts/build_android_instrumentation.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
1212
fi
1313
which "${PYTHON_EXECUTABLE}"
1414

15-
mkdir -p "${BUILD_AAR_DIR}"/executorch_android/src/androidTest/resources
16-
cp extension/module/test/resources/add.pte "${BUILD_AAR_DIR}"/executorch_android/src/androidTest/resources
15+
mkdir -p extension/android/executorch_android/src/androidTest/resources
16+
cp extension/module/test/resources/add.pte extension/android/executorch_android/src/androidTest/resources
1717

18-
pushd "${BUILD_AAR_DIR}"
18+
pushd extension/android
1919
ANDROID_HOME="${ANDROID_SDK:-/opt/android/sdk}" ./gradlew :executorch_android:testDebugUnitTest
2020
ANDROID_HOME="${ANDROID_SDK:-/opt/android/sdk}" ./gradlew :executorch_android:assembleAndroidTest
2121
popd

.github/workflows/_android.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
3838
mkdir -p ${ARTIFACTS_DIR_NAME}/library_test_dir
3939
bash .ci/scripts/build_android_instrumentation.sh
40-
cp ${BUILD_AAR_DIR}/executorch_android/build/outputs/apk/androidTest/debug/executorch_android-debug-androidTest.apk "${ARTIFACTS_DIR_NAME}/library_test_dir"
40+
cp extension/android/executorch_android/build/outputs/apk/androidTest/debug/executorch_android-debug-androidTest.apk "${ARTIFACTS_DIR_NAME}/library_test_dir"
4141
4242
mkdir -p ${ARTIFACTS_DIR_NAME}/fp32-xnnpack-custom
4343
bash examples/models/llama/install_requirements.sh

CONTRIBUTING.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Thank you for your interest in contributing to ExecuTorch! We want to make
22
it easy to contribute to this project.
33

4-
 
54

65
## Dev Install
76

@@ -91,7 +90,7 @@ executorch
9190
│ └── <a href="runtime/platform">platform</a> - Layer between architecture specific code and portable C++.
9291
├── <a href="schema">schema</a> - ExecuTorch PTE file format flatbuffer schemas.
9392
├── <a href="scripts">scripts</a> - Utility scripts for building libs, size management, dependency management, etc.
94-
├── <a href="shim">shim</a> - Compatibility layer between OSS and Internal builds.
93+
├── <a href="shim_et">shim_et</a> - Compatibility layer between OSS and Internal builds.
9594
├── <a href="test">test</a> - Broad scoped end-to-end tests.
9695
├── <a href="third-party">third-party</a> - Third-party dependencies.
9796
├── <a href="tools">tools</a> - Tools for building ExecuTorch from source, for different built tools (CMake, Buck).
@@ -192,9 +191,6 @@ in the Github repo.
192191

193192
## Coding Style
194193

195-
Goal: Encourage standards that make it easier to read, edit, maintain, and debug
196-
the ExecuTorch code.
197-
198194
### lintrunner
199195

200196
We use [`lintrunner`](https://pypi.org/project/lintrunner/) to help make sure the
@@ -259,7 +255,7 @@ toolchains, and having access to relatively modern C++ features.
259255

260256
#### C/C++ standard library usage
261257

262-
**Restricted usage of the C++ standard library.**
258+
**Restricted usage of the C++ standard library**
263259

264260
Rationale: ExecuTorch is intended to be portable to bare-metal systems that lack
265261
certain features, like dynamic memory, threading, and locking, required by parts
@@ -280,7 +276,7 @@ careful to also manually destroy objects initialized in this way.
280276

281277
#### C++ language features
282278

283-
**Exceptions: Do not use.**
279+
**Exceptions: Do not use**
284280
- Rationale: Exceptions are not widely supported on some classes of
285281
microcontrollers and DSPs, and they can significantly increase binary size.
286282

@@ -289,12 +285,12 @@ must work with threading**
289285
- Rationale: The core runtime must work on systems that do not have threading
290286
support.
291287

292-
**RTTI, dynamic_cast, and `<typeid>`: Do not use.**
288+
**RTTI, dynamic_cast, and `<typeid>`: Do not use**
293289
- Rationale: RTTI adds extra data to every virtual class. ExecuTorch doesn't
294290
have a strong need for `dynamic_cast` and friends, so it's better to reduce
295291
the binary size.
296292

297-
**Templates and template metaprogramming: Be careful and avoid if possible.**
293+
**Templates and template metaprogramming: Be careful and avoid if possible**
298294
- Rationale: Most templating results in code generation, and is one of the most
299295
common sources of binary bloat. Some use of templates is fine (e.g. an
300296
`ArrayRef<T>`, or code that handles multiple `ScalarType` types), but for the
@@ -359,7 +355,7 @@ docs](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/
359355
for basics.
360356

361357
1. Push your branch to your fork of `pytorch/executorch`. Most people do not
362-
have permission to push a branch directoy to the upstream repo.
358+
have permission to push a branch directory to the upstream repo.
363359
1. Create your PR
364360
- Use the `main` branch as the base.
365361
- Give the PR a clear and descriptive title. It will become the title of the

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ Key value propositions of ExecuTorch are:
4949
## Getting Started
5050
To get started you can:
5151

52-
- Visit the [Step by Step Tutorial](https://pytorch.org/executorch/main/index.html) on getting things running locally and deploy a model to a device
52+
- Visit the [Step by Step Tutorial](https://pytorch.org/executorch/main/index.html) to get things running locally and deploy a model to a device
5353
- Use this [Colab Notebook](https://pytorch.org/executorch/stable/getting-started-setup.html#quick-setup-colab-jupyter-notebook-prototype) to start playing around right away
54-
- Jump straight into LLMs use cases by following specific instructions for [Llama](./examples/models/llama/README.md) and [Llava](./examples/models/llava/README.md)
54+
- Jump straight into LLM use cases by following specific instructions for [Llama](./examples/models/llama/README.md) and [Llava](./examples/models/llava/README.md)
5555

5656
## Feedback and Engagement
5757

backends/qualcomm/_passes/decompose_einsum.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from executorch.exir.pass_base import ExportPass, PassResult
99
from torch.fx.experimental.proxy_tensor import make_fx
1010

11+
from .utils import copy_nn_module_stack
12+
1113

1214
class DecomposeEinsum(ExportPass):
1315
"""
@@ -36,6 +38,7 @@ def call(self, graph_module: torch.fx.GraphModule) -> PassResult:
3638
remap[f"arg1_{i+1}"] = arg
3739

3840
for decomposed_node in decomposed_module.graph.nodes:
41+
copy_nn_module_stack(node, decomposed_node)
3942
# This is the arg[0] equation string, which is not required anymore after decomposition
4043
if "arg0" in decomposed_node.name:
4144
continue

backends/qualcomm/_passes/decompose_linalg_vector_norm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from executorch.exir import to_edge
99
from executorch.exir.pass_base import ExportPass, PassResult
1010

11+
from .utils import copy_nn_module_stack
12+
1113

1214
class LinalgVectorNorm(torch.nn.Module):
1315
def __init__(self, exp, dim, keepdim):
@@ -62,6 +64,7 @@ def call(self, graph_module: torch.fx.GraphModule) -> PassResult:
6264
remap = {"x": node.args[0]}
6365

6466
for decomposed_node in decomposed_module.graph.nodes:
67+
copy_nn_module_stack(node, decomposed_node)
6568
# no need to copy existent 'output'
6669
if decomposed_node.op == "output":
6770
for user in node.users.copy():

backends/qualcomm/_passes/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ def get_passes_dependency_for_capture_program():
121121
}
122122

123123

124+
def copy_nn_module_stack(src, target):
125+
"""
126+
Copy meta["nn_module_stack"] from src node to target node if existing.
127+
"""
128+
if value := src.meta.get("nn_module_stack"):
129+
target.meta["nn_module_stack"] = value
130+
131+
124132
def is_float_tensor(node: torch.fx.Node) -> bool:
125133
if "val" not in node.meta or not isinstance(node.meta["val"], FakeTensor):
126134
return False

0 commit comments

Comments
 (0)