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
* improve updown parser, and use in README.md execution
* cut/paste errors
* typo: true -> false
* we scan each partial line, so need to suppress at partial line level :(
* make it twice as nice
* improved updown parsing
* special handling for lines w/o option
* enable run on quantization doc
* handle white space before trip backtick
* updates
* mps test
* updates
* Update run-readme-pr-macos.yml
Rename test to avoid babe conflict
* Update run-readme-pr.yml
Y
* Update run-readme-pr-mps.yml
2
* typos
* add updown end command
* typo
* move broken mps
* Update parking_lot/run-readme-pr-mps.yml
Co-authored-by: Eli Uriegas <[email protected]>
---------
Co-authored-by: Eli Uriegas <[email protected]>
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. For high-performance devices such as GPUs, quantization provides a way to reduce the required memory bandwidth and take advantage of the massive compute capabilities provided by today's server-based accelerators such as GPUs.
6
9
@@ -13,36 +16,68 @@ While quantization can potentially degrade the model's performance, the methods
^a8w4dq quantization scheme requires model to be converted to fp32, due to lack of support for fp16 and bf16 in the kernels provided with ExecuTorch.
31
+
^ a8w4dq quantization scheme requires model to be converted to fp32,
32
+
due to lack of support for fp16 and bf16 in the kernels provided with
33
+
ExecuTorch.
26
34
27
35
* These are the only valid bitwidth options.
28
36
29
-
** There are many valid group size options, including 512, 1024, etc. Note that smaller groupsize tends to be better for preserving model quality and accuracy, and larger groupsize for further improving performance. Set 0 for channelwise quantization.
37
+
** There are many valid group size options, including 512, 1024,
38
+
etc. Note that smaller groupsize tends to be better for preserving
39
+
model quality and accuracy, and larger groupsize for further
40
+
improving performance. Set 0 for channelwise quantization.
30
41
31
-
***[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.
42
+
***[GPTQ](https://arxiv.org/abs/2210.17323) and
43
+
[HQQ](https://mobiusml.github.io/hqq_blog/) are two different
44
+
algorithms to address accuracy loss when using lower bit
45
+
quantization. Due to HQQ relying on data/calibration free
46
+
quantization, it tends to take less time to quantize model.
32
47
33
48
## Quantization Profiles
34
-
Torchchat quantization supports profiles with multiple settings such as accelerator, dtype, and quantization specified in a JSON file. Four sample profiles are included wwith the torchchat distributin in config/data: `cuda.json`, `desktop.json`, `mobile.json`, `pi5.json` with profiles optimizing for execution on cuda, desktop, mobile and raspberry Pi devices.
35
-
36
-
In addition to quantization recipes described below, the profiles also enable developers to specify the accelerator and dtype to be used.
37
-
38
-
At present torchchat supports the fast, cuda, mps, and cpu devices. The default device in torchchat is "fast". The "fast" device is a virtual device that defaults to the fastest executor available in the system, selecting cuda, mps, and cpu in this order.
39
49
40
-
At present torchchat supports the fast16, fast, bf16, fp16 and fp32 data types. The default data type for models is "fast16". The "fast16" data type is a virtual data type that defaults to the best 16-bit floating point data type available on the selected device. The "fast" data type is a virtual data type that defaults to the best floating point data type available on the selected device. ("Best" tangibly representing a combination of speed and accuracy.)
50
+
Torchchat quantization supports profiles with multiple settings such
51
+
as accelerator, dtype, and quantization specified in a JSON file.
52
+
Four sample profiles are included wwith the torchchat distributin in
with profiles optimizing for execution on cuda, desktop, mobile and
55
+
raspberry Pi devices.
56
+
57
+
In addition to quantization recipes described below, the profiles also
58
+
enable developers to specify the accelerator and dtype to be used.
59
+
60
+
At present torchchat supports the fast, cuda, mps, and cpu devices.
61
+
The default device in torchchat is "fast". The "fast" device is a
62
+
virtual device that defaults to the fastest executor available in the
63
+
system, selecting cuda, mps, and cpu in this order.
64
+
65
+
At present torchchat supports the fast16, fast, bf16, fp16 and fp32
66
+
data types. The default data type for models is "fast16". The
67
+
"fast16" data type is a virtual data type that defaults to the best
68
+
16-bit floating point data type available on the selected device. The
69
+
"fast" data type is a virtual data type that defaults to the best
70
+
floating point data type available on the selected device. ("Best"
71
+
tangibly representing a combination of speed and accuracy.)
41
72
42
73
## Quantization API
43
-
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.
44
74
45
-
The expected JSON format is described below. Refer to the tables above for valid `bitwidth` and `groupsize` values.
75
+
Quantization options are passed in json format either as a config file
76
+
(see [cuda.json](../config/data/cuda.json) and
77
+
[mobile.json](../config/data/mobile.json)) or a JSON string.
78
+
79
+
The expected JSON format is described below. Refer to the tables above
80
+
for valid `bitwidth` and `groupsize` values.
46
81
47
82
| compression | JSON string |
48
83
|--|--|
@@ -57,6 +92,7 @@ See the available quantization schemes [here](https://github.com/pytorch/torchch
57
92
## Examples
58
93
We can mix and match weight quantization with embedding quantization.
59
94
95
+
[skip default]: begin
60
96
* Config file
61
97
```
62
98
--quantize quant_config.json
@@ -69,16 +105,22 @@ We can mix and match weight quantization with embedding quantization.
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`.
108
+
[skip default]: end
109
+
110
+
Quantization recipes can be applied in conjunction with any of the
111
+
`chat`, `generate`, `browser` and `export` commands. Below are
112
+
examples showcasing eager mode with `generate` and AOTI and ExecuTorch
113
+
with `export`.
114
+
73
115
### Eager mode
74
116
```
75
117
python3 generate.py [--compile] llama3 --prompt "Hello, my name is" --quantize '{"embedding" : {"bitwidth": 8, "groupsize": 0}}' --device cpu
python3 generate.py llama3 --dso-path llama3.dso --prompt "Hello my name is"
123
+
python3 generate.py llama3 --dso-path llama3.so --prompt "Hello my name is"
82
124
```
83
125
### ExecuTorch
84
126
```
@@ -90,10 +132,12 @@ python3 generate.py llama3 --pte-path llama3.pte --prompt "Hello my name is"
90
132
## Model precision (dtype precision setting)
91
133
On top of quantizing models with integer quantization schemes mentioned above, models can be converted to lower bit floating point precision to reduce the memory bandwidth requirement and take advantage of higher density compute available. For example, many GPUs and some of the CPUs have good support for BFloat16 and Float16. This can be taken advantage of via `--dtype` arg as shown below.
Unlike gpt-fast which uses bfloat16 as default, torchchat uses the dtype "fast16" as the default. Torchchat will pick the appropriate 16-bit floating point type available and offering the best performance (for execution with Executorch, macOS/ARM and Linux/x86 platforms). For macOS, support depends on the OS version, with versions starting with 14.0 supporting bfloat16 as support, and float16 for earlier OS version based on system support for these data types.
99
143
@@ -109,3 +153,5 @@ We invite contributors to submit established quantization schemes, with accuracy
109
153
- Quantization reference, describe options for --quantize parameter
110
154
- Show a table with performance/accuracy metrics
111
155
- Quantization support matrix? torchchat Quantization Support Matrix
0 commit comments