# @tf.function during inference?

**URL:** <https://discuss.ai.google.dev/t/tf-function-during-inference/28793>\
**Category:** General Discussion\
**Tags:** help\_request\
**Created:** [July 23, 2021, 1:30am UTC](https://discuss.ai.google.dev/t/tf-function-during-inference/28793 "2021-07-23T01:30:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bee](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bee/32/8331_2.png) [@bee](https://discuss.ai.google.dev/u/bee)\
**Post date:** [July 23, 2021, 1:30am UTC](https://discuss.ai.google.dev/t/tf-function-during-inference/28793/1 "2021-07-23T01:30:21Z")

</div>

Should @tf.function only be used during training, or should it also be used during inference?

The function I use during inference calls the model, sends the output to a softmax. and then calls argmax. Adding @tf.function to this function works well, but does it provide any benefits?

---

<div class="post-metadata">

**Author:** ![Sean\_Moriarity](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/sean_moriarity/32/8001_2.png) [@Sean\_Moriarity](https://discuss.ai.google.dev/u/Sean_Moriarity)\
**Post date:** [July 23, 2021, 2:03am UTC](https://discuss.ai.google.dev/t/tf-function-during-inference/28793/3 "2021-07-23T02:03:53Z")

</div>

`@tf.function` provides some nice performance benefits and I can’t think of any particular reason not to use it at inference unless your input shapes change often or for some reason your inference logic forces recompilation.

It’s a requirement to use `tf.function` to even export models to the SavedModel format, so I think it makes sense: [Лучшая производительность с tf.function &nbsp;|&nbsp; TensorFlow Core](https://www.tensorflow.org/guide/function)
