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: README.md
+10-9Lines changed: 10 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -103,9 +103,9 @@ Designed for interactive graphical conversations using the familiar web browser
103
103
104
104
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.
105
105
106
-
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.
106
+
Depending on the model and the target device, different quantization recipes may be applied. Torchchat contains two example configurations to optimize performance for desktop/server (with CPU and/or GPU) systems `config/data/qconfig_server.json`, and mobile systems `config/data/qconfig_mobile.json`. This configuration is targeted towards optimizing for memory bandwidth which is a scarce resource in desktop/server (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 a few GB or less of memory.
107
107
108
-
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).
108
+
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 commands below, to optimize the exported models. To adapt these recipes or wrote your own, please refer to the [quantization overview](docs/quantization.md).
109
109
110
110
---
111
111
*TO BE REPLACED BY SUITABLE ORDING PROVIDED BY LEGAL*
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.
python3 torchchat.py generate --dso-path stories15M.so --prompt "Hello my name is"
224
+
python3 torchchat.py generate llama3 --quantize config/data/qconfig_server.json--dso-path llama3.so --prompt "Hello my name is"
225
225
```
226
226
227
-
NOTE: The exported model will be large. We suggest you quantize the model, explained further down, before deploying the model on device.
227
+
NOTE: We use `--quantize config/data/qconfig_server.json` to quantize the llama3 model to reduce model size and improve performance for on-device use cases.
228
228
229
229
### ExecuTorch
230
230
231
231
ExecuTorch enables you to optimize your model for execution on a mobile or embedded device, but can also be used on desktop for testing.
232
232
Before running ExecuTorch commands, you must first set-up ExecuTorch in torchchat, see [Set-up Executorch](docs/executorch_setup.md).
python3 torchchat.py generate --device cpu --pte-path stories15M.pte --prompt "Hello my name is"
241
+
python3 torchchat.py generate llama3 --device cpu --pte-path llama3.pte --prompt "Hello my name is"
242
242
```
243
+
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.
243
244
244
245
See below under [Mobile Execution](#run-mobile) if you want to deploy and execute a model in your iOS or Android app.
Copy file name to clipboardExpand all lines: docs/quantization.md
+58-15Lines changed: 58 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,58 @@
4
4
## Introduction
5
5
Quantization focuses on reducing the precision of model parameters and computations from floating-point to lower-bit integers, such as 8-bit integers. This approach aims to minimize memory requirements, accelerate inference speeds, and decrease power consumption, making models more feasible for deployment on edge devices with limited computational resources. While quantization can potentially degrade the model's performance, the methods supported by torchchat are designed to mitigate this effect, maintaining a balance between efficiency and accuracy.
**There are many valid group size options, including 512, 1024, etc.
25
+
26
+
## Examples
27
+
We can mix and match weight quantization with embedding quantization. Quantization options are passed in json format either as a config file (see [qconfig_server.json](../config/data/qconfig_server.json) and [qconfig_mobile.json](../config/data/qconfig_mobile.json)) or a json string.
Quantization recipes can be applied in conjunction with any of the `chat`, `generate`, `browser` and `export` commands. Below are examples showcasing eager mode with `generate` and AOTI and ExecuTorch with `export`.
42
+
### Eager mode
43
+
```
44
+
python3 generate.py [--compile] --checkpoint-path ${MODEL_PATH} --prompt "Hello, my name is" --quantize '{"embedding" : {"bitwidth": 8, "groupsize": 0}}' --device cpu
linear operator (asymmetric) with GPTQ | n/a | 4b (group) | n/a |
15
-
linear operator (asymmetric) with HQQ | n/a | work in progress | n/a |
16
59
17
60
## Model precision (dtype precision setting)
18
61
You can generate models (for both export and generate, with eager, torch.compile, AOTI, ET, for all backends - mobile at present will primarily support fp32, with all options) specify the precision of the model with
Unlike gpt-fast which uses bfloat16 as default, torchchat uses float32 as the default. As a consequence you will have to set to --dtype bf16 or --dtype fp16 on server / desktop for best performance.
27
-
Support for FP16 and BF16 is limited in many embedded processors. Additional executorch support for 16-bit floating point types may be added in the future based on hardware support.
70
+
Support for FP16 and BF16 is limited in many embedded processors. Additional ExecuTorch support for 16-bit floating point types may be added in the future based on hardware support.
0 commit comments