# Tensorflow TPUStrategy and model.generate: Does it work?

**URL:** <https://discuss.huggingface.co/t/tensorflow-tpustrategy-and-model-generate-does-it-work/6061>\
**Category:** 🤗Transformers\
**Created:** [May 7, 2021, 2:57pm UTC](https://discuss.huggingface.co/t/tensorflow-tpustrategy-and-model-generate-does-it-work/6061 "2021-05-07T14:57:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JulesGM](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/julesgm/32/14283_2.png) [@JulesGM](https://discuss.huggingface.co/u/JulesGM)\
**Post date:** [May 7, 2021, 2:57pm UTC](https://discuss.huggingface.co/t/tensorflow-tpustrategy-and-model-generate-does-it-work/6061/1 "2021-05-07T14:57:25Z")

</div>

Hello folks,

I’m trying to get GPT-2 in Tensorflow 2.x to generate on TPUs using `tf.distribute.TPUStrategy`. This requires compiling the functions with `tf.function`, but I haven’t had any luck getting `tf.function` to work on a `TFGPT2LMHeadModel`.

Has anyone tried this, and / or had any luck?  
Thanks.
