Skip to content
Merged
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
23 changes: 22 additions & 1 deletion docs/source/optimization_ov.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ tokenizer.save_pretrained(save_dir)

The `quantize()` method applies post-training static quantization and export the resulting quantized model to the OpenVINO Intermediate Representation (IR). The resulting graph is represented with two files: an XML file describing the network topology and a binary file describing the weights. The resulting model can be run on any target Intel device.

### Weights compression

For large language models (LLMs), it is often beneficial to only quantize weights, and keep activations in floating point precision. This method does not require a calibration dataset. To enable weights compression, set the `weights_only` parameter of `OVQuantizer`:

```python
from optimum.intel.openvino import OVQuantizer, OVModelForCausalLM
from transformers import AutoModelForCausalLM

save_dir = "int8_weights_compressed_model"
model = AutoModelForCausalLM.from_pretrained("databricks/dolly-v2-3b")
quantizer = OVQuantizer.from_pretrained(model, task="text-generation")
quantizer.quantize(save_directory=save_dir, weights_only=True)
```

To load the optimized model for inference:

```python
optimized_model = OVModelForCausalLM.from_pretrained(save_dir)
```

Weights compression is enabled for PyTorch and OpenVINO models: the starting model can be an `AutoModelForCausalLM` or `OVModelForCausalLM` instance.

## Training-time optimization

Expand Down Expand Up @@ -221,4 +242,4 @@ text = "He's a dreadful magician."
outputs = cls_pipe(text)

[{'label': 'NEGATIVE', 'score': 0.9840195178985596}]
```
```