|
| 1 | +# Model Customization |
| 2 | + |
| 3 | +By default, torchchat (and PyTorch) defaults to unquantized [eager execution](https://pytorch.org/blog/optimizing-production-pytorch-performance-with-graph-transformations/). |
| 4 | + |
| 5 | +This page goes over the different options torchchat provides for customizing the model execution for inference. |
| 6 | +- Device |
| 7 | +- Compilation |
| 8 | +- Model Precision |
| 9 | +- Quantization |
| 10 | + |
| 11 | + |
| 12 | +## Device |
| 13 | + |
| 14 | +``` |
| 15 | +python3 (chat | generate | browser | server | export | eval) --device [cpu | cuda | mps] ... |
| 16 | +``` |
| 17 | + |
| 18 | +To leverage a specific accelerator, the target device can be set. |
| 19 | + |
| 20 | +By default, torchchat defaults to the fastest executor available in the system, chosen in this |
| 21 | +order: cuda, mps, and cpu. |
| 22 | + |
| 23 | + |
| 24 | +## Compilation: JIT-compiled execution |
| 25 | +``` |
| 26 | +python3 (chat | generate | browser | server | eval) [--compile][--compile_prefill] ... |
| 27 | +``` |
| 28 | + |
| 29 | +To improve performance, you can compile the model with `--compile`; |
| 30 | +trading off the time to first token processed with time per token. |
| 31 | + |
| 32 | +To improve performance further, at the cost of increased compile time, you may also compile the |
| 33 | +prefill with `--compile_prefill`. |
| 34 | + |
| 35 | +To learn more about compilation, check out: https://pytorch.org/get-started/pytorch-2.0/ |
| 36 | + |
| 37 | + |
| 38 | +## Model Precision |
| 39 | + |
| 40 | +``` |
| 41 | +python3 (chat | generate | browser | server | export | eval) --dtype [fast | fast16 | bf16 | fp16 | fp32] ... |
| 42 | +``` |
| 43 | + |
| 44 | +To reduce the memory bandwidth requirement and to take advantage of higher density compute available, |
| 45 | +the model can use lower precision floating point representations. |
| 46 | +For example, many GPUs and some of the CPUs have good support for bfloat16 and float16. |
| 47 | + |
| 48 | +See the [precision guide](quantization.md#model-precision-dtype-precision-setting) for more details. |
| 49 | + |
| 50 | + |
| 51 | +## Quantization |
| 52 | + |
| 53 | +``` |
| 54 | +python3 (chat | generate | browser | server | export | eval) [--quantize] <quant.json> ... |
| 55 | +``` |
| 56 | + |
| 57 | +To further minimize memory requirements, accelerate inference speeds, and |
| 58 | +decrease power consumption the model can also be quantized. |
| 59 | +Torchchat leverages [torchao](https://github.com/pytorch/ao) for quantization. |
| 60 | + |
| 61 | +See the [quantization guide](quantization.md) for examples and more details. |
0 commit comments