# Upload a TF model to Huggingface

**URL:** <https://discuss.huggingface.co/t/upload-a-tf-model-to-huggingface/9662>\
**Category:** Intermediate\
**Created:** [September 1, 2021, 11:10am UTC](https://discuss.huggingface.co/t/upload-a-tf-model-to-huggingface/9662 "2021-09-01T11:10:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kamel](https://avatars.discourse-cdn.com/v4/letter/k/838e76/32.png) [@Kamel](https://discuss.huggingface.co/u/Kamel)\
**Post date:** [September 1, 2021, 11:10am UTC](https://discuss.huggingface.co/t/upload-a-tf-model-to-huggingface/9662/1 "2021-09-01T11:10:03Z")

</div>

Hi,  
I am pre-training a Bert model from scratch using Tensorflow.  
I’ve seen the methid to push pyTorch models, but I don’t know how to do with my TF model.

Here is how I imagine I have to do:  
1- Convert my checkpoint from Tf to torch  
2- Push to HF

Is this correct?

But an other question is :  
I don’t know how to push the tokenizer, all I am having is:

- my vocab.txt
- tokenizer.vocab  
-tokenizer.model

how can I do this please.

Thanks

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [September 1, 2021, 1:14pm UTC](https://discuss.huggingface.co/t/upload-a-tf-model-to-huggingface/9662/2 "2021-09-01T13:14:58Z")

</div>

If you pre-trained BERT from scratch in TF using the [`run_mlm.py` script](https://github.com/huggingface/transformers/tree/master/examples/tensorflow/language-modeling), you can easily convert the model from TF to PyTorch, like so:

```auto
from transformers import BertForMaskedLM

model = BertForMaskedLM.from_pretrained("name of directory where the run_mlm.py script saved all files", from_tf=True)
model.save_pretrained("name of directory where you'd like to save all model files")

```

Next, you can easily push it to the hub as follows (I’m assuming you’re in a Colab notebook):

First, install git-LFS:

```auto
!sudo apt-get install git-lfs
!git config --global user.email "<your email>"
!git config --global user.name "<your name>"

```

Next, create a repo on the [hub](https://huggingface.co/), then git clone it:

```auto
git clone <URL of your repository on the hub>

```

Next, add your files and upload them:

```auto
git add .
git commit -m "First commit"
git push

```

---

<div class="post-metadata">

**Author:** ![Kamel](https://avatars.discourse-cdn.com/v4/letter/k/838e76/32.png) [@Kamel](https://discuss.huggingface.co/u/Kamel)\
**Post date:** [September 1, 2021, 1:35pm UTC](https://discuss.huggingface.co/t/upload-a-tf-model-to-huggingface/9662/3 "2021-09-01T13:35:29Z")

</div>

Thanks a lot.  
Is this enough even for the tokenizer. I heard I have also provide the tokenizer with the model.

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [September 1, 2021, 1:38pm UTC](https://discuss.huggingface.co/t/upload-a-tf-model-to-huggingface/9662/4 "2021-09-01T13:38:30Z")

</div>

Yes you should also include the tokenizer files. As these are framework-independent, you can use the ones that were saved from the `run_mlm`.py script.

---

<div class="post-metadata">

**Author:** ![Kamel](https://avatars.discourse-cdn.com/v4/letter/k/838e76/32.png) [@Kamel](https://discuss.huggingface.co/u/Kamel)\
**Post date:** [September 1, 2021, 1:41pm UTC](https://discuss.huggingface.co/t/upload-a-tf-model-to-huggingface/9662/5 "2021-09-01T13:41:42Z")

</div>

Thanks, one more question about it:  
How can pytorch users use my tokenizer with AutoTokenizer?  
Providing my vocab.txt is it enough or tokenizer.model is the one they need.

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [September 1, 2021, 1:42pm UTC](https://discuss.huggingface.co/t/upload-a-tf-model-to-huggingface/9662/6 "2021-09-01T13:42:37Z")

</div>

Not sure what tokenizer.model is, normally the `vocab.txt` is enough.

---

<div class="post-metadata">

**Author:** ![Kamel](https://avatars.discourse-cdn.com/v4/letter/k/838e76/32.png) [@Kamel](https://discuss.huggingface.co/u/Kamel)\
**Post date:** [September 1, 2021, 1:43pm UTC](https://discuss.huggingface.co/t/upload-a-tf-model-to-huggingface/9662/7 "2021-09-01T13:43:08Z")

</div>

Thanks a lot for you complete answer Nielsr
