Publish your Keras fashions on Kaggle and Hugging Face – Uplaza

An replace from Kaggle

Kaggle Fashions opened a 12 months in the past and is already house to ~4,000 pre-trained fashions from a variety of organizations. And now, Kaggle Fashions is opening up for person contributions, with Keras mannequin uploads. For those who fine-tuned a mannequin that you just wish to share with the world, right here is the way it works:

import keras
import keras_nlp

# Load the mannequin
gemma = keras_nlp.fashions.CausalLM.from_preset("gemma_1.1_instruct_7b_en")

# High quality tune the mannequin right here. Instance: Gemma fine-tuned to
# communicate like a pirate. See bit.ly/gemma-pirate-demo
# ...

# Save the finetuned mannequin as a KerasNLP preset.
gemma.save_to_preset("./gemma-pirate-instruct-7b")

# Add the preset as a brand new mannequin variant on Kaggle
kaggle_uri = "kaggle://my_kaggle_username/gemma-pirate/keras/gemma-pirate-instruct-7b"
keras_nlp.upload_preset(kaggle_uri, "./gemma-pirate-instruct-7b")

Folks will have the ability to load your mannequin utilizing the very same .from_preset(url) name as if loading the unique Gemma, so long as they level the URL at your customized fine-tuned model.

gemma = keras_nlp.fashions.CausalLM.from_preset("kaggle://my_kaggle_username/gemma-pirate/keras/gemma-pirate-instruct-7b")

To make the invention of user-uploaded fashions simpler, Kaggle offers mannequin pages for them, the place you possibly can add an outline, particulars concerning the dataset used for fine-tuning and so on. This web page can be the place you go to make your uploaded mannequin public (“Settings” tab within the screenshot beneath).

A pleasant contact right here from the Kaggle crew is the usability score. It helps you see which mannequin particulars are lacking to your mannequin to be seen and appreciated by the group.


Why Keras?

You should have seen that the mannequin.save_to_preset() and keras_nlp.upload_preset() calls are constructed proper into Keras to make importing handy. Whereas it’s attainable to add fashions in any format, offered you publish directions for loading them, Kaggle has chosen Keras as the popular mannequin format due to the constant person expertise offered by Keras for pre-trained fashions:

  • all fashions load via the identical .from_preset() API
  • fashions have a well-recognized Keras API as soon as loaded (mannequin.match() for fine-tuning, and so on)
  • mannequin supply code is all the time in kerasCV or kerasNLP
  • clear and readable Keras implementations
  • and with Keras 3, all fashions work on JAX, TensorFlow and PyTorch

However it’s all the time necessary to examine our assumptions. The launch of the Gemma fashions, the newest open Giant Language Fashions (LLM) from Google, was an ideal take a look at. It was launched in at least 9 codecs (!) and the Kaggle obtain information are in: there are greater than 2x extra downloads in keras than in all different codecs mixed.

Gemma downloads on Kaggle, by framework. Be aware 1: the keras model runs on JAX, PyTorch, and Tensorflow. The “pytorch” rely is for a pure pytorch model. Be aware 2: The “transformers” rely represents downloads of the HF transformers model of Gemma from Kaggle, not from Hugging Face.

Kaggle has run two Gemma competitions and the KerasNLP starter notebooks for them have been copied greater than 950 instances between them (our inside benchmark is: >500 copies= “wow, Kagglers found it useful”, >1000 copies=”superb”):

And Kagglers are performing some fairly superb issues with these fashions. Here’s a choice:

Offering a pocket book was once the one manner on Kaggle to share a modified mannequin with the group. However with fine-tuning taking hours, it’s a lot better to have the ability to share the ultimate consequence straight, as a Kaggle Mannequin.


However wait, there’s extra: Hugging Face!

With this launch, KerasNLP additionally turns into a first-class citizen on Hugging Face. Keras fashions could be loaded straight from Hugging Face utilizing KerasNLP, which is now one of many supported pre-trained mannequin libraries on Hugging Face, in the identical manner as Transformers or Diffusers. Right here is the Gemma Keras web page on Hugging Face for instance. You may load the mannequin with:

# Load the mannequin
gemma = keras_nlp.fashions.CausalLM.from_preset("hf://google/gemma-7b-instruct-keras")

And right here is the way you add your mannequin to Hugging Face. The one factor that modifications in comparison with Kaggle uploads is the “hf://” as a substitute of “kaggle://” within the URL.

# High quality-tune mannequin
# ...
# Then reserve it as a KerasNLP preset.
gemma.save_to_preset('./gemma-pirate-instruct-7b)


# Add the preset to Hugging Face Hub
hf_uri = "hf://my_hf_username/gemma-pirate-instruct-7b"
keras_nlp.upload_preset(hf_uri, './gemma-pirate-instruct-7b)

Right here is the consequence, a pre-populated mannequin card on Hugging Face. You may add extra data there and make your mannequin public via the “settings” tab.:

Discover how the mannequin was mechanically acknowledged on Hugging Face and auto-tagged with “KerasNLP” and “Text Generation”.


Your flip to play on Kaggle or Hugging Face

It’s your flip to play. Completely satisfied mannequin importing!

To check out the mannequin add code straight, attempt the Gemma 7B pirate add to Kaggle and Hugging Face.

Discover the official documentation for this characteristic right here.

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version