# How to quantize a custom model(not of tf.keras.Model type)?

**URL:** <https://discuss.ai.google.dev/t/how-to-quantize-a-custom-model-not-of-tf-keras-model-type/26391>\
**Category:** General Discussion\
**Tags:** keras, models, help\_request\
**Created:** [May 11, 2022, 2:12am UTC](https://discuss.ai.google.dev/t/how-to-quantize-a-custom-model-not-of-tf-keras-model-type/26391 "2022-05-11T02:12:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felicity\_Wang](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/felicity_wang/32/10663_2.png) [@Felicity\_Wang](https://discuss.ai.google.dev/u/Felicity_Wang)\
**Post date:** [May 11, 2022, 2:12am UTC](https://discuss.ai.google.dev/t/how-to-quantize-a-custom-model-not-of-tf-keras-model-type/26391/1 "2022-05-11T02:12:39Z")

</div>

Hi,  
I’m trying to perform quantization-aware training on a customized model that’s not of `tf.keras.Model` type. It’s got its own `forward()`, `loss()`, and `trainable_variables()` functions for the optimizer to apply gradients on. Has anyone had any experience running quantization aware training in such a scenario?

Thank you.

---

<div class="post-metadata">

**Author:** ![Kiran\_Sai\_Ramineni](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/kiran_sai_ramineni/32/8859_2.png) [@Kiran\_Sai\_Ramineni](https://discuss.ai.google.dev/u/Kiran_Sai_Ramineni)\
**Post date:** [March 6, 2023, 5:08pm UTC](https://discuss.ai.google.dev/t/how-to-quantize-a-custom-model-not-of-tf-keras-model-type/26391/3 "2023-03-06T17:08:02Z")

</div>

Hi @Felicity_Wang, To perform QAT on custom layers you have to apply [`tfmot.quantization.keras.quantize_annotate_layer`](https://www.tensorflow.org/model_optimization/api_docs/python/tfmot/quantization/keras/quantize_annotate_layer) to the `CustomLayer` and pass in the `QuantizeConfig`. For more details please refer to this [document](https://www.tensorflow.org/model_optimization/guide/quantization/training_comprehensive_guide#quantize_custom_keras_layer). Thank You.
