The Hugging Face Hub is a vast repository, right now hosting 750K+ public models, offering a diverse range of pre-trained models for various machine learning frameworks. Among these, 346,268 (as of the time of writing) models are built using the popular Transformers library. The KerasHub library recently added an integration with the Hub compatible with a first batch of 33 models.
In this first version, people of KerasHub were limited to only the KerasHub-based models available on the Hugging Face Hub. (Related: YouTube ‘Co-Views’ try to guess how many people are wat...)
They were able to train/fine-tune the model and upload it back to the Hub (notice that the model is still a Keras model).
They were missing out on the extensive collection of over 300K models created with the transformers library. Figure 1 shows 4k Gemma models in the Hub. (Related: Intel Diamond Rapids shows signs of life in SC26 demo r...)
However, what if we told you that you can now access and use these 300K+ models with KerasHub, significantly expanding your model selection and capabilities?
Sources indicate that we're thrilled to announce a significant step forward for the Hub community: Transformers and KerasHub now have a shared model save format. This means that models of the transformers library on the Hugging Face Hub can now also be loaded directly into KerasHub - immediately making a huge range of fine-tuned models available to KerasHub users. Initially, this integration focuses on enabling the use of Gemma (1 and 2), Llama 3, and PaliGemma models, with prepares to expand compatibility to a wider range of architectures in the near future.
It has been revealed that because KerasHub models can seamlessly use TensorFlow, JAX, or PyTorch backends, this means that a huge range of model checkpoints can now be loaded into any of these frameworks in a single line of code. Found a great checkpoint on Hugging Face, but you wish you could deploy it to TFLite for serving or port it into JAX to do research? Now you can!
Using the integration requires updating your Keras versions.
Once updated, trying out the integration is as simple as:.
Sources indicate that transformers models are stored as a set of config files in JSON format, a tokenizer (usually also a .JSON file), and a set of safetensors weights files. The actual modeling code is contained in the Transformers library itself. This means that cross-loading a Transformers checkpoint into KerasHub is relatively straightforward as long as both libraries have modeling code for the relevant architecture. All we need to do is map config variables, weight names, and tokenizer vocabularies from one format to the other, and we create a KerasHub checkpoint from a Transformers checkpoint, or vice-versa.
All of this is handled internally for you, so you can focus on trying out the models rather than converting them!
Sources indicate that A first use case of language models is to generate text. Here is an example to load a transformers model and generate fresh tokens using the .generate method from KerasHub.
You can change the precision of your model using keras.config like so.
To test drive a model using JAX, you can leverage Keras to run the model with the JAX backend. This can be achieved by simply switching Keras's backend to JAX. Here’s how you can use the model within the JAX environment.
We are pleased to inform you that the Gemma 2 models are also compatible with this integration.
You can also use any PaliGemma safetensor checkpoint in your KerasHub pipeline.
This is just the beginning. We envision expanding this integration to encompass an even wider range of Hugging Face models and architectures. Stay tuned for updates and be sure to explore the incredible potential that this collaboration unlocks!
I would like to take this opportunity to thank Matthew Carrigan and Matthew Watson for their help in the entire process.
Reading through your blog on Announcing New Hugging Face and KerasHub Integration—such a well-explained guide, Aritra Roy Gosthipaty! The breakdown of how to use the integration and its common use cases was really helpful.
While researching, I found this resource on ComfyUI setup with RunPod, which covers Hugging Face model integration and AI model deployment: https://mobisoftinfotech.com/resources/blog/flux-on-runpod-using-comfyui.
I’d love to hear your thoughts on how this integration compares to other AI deployment methods!