Skip to content

Commit 92a298c

Browse files
lucylqmalfet
authored andcommitted
Quantize llama3 on et export (#436)
* create dir on download * quantization
1 parent 80f7856 commit 92a298c

File tree

4 files changed

+71
-253
lines changed

4 files changed

+71
-253
lines changed

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,13 @@ Designed for interactive graphical conversations using the familiar web browser
111111

112112
Quantization is the process of converting a model into a more memory-efficient representation. Quantization is particularly important for accelerators -- to take advantage of the available memory bandwidth, and fit in the often limited high-speed memory in accelerators – and mobile devices – to fit in the typically very limited memory of mobile devices.
113113

114+
Depending on the model and the target device, different quantization recipes may be applied. Torchchat contains two example configurations to optimize performance for GPU-based systems `config/data/qconfig_gpu.json`, and mobile systems `config/data/qconfig_mobile.json`. The GPU configuration is targeted towards optimizing for memory bandwidth which is a scarce resource in powerful GPUs (and to a less degree, memory footprint to fit large models into a device's memory). The mobile configuration is targeted towards optimizing for memory fotoprint because in many devices, a single application is limited to as little as GB or less of memory.
114115

115-
Depending on the model and the target device, different quantization recipes may be applied. Torchchat contains two example configurations to optimize performance for GPU-based systems `config/data/cuda.json` , and mobile systems `config/data/mobile.json`. The GPU configuration is targeted towards optimizing for memory bandwidth which is a scarce resource in powerful GPUs (and to a less degree, memory footprint to fit large models into a device's memory). The mobile configuration is targeted towards optimizing for memory fotoprint because in many devices, a single application is limited to as little as GB or less of memory.
116-
117-
You can use the quantization recipes in conjunction with any of the `chat`, `generate` and `browser` commands to test their impact and accelerate model execution. You will apply these recipes to the export comamnds below, to optimize the exported models. To adapt these recipes or wrote your own, please refer to the [quantization overview](docs/quantization.md).
116+
You can use the quantization recipes in conjunction with any of the `chat`, `generate` and `browser` commands to test their impact and accelerate model execution. You will apply these recipes to the `export` comamnds below, to optimize the exported models. For example:
117+
```
118+
python3 torchchat.py chat llama3 --quantize config/data/qconfig_gpu.json
119+
```
120+
To adapt these recipes or wrote your own, please refer to the [quantization overview](docs/quantization.md).
118121

119122
*TO BE REPLACED BY SUITABLE ORDING PROVIDED BY LEGAL:*
120123

@@ -223,16 +226,16 @@ python3 torchchat.py chat codellama
223226
AOT compiles models into machine code before execution, enhancing performance and predictability. It's particularly beneficial for frequently used models or those requiring quick start times. However, it may lead to larger binary sizes and lacks the runtime flexibility of eager mode.
224227

225228
**Examples**
226-
The following example uses the Stories15M model.
229+
The following example uses the Llama3 8B model.
227230
```
228231
# Compile
229-
python3 torchchat.py export stories15M --output-dso-path stories15M.so
232+
python3 torchchat.py export llama3 --output-dso-path llama3.so
230233
231234
# Execute
232-
python3 torchchat.py generate --dso-path stories15M.so --prompt "Hello my name is"
235+
python3 torchchat.py generate llama3 --quantize config/data/qconfig_gpu.json--dso-path llama3.so --prompt "Hello my name is"
233236
```
234237

235-
NOTE: The exported model will be large. We suggest you quantize the model, explained further down, before deploying the model on device.
238+
NOTE: We use `--quantize config/data/qconfig_gpu.json` to quantize the llama3 model to reduce model size and improve performance for on-device use cases.
236239

237240
**Build Native Runner Binary**
238241

@@ -254,14 +257,15 @@ ExecuTorch enables you to optimize your model for execution on a mobile or embed
254257
Before running ExecuTorch commands, you must first set-up ExecuTorch in torchchat, see [Set-up Executorch](docs/executorch_setup.md).
255258

256259
**Examples**
257-
The following example uses the Stories15M model.
260+
The following example uses the Llama3 8B model.
258261
```
259262
# Compile
260-
python3 torchchat.py export stories15M --output-pte-path stories15M.pte
263+
python3 torchchat.py export llama3 --quantize config/data/qconfig_mobile.json --output-pte-path llama3.pte
261264
262265
# Execute
263-
python3 torchchat.py generate --device cpu --pte-path stories15M.pte --prompt "Hello my name is"
266+
python3 torchchat.py generate llama3 --device cpu --pte-path llama3.pte --prompt "Hello my name is"
264267
```
268+
NOTE: We use `--quantize config/data/qconfig_mobile.json` to quantize the llama3 model to reduce model size and improve performance for on-device use cases.
265269

266270
See below under [Mobile Execution](#mobile-execution) if you want to deploy and execute a model in your iOS or Android app.
267271

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)