Skip to content

Commit 184768d

Browse files
committed
Update Readme
stack-info: PR: #1526, branch: drisspg/stack/24
1 parent d42a382 commit 184768d

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

README.md

+37-36
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,47 @@ From the team that brought you the fast series
1515

1616
torchao just works with `torch.compile()` and `FSDP2` over most PyTorch models on Huggingface out of the box.
1717

18+
19+
## Installation
20+
21+
`torchao` makes liberal use of several new features in Pytorch, it's recommended to use it with the current nightly or latest stable version of PyTorch, see [getting started](https://pytorch.org/get-started/locally/) for more details.
22+
23+
#### Stable release from PyPI which will default to CUDA 12.4
24+
25+
```Shell
26+
pip install torchao
27+
```
28+
29+
#### Nightly Release
30+
```Shell
31+
pip install --pre torchao --index-url https://download.pytorch.org/whl/nightly/cu124 # full options are cpu/cu118/cu121/cu124
32+
```
33+
34+
#### From Source
35+
36+
For *most* developers you probably want to skip building custom C++/CUDA extensions for faster iteration
37+
38+
```Shell
39+
USE_CPP=0 pip install -e .
40+
```
41+
1842
## Inference
1943

2044
### Post Training Quantization
2145

22-
Quantizing and Sparsifying your models is a 1 liner that should work on any model with an `nn.Linear` including your favorite HuggingFace model. You can find a more comprehensive usage instructions [here](torchao/quantization/), sparsity [here](/torchao/_models/sam/README.md) and a HuggingFace inference example [here](scripts/hf_eval.py)
46+
Quantizing and Sparsifying your models is a 1 liner that should work on any model with an `nn.Linear` including your favorite HuggingFace model. You can find a more comprehensive usage instructions [here](torchao/quantization/README.md), sparsity [here](torchao/sparsity/README.md) and a HuggingFace inference example [here](scripts/hf_eval.py)
2347

2448
For inference, we have the option of
2549
1. Quantize only the weights: works best for memory bound models
2650
2. Quantize the weights and activations: works best for compute bound models
27-
2. Quantize the activations and weights and sparsify the weight
51+
3. Quantize the activations and weights and sparsify the weight
2852

2953
```python
3054
from torchao.quantization.quant_api import (
3155
quantize_,
3256
int8_dynamic_activation_int8_weight,
57+
float8_dynamic_activation_float8_weight
3358
int4_weight_only,
34-
int8_weight_only
3559
)
3660
quantize_(m, int4_weight_only())
3761
```
@@ -52,11 +76,12 @@ We also provide a developer facing API so you can implement your own quantizatio
5276

5377
We've added kv cache quantization and other features in order to enable long context length (and necessarily memory efficient) inference.
5478

55-
In practice these features alongside int4 weight only quantization allow us to **reduce peak memory by ~55%**, meaning we can Llama3.1-8B inference with a **130k context length with only 18.9 GB of peak memory.** More details can be found [here](torchao/_models/llama/README.md)
79+
In practice these features alongside int4 weight only quantization allow us to **reduce peak memory by ~55%**, meaning we can Llama3.1-8B inference with a **130k context length with only 18.9 GB of peak memory.** More details can be found [here](torchao/_models/llama/README.md#kv-cache-quantization---memory-efficient-inference)
80+
5681

5782
### Quantization Aware Training
5883

59-
Post-training quantization can result in a fast and compact model, but may also lead to accuracy degradation. We recommend exploring Quantization Aware Training (QAT) to overcome this limitation. In collaboration with Torchtune, we've developed a QAT recipe that demonstrates significant accuracy improvements over traditional PTQ, recovering **96% of the accuracy degradation on hellaswag and 68% of the perplexity degradation on wikitext** for Llama3 compared to post-training quantization (PTQ). And we've provided a full recipe [here](https://pytorch.org/blog/quantization-aware-training/)
84+
Post-training quantization can result in a fast and compact model, but may also lead to accuracy degradation. We recommend exploring Quantization Aware Training (QAT) to overcome this limitation. In collaboration with [Torchtune](https://github.com/pytorch/torchtune/blob/main/recipes/quantization.md#quantization-aware-training-qat), we've developed a QAT recipe that demonstrates significant accuracy improvements over traditional PTQ, recovering **96% of the accuracy degradation on hellaswag and 68% of the perplexity degradation on wikitext** for Llama3 compared to post-training quantization (PTQ). And we've provided a full recipe [here](https://pytorch.org/blog/quantization-aware-training/)
6085

6186
```python
6287
from torchao.quantization.qat import Int8DynActInt4WeightQATQuantizer
@@ -96,6 +121,8 @@ We've added support for semi-structured 2:4 sparsity with **6% end-to-end speedu
96121
The code change is a 1 liner with the full example available [here](torchao/sparsity/training/)
97122

98123
```python
124+
from torchao.sparsity.training import SemiSparseLinear, swap_linear_with_semi_sparse_linear
125+
99126
swap_linear_with_semi_sparse_linear(model, {"seq.0": SemiSparseLinear})
100127
```
101128

@@ -118,21 +145,21 @@ optim.load_state_dict(ckpt["optim"])
118145
```
119146

120147
## Composability
148+
`torch.compile`: A key design principle for us is composability - any custom dtype or memory layout should work with our compiler. We enable kernel implementations in PyTorch, CUDA, C++, or Triton. This allows researchers and engineers to start with high-level dtype and layout logic in pure PyTorch, then progressively optimize performance by implementing lower-level kernels as needed, while maintaining compatibility with the compile infrastructure.
121149

122-
1. `torch.compile`: A key design principle for us is composability as in any new dtype or layout we provide needs to work with our compiler. It shouldn't matter if the kernels are written in pure PyTorch, CUDA, C++, or Triton - things should just work! So we write the dtype, layout, or bit packing logic in pure PyTorch and code-generate efficient kernels.
123-
3. [FSDP2](https://github.com/pytorch/torchtitan/blob/main/docs/fsdp.md): Historically most quantization has been done for inference, there is now a thriving area of research combining distributed algorithms and quantization.
150+
[FSDP2](https://github.com/pytorch/torchtitan/blob/main/docs/fsdp.md): Historically most quantization has been done for inference, there is now a thriving area of research combining distributed algorithms and quantization.
124151

125152
The best example we have combining the composability of lower bit dtype with compile and fsdp is [NF4](torchao/dtypes/nf4tensor.py) which we used to implement the [QLoRA](https://www.youtube.com/watch?v=UvRl4ansfCg) algorithm. So if you're doing research at the intersection of this area we'd love to hear from you.
126153

127154
## Custom Kernels
128155

129-
We've added support for authoring and releasing [custom ops](./torchao/csrc/) that do not graph break with `torch.compile()` so if you love writing kernels but hate packaging them so they work all operating systems and cuda versions, we'd love to accept contributions for your custom ops. We have a few examples you can follow
156+
We've added support for authoring and releasing [custom ops](./torchao/csrc/) that do not graph break with `torch.compile()`. We have a few examples you can follow
130157

131-
1. [fp6](torchao/dtypes/floatx) for 2x faster inference over fp16 with an easy to use API `quantize_(model, fpx_weight_only(3, 2))`
158+
1. [fp6](torchao/dtypes/floatx/README.md) for 2x faster inference over fp16 with an easy to use API `quantize_(model, fpx_weight_only(3, 2))`
132159
2. [2:4 Sparse Marlin GEMM](https://github.com/pytorch/ao/pull/733) 2x speedups for FP16xINT4 kernels even at batch sizes up to 256
133160
3. [int4 tinygemm unpacker](https://github.com/pytorch/ao/pull/415) which makes it easier to switch quantized backends for inference
134161

135-
If you believe there's other CUDA kernels we should be taking a closer look at please leave a comment on [this issue](https://github.com/pytorch/ao/issues/697)
162+
If you believe there's other CUDA kernels we should be taking a closer look at please leave a comment on [this issue](https://github.com/pytorch/ao/issues/697) or feel free to contribute directly to the repo.
136163

137164

138165
## Alpha features
@@ -144,32 +171,6 @@ Things we're excited about but need more time to cook in the oven
144171
3. [IntX](https://github.com/pytorch/ao/tree/main/torchao/dtypes/uintx): We've managed to support all the ints by doing some clever bitpacking in pure PyTorch and then compiling it. This work is prototype as unfortunately without some more investment in either the compiler or low-bit kernels, int4 is more compelling than any smaller dtype
145172
4. [Bitnet](https://github.com/pytorch/ao/blob/main/torchao/prototype/dtypes/bitnet.py): Mostly this is very cool to people on the team. This is prototype because how useful these kernels are is highly dependent on better hardware and kernel support.
146173

147-
## Installation
148-
149-
`torchao` makes liberal use of several new features in Pytorch, it's recommended to use it with the current nightly or latest stable version of PyTorch.
150-
151-
Stable release from Pypi which will default to CUDA 12.1
152-
153-
```Shell
154-
pip install torchao
155-
```
156-
157-
Stable Release from the PyTorch index
158-
```Shell
159-
pip install torchao --extra-index-url https://download.pytorch.org/whl/cu121 # full options are cpu/cu118/cu121/cu124
160-
```
161-
162-
Nightly Release
163-
```Shell
164-
pip install --pre torchao --index-url https://download.pytorch.org/whl/nightly/cu121 # full options are cpu/cu118/cu121/cu124
165-
```
166-
167-
For *most* developers you probably want to skip building custom C++/CUDA extensions for faster iteration
168-
169-
```Shell
170-
USE_CPP=0 pip install -e .
171-
```
172-
173174
## OSS Integrations
174175

175176
We're also fortunate to be integrated into some of the leading open-source libraries including

0 commit comments

Comments
 (0)