Skip to content

Commit 6820398

Browse files
mergennachinfacebook-github-bot
authored andcommitted
Prepare Llama2 README.md for consumption (#2831)
Summary: Cleaning up old contents from Llama2. This is purely skeleton. Follow-up diffs will contain fixing individual steps. Reviewed By: iseeyuan Differential Revision: D55703398
1 parent a25dea6 commit 6820398

File tree

1 file changed

+46
-24
lines changed

1 file changed

+46
-24
lines changed

examples/models/llama2/README.md

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Summary
2-
This example demonstrates how to Export a [Llama 2](https://ai.meta.com/llama/) model in ExecuTorch such that it can be used in a mobile environment.
2+
This example demonstrates how to run a [Llama 2](https://ai.meta.com/llama/) model on mobile via ExecuTorch. We use XNNPACK to accelerate the performance and 4-bit groupwise PTQ quantization to fit the model on a phone.
3+
4+
35
For Llama2, please refer to [the llama's github page](https://github.com/facebookresearch/llama) for details.
46
Pretrained parameters are not included in this repo. Users are suggested to download them through [the llama's download page](https://ai.meta.com/resources/models-and-libraries/llama-downloads/).
57

@@ -12,31 +14,28 @@ Overall, Llama models are powerful and versatile language models that can be use
1214

1315
Please note that the models are subject to the [acceptable use policy](https://github.com/facebookresearch/llama/blob/main/USE_POLICY.md) and the provided [responsible use guide](https://ai.meta.com/static-resource/responsible-use-guide/).
1416

15-
# Notes
16-
1. This example is to show the feasibility of exporting a Llama2 model in ExecuTorch. There is no guarantee for performance.
17-
2. The provided checkpoint, demo_rand_params.pth is a dummy checkpoint with random parameters. It does not provide meaningful results. It's only for the purpose of demonstration and fast iterations. Use the options `--checkpoint <checkpoint>` and `--params <params>` for custom checkpoints.
18-
1917

20-
# Limitations
21-
This example tries to reuse the Python code, with modifications to make it compatible with current ExecuTorch:
22-
1. Since ExecuTorch does not support complex Tensor data type, use the customized functions to have rotary embedding with real numbers. Please see [GitHub issue: Support complex data type in ExecuTorch](https://github.com/pytorch/executorch/issues/886).
23-
2. No KV cache. The current cache implementation in the original Llama2 repo is not supported by ExecuTorch, because ExecuTorch runtime assumes model data attributes being static. Please see [GitHub issue: Add support of mutable buffers in ExecuTorch](https://github.com/pytorch/executorch/issues/897).
24-
3. No CUDA. ExecuTorch is focused on Edge use cases where CUDA is not available on most of the edge devices.
25-
4. No dependencies on fairscale. The ColumnParallelLinear, ParallelEmbedding and training are not needed and supported in ExecuTorch.
18+
# Results
2619

20+
TODO - Will fill in table of results.
2721

2822
# Instructions:
29-
### Setup
30-
1. Follow the [tutorial](https://pytorch.org/executorch/stable/getting-started-setup) to set up ExecuTorch
31-
2. `cd examples/third-party/llama`
32-
3. `pip install -e .`
33-
4. Go back to `executorch` root, run `bash examples/models/llama2/install_requirements.sh`.
23+
### Step 1: Setup
24+
1. Follow the [tutorial](https://pytorch.org/executorch/main/getting-started-setup) to set up ExecuTorch
25+
2. Run `examples/models/llama2/install_requirements.sh`.
26+
27+
### Step 2: Prepare model
3428

35-
### Export llama2 models
36-
2. From `executorch` root, run `python3 -m examples.models.llama2.export_llama`. The exported program, llama2.pte would be saved in current directory using the dummy checkpoint.
37-
3. Llama2 pretrained parameters can be downloaded [here](https://ai.meta.com/resources/models-and-libraries/llama-downloads/) and run with `python3 -m examples.models.llama2.export_llama --checkpoint <checkpoint.pth> --params <params.json>`.
29+
#### Option A: Download and export llama2 model
3830

39-
### Export and run stories110M model
31+
You can export and run the original Llama2 model.
32+
33+
1. From `executorch` root, run `python3 -m examples.models.llama2.export_llama`. The exported program, llama2.pte would be saved in current directory using the dummy checkpoint.
34+
2. Llama2 pretrained parameters can be downloaded [here](https://ai.meta.com/resources/models-and-libraries/llama-downloads/) and run with `python3 -m examples.models.llama2.export_llama --checkpoint <checkpoint.pth> --params <params.json>`.
35+
36+
#### Option B: Download and export stories110M model
37+
38+
If you want to deploy and run a smaller model for educational purposes.
4039

4140
1. Download `stories110M.pt` and `tokenizer.model` from Github.
4241
```
@@ -49,21 +48,44 @@ This example tries to reuse the Python code, with modifications to make it compa
4948
```
5049
3. Export model. Export options available [here](https://github.com/pytorch/executorch/blob/main/examples/models/llama2/export_llama_lib.py#L161).
5150
```
52-
python3 -m examples.models.llama2.export_llama -c stories110M.pt -p params.json
51+
python -m executorch.examples.models.llama2.export_llama -c stories110M.pt -p params.json
5352
```
5453
4. Create tokenizer.bin.
5554
5655
Build with buck2:
5756
```
58-
buck2 run examples/models/llama2/tokenizer:tokenizer_py -- -t tokenizer.model -o tokenizer.bin
57+
python -m executorch.examples.models.llama2.tokenizer.tokenizer -t tokenizer.model -o tokenizer.bin
5958
```
60-
Build with cmake: todo
6159
62-
5. Run model. Run options available [here](https://github.com/pytorch/executorch/blob/main/examples/models/llama2/main.cpp#L13).
60+
### Step 3: Run on your computer to validate
61+
62+
1. Build llama runner
63+
64+
2. Run model. Run options available [here](https://github.com/pytorch/executorch/blob/main/examples/models/llama2/main.cpp#L13).
6365
Build with buck2:
6466
```
6567
buck2 run examples/models/llama2:main -- --model_path=llama2.pte --tokenizer_path=tokenizer.bin --prompt="Once"
6668
```
6769
Build with cmake: todo
6870
6971
See test script [here](https://github.com/pytorch/executorch/blob/main/.ci/scripts/test_llama.sh).
72+
73+
### Step 4: Run benchmark on Android phone
74+
75+
1. Build llama runner binary for Android
76+
77+
2. Run on Android via adb shell
78+
79+
### Step 5: Build iOS and/or Android apps
80+
81+
TODO
82+
83+
### What is coming next?
84+
85+
TODO
86+
87+
# Notes
88+
This example tries to reuse the Python code, with minimal modifications to make it compatible with current ExecuTorch:
89+
1. Since ExecuTorch does not support complex Tensor data type, use the customized functions to have rotary embedding with real numbers. Please see [GitHub issue: Support complex data type in ExecuTorch](https://github.com/pytorch/executorch/issues/886).
90+
2. No CUDA. ExecuTorch is focused on Edge use cases where CUDA is not available on most of the edge devices.
91+
3. No dependencies on fairscale. The ColumnParallelLinear, ParallelEmbedding and training are not needed and supported in ExecuTorch.

0 commit comments

Comments
 (0)