Skip to content

Commit 97b02c6

Browse files
committed
refactor
1 parent c8d583f commit 97b02c6

File tree

7 files changed

+92
-85
lines changed

7 files changed

+92
-85
lines changed

program-data-separation/README.md

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,10 @@ PTD files are used to store data outside of the PTE file. Some use-cases:
1313
- Deduplication: sharing model weights between multiple executable PTE files. This can significantly reduce binary file size and runtime memory usage.
1414
- Flexible deployment: allow async updates between program and data, especially if they are updated with different cadences.
1515

16-
## Virtual environment setup
17-
Create and activate a Python virtual environment:
18-
```bash
19-
python3 -m venv .venv && source .venv/bin/activate && pip install --upgrade pip
20-
```
21-
Or alternatively, [install conda on your machine](https://conda.io/projects/conda/en/latest/user-guide/install/index.html)
22-
```bash
23-
conda create -yn executorch-ptd python=3.10.0 && conda activate executorch-ptd
24-
```
25-
26-
Install dependencies:
27-
```
28-
pip install executorch==0.7.0
29-
```
30-
31-
## Export a model with program-data separation
32-
To export a non-delegated linear model, into the current directory:
33-
```python
34-
python export_linear.py --outdir .
35-
```
36-
Expect the files 'linear.pte' and 'linear.ptd'.
37-
38-
To export a linear model delegated to XNNPACK, into the current directory:
39-
```python
40-
python export_linear.py --outdir . --xnnpack
41-
```
42-
Expect the files 'linear_xnnpack.pte' and 'linear_xnnpack.ptd'.
43-
44-
Note:
45-
- PTE: contains the program execution logic.
46-
- PTD: contains the constant tensors used by the PTE.
47-
4816
For more information on the PTD data format, please see the [flat_tensor](https://github.com/pytorch/executorch/blob/main/extension/flat_tensor/README.md) directory.
4917

50-
Please see [program-data-separation/cpp](cpp/) for instructions on running the exported models.
18+
## Export a model with program-data separation
19+
For a demo of the program-data separation APIs using a linear model, please see [program-data-separation/cpp/linear_example](linear_example/). This example generates and runs a program-data separated linear model, with weights and bias in a separate .ptd file.
5120

5221
## Export a model with LoRA
5322
A major use-case that program-data separation enables is inference with multiple LoRA adapters. LoRA is a fine-tuning technique introduced in [LoRA: Low-Rank Adaptation of Large Language Models](https://arxiv.org/abs/2106.09685). LoRA fine-tuning produces lightweight 'adapter' weights that can be applied to an existing model to adapt it to a new task. LoRA adapters are typically small in comparison to LLM foundation weights, on the order of KB-MB depending on the finetuning setup and model size.

program-data-separation/cpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ option(EXECUTORCH_BUILD_XNNPACK "" ON)
1717
# Add ExecuTorch subdirectory
1818
add_subdirectory("executorch")
1919

20-
set(DEMO_SOURCES main.cpp)
20+
set(DEMO_SOURCES linear_example/main.cpp)
2121

2222
# Create executable
2323
add_executable(executorch_program_data_separation ${DEMO_SOURCES})

program-data-separation/cpp/README.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

program-data-separation/cpp/build_example.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# ExecuTorch Program Data Separation Demo C++.
2+
3+
This directory contains the C++ code to run the examples generated in [program-data-separation](../program-data-separation/README.md).
4+
5+
6+
## Virtual environment setup.
7+
Create and activate a Python virtual environment:
8+
```bash
9+
python3 -m venv .venv && source .venv/bin/activate && pip install --upgrade pip
10+
```
11+
Or alternatively, [install conda on your machine](https://conda.io/projects/conda/en/latest/user-guide/install/index.html)
12+
```bash
13+
conda create -yn executorch-ptd python=3.10.0 && conda activate executorch-ptd
14+
```
15+
16+
Install dependencies:
17+
```bash
18+
pip install executorch==0.7.0
19+
```
20+
21+
## Export the model/s.
22+
23+
Change into the program-data-separation directory and create a directory to hold exported artifacts.
24+
```bash
25+
cd ~/executorch-examples/program-data-separation
26+
mkdir models
27+
```
28+
29+
Export models into the `models` directory. The first command will generated undelegated model/data files, and the second will generate XNNPACK-delegated model/data files.
30+
```bash
31+
python export_linear.py --outdir models/
32+
python export_linear.py --outdir models/ --xnnpack
33+
```
34+
Expect the files `linear.pte` and `linear.ptd`, `linear_xnnpack.pte` and `linear_xnnpack.ptd`.
35+
36+
Note:
37+
- PTE: contains the program execution logic.
38+
- PTD: contains the constant tensors used by the PTE.
39+
40+
See [program-data-separation](../../program-data-separation/README.md) for instructions.
41+
42+
## Install runtime dependencies.
43+
The ExecuTorch repository is configured as a git submodule at `~/executorch-examples/program-data-separation/cpp/executorch`. To initialize it:
44+
```bash
45+
cd ~/executorch-examples/
46+
git submodule sync
47+
git submodule update --init --recursive
48+
```
49+
Install dev requirements for ExecuTorch
50+
51+
```bash
52+
cd ~/executorch-examples/program-data-separation/cpp/executorch
53+
pip install -r requirements-dev.txt
54+
```
55+
56+
## Build the runtime.
57+
Build the executable:
58+
```bash
59+
cd ~/executorch-examples/program-data-separation/cpp/linear_example
60+
chmod +x build_example.sh
61+
./build_example.sh
62+
```
63+
64+
## Run the executable.
65+
```
66+
./build/bin/executorch_program_data_separation --model-path ../../models/linear.pte --data-path ../../models/linear.ptd
67+
68+
./build/bin/executorch_program_data_separation --model-path ../../models/linear_xnnpack.pte --data-path ../../models/linear_xnnpack.ptd
69+
```
70+
71+
## Clean up.
72+
rm -rf build
73+
cd ~/executorch-examples/program-data-separation
74+
rm -rf models
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Clean and create build directory if it doesn't exist
5+
rm -rf build
6+
mkdir -p build
7+
cd build
8+
9+
# Configure CMake
10+
cmake -DCMAKE_BUILD_TYPE=Release ../..
11+
12+
# Build the project
13+
cmake --build . -j$(nproc)
14+
15+
echo "Build complete! Executable located at: ./build/bin/executorch_program_data_separation"

0 commit comments

Comments
 (0)