qaihm-bot commited on
Commit
72407af
·
verified ·
1 Parent(s): f9475b8

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +43 -133
README.md CHANGED
@@ -17,20 +17,19 @@ tags:
17
 
18
  Llama 2 is a family of LLMs. The "Chat" at the end indicates that the model is optimized for chatbot-like dialogue. The model is quantized to w4a16(4-bit weights and 16-bit activations) and part of the model is quantized to w8a16(8-bit weights and 16-bit activations) making it suitable for on-device deployment. For Prompt and output length specified below, the time to first token is Llama-PromptProcessor-Quantized's latency and average time per addition token is Llama-TokenGenerator-KVCache-Quantized's latency.
19
 
20
- This model is an implementation of Llama-v2-7B-Chat found [here](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf).
21
- This repository provides scripts to run Llama-v2-7B-Chat on Qualcomm® devices.
22
- More details on model performance across various devices, can be found
23
- [here](https://aihub.qualcomm.com/models/llama_v2_7b_chat_quantized).
24
-
25
 
26
  ### Model Details
27
 
28
  - **Model Type:** Text generation
29
  - **Model Stats:**
 
 
30
  - Number of parameters: 7B
31
  - Precision: w4a16 + w8a16 (few layers)
32
  - Model-1 (Prompt Processor): Llama-PromptProcessor-Quantized
33
- - Max context length: 1024
34
  - Prompt processor model size: 3.6 GB
35
  - Prompt processor input: 1024 tokens
36
  - Prompt processor output: 1024 output tokens + KVCache for token generator
@@ -38,31 +37,22 @@ More details on model performance across various devices, can be found
38
  - Token generator model size: 3.6 GB
39
  - Token generator input: 1 input token + past KVCache
40
  - Token generator output: 1 output token + KVCache for next iteration
41
- - Decoding length: 1024 (1 output token + 1023 from KVCache)
42
  - Use: Initiate conversation with prompt-processor and then token generator for subsequent iterations.
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  ## Deploying Llama 2 on-device
45
 
46
- Large Language Model (LLM) such as [Llama 2](https://llama.meta.com/llama2/) has the following complexities to deploy on-device:
47
- 1. Model size is too large to fit in device memory for inference
48
- 2. Multi-Head Attention (MHA) has large activations leading to fallback from accelerators
49
- 3. High model load and inference time
50
-
51
- We can tackle the above constraints with the following steps:
52
- 1. Quantize weights to reduce on-disk model size, e.g., int8 or int4 weights
53
- 2. Quantize activations to reduce inference time memory pressure
54
- 3. Graph transformations to reduce inference time memory pressure, e.g., Multi-Head to Split-Head Attention (MHA -> SHA)
55
- 4. Graph transformations to convert or decompose operations into more accelerator friendly operations e.g. Linear to Conv
56
- 5. For LLM with 7B or more parameters, above steps are still not good enough on mobile,
57
- hence we go one step further and split model into sub-parts.
58
-
59
- Here, we divide the model into 4 parts in order to
60
- 1. Make model exportable with low memory usage
61
- 2. Avoid inference time out-of-memory errors
62
-
63
- In order to export Llama 2, please ensure
64
- 1. Host machine has >40GB memory (RAM+swap-space)
65
- 2. If you don't have enough memory, export.py will dump instructions to increase swap space accordingly.
66
 
67
  ## Sample output prompts generated on-device
68
  1. --prompt "what is gravity?" --max-output-tokens 30
@@ -98,119 +88,39 @@ print(fibonacci(5))
98
 
99
 
100
 
101
- | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
102
- | ---|---|---|---|---|---|---|---|
103
- | Samsung Galaxy S23 Ultra (Android 13) | Snapdragon® 8 Gen 2 | QNN Model Library | 97.732 ms | 71 - 72 MB | UINT16 | NPU | Llama2-TokenGenerator-KVCache-Quantized
104
- | Samsung Galaxy S23 Ultra (Android 13) | Snapdragon® 8 Gen 2 | QNN Model Library | 2020.745 ms | 11 - 12 MB | UINT16 | NPU | Llama2-PromptProcessor-Quantized
105
-
106
-
107
-
108
- ## Installation
109
-
110
- This model can be installed as a Python package via pip.
111
-
112
- ```bash
113
- pip install "qai-hub-models[llama_v2_7b_chat_quantized]"
114
- ```
115
-
116
-
117
-
118
- ## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
119
-
120
- Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
121
- Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
122
-
123
- With this API token, you can configure your client to run models on the cloud
124
- hosted devices.
125
- ```bash
126
- qai-hub configure --api_token API_TOKEN
127
- ```
128
- Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
129
-
130
-
131
-
132
- ## Demo off target
133
-
134
- The package contains a simple end-to-end demo that downloads pre-trained
135
- weights and runs this model on a sample input.
136
-
137
- ```bash
138
- python -m qai_hub_models.models.llama_v2_7b_chat_quantized.demo
139
- ```
140
-
141
- The above demo runs a reference implementation of pre-processing, model
142
- inference, and post processing.
143
-
144
- **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
145
- environment, please add the following to your cell (instead of the above).
146
- ```
147
- %run -m qai_hub_models.models.llama_v2_7b_chat_quantized.demo
148
- ```
149
-
150
-
151
- ### Run model on a cloud-hosted device
152
-
153
- In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
154
- device. This script does the following:
155
- * Performance check on-device on a cloud-hosted device
156
- * Downloads compiled assets that can be deployed on-device for Android.
157
- * Accuracy check between PyTorch and on-device outputs.
158
-
159
- ```bash
160
- python -m qai_hub_models.models.llama_v2_7b_chat_quantized.export
161
- ```
162
-
163
- ```
164
- Profile Job summary of Llama2-TokenGenerator-KVCache-Quantized
165
- --------------------------------------------------
166
- Device: Snapdragon X Elite CRD (11)
167
- Estimated Inference Time: 95.96 ms
168
- Estimated Peak Memory Range: 65.07-65.07 MB
169
- Compute Units: NPU (33818) | Total (33818)
170
-
171
- Profile Job summary of Llama2-PromptProcessor-Quantized
172
- --------------------------------------------------
173
- Device: Snapdragon X Elite CRD (11)
174
- Estimated Inference Time: 1889.09 ms
175
- Estimated Peak Memory Range: 10.29-10.29 MB
176
- Compute Units: NPU (31766) | Total (31766)
177
-
178
-
179
- ```
180
-
181
-
182
-
183
-
184
-
185
- ## Deploying compiled model to Android
186
-
187
-
188
- The models can be deployed using multiple runtimes:
189
- - TensorFlow Lite (`.tflite` export): [This
190
- tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
191
- guide to deploy the .tflite model in an Android application.
192
-
193
-
194
- - QNN (`.so` export ): This [sample
195
- app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
196
- provides instructions on how to use the `.so` shared library in an Android application.
197
-
198
 
199
- ## View on Qualcomm® AI Hub
200
- Get more details on Llama-v2-7B-Chat's performance across various devices [here](https://aihub.qualcomm.com/models/llama_v2_7b_chat_quantized).
201
- Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
202
 
203
- ## License
204
- - The license for the original implementation of Llama-v2-7B-Chat can be found
205
- [here](https://github.com/facebookresearch/llama/blob/main/LICENSE).
206
- - The license for the compiled assets for on-device deployment can be found [here](https://github.com/facebookresearch/llama/blob/main/LICENSE)
207
 
208
  ## References
209
  * [LLaMA: Open and Efficient Foundation Language Models](https://arxiv.org/abs/2302.13971)
210
  * [Source Model Implementation](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf)
211
 
 
 
212
  ## Community
213
- * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
214
  * For questions or feedback please [reach out to us](mailto:[email protected]).
215
 
216
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  Llama 2 is a family of LLMs. The "Chat" at the end indicates that the model is optimized for chatbot-like dialogue. The model is quantized to w4a16(4-bit weights and 16-bit activations) and part of the model is quantized to w8a16(8-bit weights and 16-bit activations) making it suitable for on-device deployment. For Prompt and output length specified below, the time to first token is Llama-PromptProcessor-Quantized's latency and average time per addition token is Llama-TokenGenerator-KVCache-Quantized's latency.
19
 
20
+ This is based on the implementation of Llama-v2-7B-Chat found
21
+ [here]({source_repo}). More details on model performance
22
+ accross various devices, can be found [here](https://aihub.qualcomm.com/models/llama_v2_7b_chat_quantized).
 
 
23
 
24
  ### Model Details
25
 
26
  - **Model Type:** Text generation
27
  - **Model Stats:**
28
+ - Input sequence length for Prompt Processor: 1024
29
+ - Context length: 1024
30
  - Number of parameters: 7B
31
  - Precision: w4a16 + w8a16 (few layers)
32
  - Model-1 (Prompt Processor): Llama-PromptProcessor-Quantized
 
33
  - Prompt processor model size: 3.6 GB
34
  - Prompt processor input: 1024 tokens
35
  - Prompt processor output: 1024 output tokens + KVCache for token generator
 
37
  - Token generator model size: 3.6 GB
38
  - Token generator input: 1 input token + past KVCache
39
  - Token generator output: 1 output token + KVCache for next iteration
 
40
  - Use: Initiate conversation with prompt-processor and then token generator for subsequent iterations.
41
+ - Minimum QNN SDK version required: 2.27.0
42
+ - Supported languages: English.
43
+ - TTFT: Time To First Token is the time it takes to generate the first response token. This is expressed as a range because it varies based on the length of the prompt. For Llama-v2-7B-Chat, both values in the range are the same since prompt length is the full context length (1024 tokens).
44
+ - Response Rate: Rate of response generation after the first response token.
45
+
46
+ | Model | Device | Chipset | Target Runtime | Response Rate (tokens per second) | Time To First Token (range, seconds)
47
+ |---|---|---|---|---|---|
48
+ | Llama-v2-7B-Chat | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 12.85 | 1.49583 - 1.49583 | -- | -- |
49
+ | Llama-v2-7B-Chat | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 11.2 | 1.9189999999999998 - 1.9189999999999998 | -- | -- |
50
+ | Llama-v2-7B-Chat | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 11.2 | 1.9189999999999998 - 1.9189999999999998 | -- | -- |
51
+ | Llama-v2-7B-Chat | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 17.94 | 1.44 - 1.44 | -- | -- |
52
 
53
  ## Deploying Llama 2 on-device
54
 
55
+ Please follow the [LLM on-device deployment](https://github.com/quic/ai-hub-apps/tree/main/tutorials/llm_on_genie) tutorial.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  ## Sample output prompts generated on-device
58
  1. --prompt "what is gravity?" --max-output-tokens 30
 
88
 
89
 
90
 
91
+ ## License
92
+ * The license for the original implementation of Llama-v2-7B-Chat can be found [here](https://github.com/facebookresearch/llama/blob/main/LICENSE).
93
+ * The license for the compiled assets for on-device deployment can be found [here](https://github.com/facebookresearch/llama/blob/main/LICENSE)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
 
 
 
95
 
 
 
 
 
96
 
97
  ## References
98
  * [LLaMA: Open and Efficient Foundation Language Models](https://arxiv.org/abs/2302.13971)
99
  * [Source Model Implementation](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf)
100
 
101
+
102
+
103
  ## Community
104
+ * Join [our AI Hub Slack community](https://qualcomm-ai-hub.slack.com/join/shared_invite/zt-2d5zsmas3-Sj0Q9TzslueCjS31eXG2UA#/shared-invite/email) to collaborate, post questions and learn more about on-device AI.
105
  * For questions or feedback please [reach out to us](mailto:[email protected]).
106
 
107
+ ## Usage and Limitations
108
+
109
+ Model may not be used for or in connection with any of the following applications:
110
+
111
+ - Accessing essential private and public services and benefits;
112
+ - Administration of justice and democratic processes;
113
+ - Assessing or recognizing the emotional state of a person;
114
+ - Biometric and biometrics-based systems, including categorization of persons based on sensitive characteristics;
115
+ - Education and vocational training;
116
+ - Employment and workers management;
117
+ - Exploitation of the vulnerabilities of persons resulting in harmful behavior;
118
+ - General purpose social scoring;
119
+ - Law enforcement;
120
+ - Management and operation of critical infrastructure;
121
+ - Migration, asylum and border control management;
122
+ - Predictive policing;
123
+ - Real-time remote biometric identification in public spaces;
124
+ - Recommender systems of social media platforms;
125
+ - Scraping of facial images (from the internet or otherwise); and/or
126
+ - Subliminal manipulation