## Optimize machine learning models

```
import tensorflow as tf
import tensorflow_model_optimization as tfmot
import tf_keras as keras

model = keras.Sequential([...])

pruning_schedule = tfmot.sparsity.keras.PolynomialDecay(
                      initial_sparsity=0.0, final_sparsity=0.5,
                      begin_step=2000, end_step=4000)

model_for_pruning = tfmot.sparsity.keras.prune_low_magnitude(
    model, pruning_schedule=pruning_schedule)
...

model_for_pruning.fit(...)
```
The *TensorFlow Model Optimization Toolkit* is a suite of tools for optimizing ML models for deployment and execution. Among many uses, the toolkit supports techniques used to:

- Reduce latency and inference cost for cloud and edge devices (e.g. mobile, IoT).
- Deploy models to edge devices with restrictions on processing, memory, power-consumption, network usage, and model storage space.
- Enable execution on and optimize for existing hardware or new special purpose accelerators.


Choose the model and optimization tool depending on your task:

- [](http://www.tensorflow.org/model_optimization/guide/get_started.md.txt)

  #### [Improve performance with off-the-shelf models](http://www.tensorflow.org/model_optimization/guide/get_started.md.txt)

  In many cases, pre-optimized models can improve the efficiency of your application.
- [](http://www.tensorflow.org/model_optimization/guide/get_started.md.txt)

  #### [Use the TensorFlow Model Optimization Toolkit](http://www.tensorflow.org/model_optimization/guide/get_started.md.txt)

  Try the post-training tools to optimize an already-trained TensorFlow model.
- [](http://www.tensorflow.org/model_optimization/guide/optimize_further.md.txt)

  #### [Optimize further](http://www.tensorflow.org/model_optimization/guide/optimize_further.md.txt)

  Use training-time optimization tools and learn about the techniques.

### [Collaborative Optimization API](https://blog.tensorflow.org/2021/10/Collaborative-Optimizations.html)

[Read on TensorFlow blog](https://blog.tensorflow.org/2021/10/Collaborative-Optimizations.html)

### [Weight Clustering API](https://blog.tensorflow.org/2020/08/tensorflow-model-optimization-toolkit-weight-clustering-api.html)

[Read on TensorFlow blog](https://blog.tensorflow.org/2020/08/tensorflow-model-optimization-toolkit-weight-clustering-api.html)

### [Quantization Aware Training - Performance with Accuracy](https://blog.tensorflow.org/2020/04/quantization-aware-training-with-tensorflow-model-optimization-toolkit.html)

[Read on TensorFlow blog](https://blog.tensorflow.org/2020/04/quantization-aware-training-with-tensorflow-model-optimization-toolkit.html)

### [Post-Training Integer Quantization](https://blog.tensorflow.org/2019/06/tensorflow-integer-quantization.html)

[Read on TensorFlow blog](https://blog.tensorflow.org/2019/06/tensorflow-integer-quantization.html)

### [Pruning API](https://blog.tensorflow.org/2019/05/tf-model-optimization-toolkit-pruning-API.html)

[Read on TensorFlow blog](https://blog.tensorflow.org/2019/05/tf-model-optimization-toolkit-pruning-API.html)

### [Introducing the Model Optimization Toolkit for TensorFlow](https://blog.tensorflow.org/2018/09/introducing-model-optimization-toolkit.html)

[Read on TensorFlow blog](https://blog.tensorflow.org/2018/09/introducing-model-optimization-toolkit.html)

### [Model Optimization Toolkit on GitHub](https://github.com/tensorflow/model-optimization)

[View on GitHub](https://github.com/tensorflow/model-optimization)