Skip to content

Rename quant config files #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ with `python3 torchchat.py remove llama3`.
* in Chat mode
* in Generate mode
* Fine-tuned models from torchtune


## Running via PyTorch / Python

Expand All @@ -92,7 +92,7 @@ In chat mode, the LLM engages in a back-and-forth dialogue with the user. It res

```bash
# Llama 3 8B Instruct
python3 torchchat.py chat llama3
python3 torchchat.py chat llama3
```

```
Expand Down Expand Up @@ -134,11 +134,11 @@ Enter some text in the input box, then hit the enter key or click the “SEND”

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.

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.
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.

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:
```
python3 torchchat.py chat llama3 --quantize config/data/qconfig_gpu.json
python3 torchchat.py chat llama3 --quantize config/data/cuda.json
```
To adapt these recipes or wrote your own, please refer to the [quantization overview](docs/quantization.md).

Expand All @@ -157,10 +157,10 @@ The following example uses the Llama3 8B model.
python3 torchchat.py export llama3 --output-dso-path llama3.so

# Execute
python3 torchchat.py generate llama3 --quantize config/data/qconfig_gpu.json--dso-path llama3.so --prompt "Hello my name is"
python3 torchchat.py generate llama3 --quantize config/data/cuda.json--dso-path llama3.so --prompt "Hello my name is"
```

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.
NOTE: We use `--quantize config/data/cuda.json` to quantize the llama3 model to reduce model size and improve performance for on-device use cases.

**Build Native Runner Binary**

Expand All @@ -185,12 +185,12 @@ Before running ExecuTorch commands, you must first set-up ExecuTorch in torchcha
The following example uses the Llama3 8B model.
```
# Compile
python3 torchchat.py export llama3 --quantize config/data/qconfig_mobile.json --output-pte-path llama3.pte
python3 torchchat.py export llama3 --quantize config/data/mobile.json --output-pte-path llama3.pte

# Execute
python3 torchchat.py generate llama3 --device cpu --pte-path llama3.pte --prompt "Hello my name is"
```
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.
NOTE: We use `--quantize config/data/mobile.json` to quantize the llama3 model to reduce model size and improve performance for on-device use cases.

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

Expand Down Expand Up @@ -336,6 +336,6 @@ you've built around local LLM inference.


## License
torchchat is released under the [BSD 3 license](LICENSE). (Additional code in this
torchchat is released under the [BSD 3 license](LICENSE). (Additional code in this
distribution is covered by the MIT and Apache Open Source licenses.) However you may have other legal obligations
that govern your use of content, such as the terms of service for third-party models.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/quantization.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Due to the larger vocabulary size of llama3, we also recommend quantizing the em
*** [GPTQ](https://arxiv.org/abs/2210.17323) and [HQQ](https://mobiusml.github.io/hqq_blog/) are two different algorithms to address accuracy loss when using lower bit quantization. Due to HQQ relying on data/calibration free quantization, it tends to take less time to quantize model.

## Quantization API
Quantization options are passed in json format either as a config file (see [qconfig_gpu.json](../config/data/qconfig_gpu.json) and [qconfig_mobile.json](../config/data/qconfig_mobile.json)) or a JSON string.
Quantization options are passed in json format either as a config file (see [cuda.json](../config/data/cuda.json) and [mobile.json](../config/data/mobile.json)) or a JSON string.

The expected JSON format is described below. Refer to the tables above for valid `bitwidth` and `groupsize` values.

Expand Down