question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TF] Save finetuned-model without huggingface-hub login

See original GitHub issue

Feature request

[TF] Save finetuned-model in local without huggingface-hub login

Motivation

in TF, We need to login for saving finetuned-model.

from transformers.keras_callbacks import PushToHubCallback

push_to_hub_callback = PushToHubCallback(
    output_dir="my_awesome_model",
    tokenizer=tokenizer,
)

But I don’t want to sync in my hub yet. Firstly, I want to save my models in local and test them

I checked that works in PyTorch, But It’s not in Tensorflow

Your contribution

I think we need to add argument whether to login or not

https://github.com/huggingface/transformers/blob/0526a075c567d7508205fe6054310f3d132b3227/src/transformers/keras_callbacks.py#L267

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
goreng2commented, Dec 16, 2022

Hi @Rocketknight1 ! Thanks for your comment.

I want to use Huggingface’s pipeline API for inference. I think pipeline perhaps can receive only .h5 model

When I tried ModelCheckpoint callback, It returns ckpt files. It can’t be used in pipeline. For convert ckpt to .h5, I need to write model architecture (in my case ELECTRA) But It’s so difficult and complex to me 😥 I tried to convert ckpt to pth (PyTorch) But It doesn’t work… Maybe this code only works in converting TF1 to PyTorch

When I tried model.save('my_model.h5'), Error msg raised. Maybe Something format is not match

I don’t test model.save_pretrained() yet, It returns .h5?

0reactions
Rocketknight1commented, Dec 16, 2022

Ah, yes. The .ckpt files from ModelCheckpoint are only useful for saving/resuming training, and you won’t be able to use them in pipelines.

The way TF models on HuggingFace work is that they’re built on top of Keras models. model.save() and ModelCheckpoint are both part of Keras. However, if you want to save the model to load with other HuggingFace tools, you should use save_pretrained(). This is our method and doesn’t exist in base Keras models. It saves the model as .h5, but also adds a config.json that will allow the pipeline API and other methods like from_pretrained to initialize the model correctly.

Try just doing this:

model.save_pretrained("my_model")
pipe = pipeline("text-classification", model="my_model")

Though of course, make sure to change text-classification to the task you want to do!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Model sharing and uploading - Hugging Face
Uploading your files. Once the repo is cloned, you can add the model, configuration and tokenizer files. For instance, saving the model and...
Read more >
huggingface transformers - saving finetuned model locally
I want to save the model locally, and then later be able to load it from my own computer into future task so...
Read more >
I Fine-Tuned GPT-2 on 100K Scientific Papers
I started by loading the dataset from the Huggingface Hub. ... At this point, I set up a callback to the Huggingface Hub...
Read more >
Untitled
Feature request [TF] Save finetuned-model in local without huggingface-hub login ... or any dir you want to save logs # training train_result =...
Read more >
François Chollet on Twitter: "Exciting -- you can now push any ...
Exciting -- you can now push any Keras model to the HuggingFace Hub in just a couple of lines of code. Quote Tweet....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found