You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/llm/build-run-llama3-qualcomm-ai-engine-direct-backend.md
+33-13Lines changed: 33 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -13,37 +13,57 @@ This tutorial demonstrates how to export Llama 3 8B Instruct for Qualcomm AI Eng
13
13
14
14
## Instructions
15
15
16
-
### Step1: Prepare the checkpoint of the model and optimized matrix from [Spin Quant](https://github.com/facebookresearch/SpinQuant)
16
+
### Step 1: Prepare the checkpoint of the model and optimized matrix from [Spin Quant](https://github.com/facebookresearch/SpinQuant)
17
17
18
18
1. For Llama 3 tokenizer and checkpoint, please refer to https://github.com/meta-llama/llama-models/blob/main/README.md for further instructions on how to download `tokenizer.model`, `consolidated.00.pth` and `params.json`.
19
19
2. To get the optimized matrix, please refer to [SpinQuant on GitHub](https://github.com/facebookresearch/SpinQuant). You can download the optimized rotation matrices in the Quantized Models section. Please choose **LLaMA-3-8B/8B_W4A16KV16_lr_1.5_seed_0**.
20
20
21
-
### Step2: Export to ExecuTorch with Qualcomm AI Engine Direct Backend
21
+
### Step 2: Export to ExecuTorch with Qualcomm AI Engine Direct Backend
22
22
Deploying large language models like Llama 3 on-device presents the following challenges:
23
23
24
24
1. The model size is too large to fit in device memory for inference.
25
25
2. High model loading and inference time.
26
26
3. Difficulty in quantization.
27
27
28
28
To address these challenges, we have implemented the following solutions:
29
-
1. Using `--pt2e_quantize qnn_16a4w` to quantize activations and weights, thereby reducing the on-disk model size and alleviating memory pressure during inference.
30
-
2. Using `--num_sharding 8` to shard the model into sub-parts.
29
+
1. Using `quantization.pt2e_quantize = "qnn_16a4w'` to quantize activations and weights, thereby reducing the on-disk model size and alleviating memory pressure during inference.
30
+
2. Using `backed.qnn.num_sharding = 8` to shard the model into sub-parts.
31
31
3. Performing graph transformations to convert or decompose operations into more accelerator-friendly operations.
32
-
4. Using `--optimized_rotation_path <path_to_optimized_matrix>` to apply R1 and R2 of [Spin Quant](https://github.com/facebookresearch/SpinQuant) to improve accuracy.
33
-
5. Using `--calibration_data "<|start_header_id|>system<|end_header_id|..."` to ensure that during the quantization of Llama 3 8B instruct, the calibration includes special tokens in the prompt template. For more details on the prompt template, refer to [the model card of meta llama3 instruct](https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3/).
32
+
4. Using `backend.qnn.optimized_rotation_path = "<path_to_optimized_matrix>"` to apply R1 and R2 of [Spin Quant](https://github.com/facebookresearch/SpinQuant) to improve accuracy.
33
+
5. Using `quantization.calibration_data = "<|start_header_id|>system<|end_header_id|..."` to ensure that during quantization, the calibration includes special tokens in the prompt template. For more details on the prompt template, refer to [the model card](https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3/).
34
34
35
-
To export Llama 3 8B instruct with the Qualcomm AI Engine Direct Backend, ensure the following:
35
+
To export with the Qualcomm AI Engine Direct Backend, ensure the following:
36
36
37
37
1. The host machine has more than 100GB of memory (RAM + swap space).
38
38
2. The entire process takes a few hours.
39
39
40
40
```bash
41
-
# Please note that calibration_data must include the prompt template for special tokens.
# Please note that calibration_data must include the prompt template for special tokens.
54
+
calibration_data: "<|start_header_id|>system<|end_header_id|>\n\nYou are a funny chatbot.<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nCould you tell me about Facebook?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
55
+
backend:
56
+
qnn:
57
+
enabled: True
58
+
num_sharding: 8
59
+
60
+
61
+
# export_llm
62
+
python -m extension.llm.export.export_llm \
63
+
--config path/to/config.yaml
44
64
```
45
65
46
-
### Step3: Invoke the Runtime on an Android smartphone with Qualcomm SoCs
66
+
### Step 3: Invoke the Runtime on an Android smartphone with Qualcomm SoCs
47
67
1. Build executorch with Qualcomm AI Engine Direct Backend for android
48
68
```bash
49
69
cmake \
@@ -116,9 +136,9 @@ You should see the message:
116
136
```
117
137
118
138
## What is coming?
119
-
- Improve the performance for Llama 3 Instruct
139
+
- Performance improvements
120
140
- Reduce the memory pressure during inference to support 12GB Qualcomm devices
0 commit comments