How to use Gradio for demo your machine learning model?
Introduction
This post will show you how to use Gradio for demo your machine learning model, whether it is a deep neural network, a random forest, or another algorithm that doesn’t require a distributed system. Using Gradio means you can just run your algorithm on a single machine, but with the same input and output as if it was running across multiple machines in parallel.
Gradio is a powerful open source machine learning framework that allows you to run any machine learning algorithm in parallel. You can create your own distributed training or prediction engine by using Gradio’s Python API and the Gradio CLI. Gradio is written in C++ but uses Python bindings to communicate with the engine. You can find more information about Artificial Intelligence here: Artificial Intelligence Training in Kochi
This post is not only to show how to use Gradio for demo your machine learning model, but also to introduce Gradio and its benefits.
A word about Gradio
Gradio was created by Hong Li-An, and it has been used in a couple of projects with great success. One of the projects is a translation tool which uses multiple machines and uses the usual translation back-end system such as Hadoop or HBase. This platform runs on Android devices with Google’s TensorFlow Deep Learning Library (TensorFlow DL) to extract translations from a corpus of videos uploaded by users. This engine can run on many different platforms including Linux, MacOS, and Windows.
Run model using Gradio
In this post, we will focus on how to adapt TensorFlow-DL as a proof-of-concept (PoC) without deep knowledge of Gradio and its usage. First, we must create a new engine by setting up the Gradio KVM template.
The following steps will help you run your model in parallel on multiple machines:
1. Run tfrb_train.sh with your data
2. Set up the Gradio Engine Start by opening a terminal, and running
gradio engine create –template ‘~/.kvm_template’ –name model_to_poC
Within this template directory, you can use python modules and setups to launch a process on different machines, different instances of Python, etc.
3. Run the model
After creating a new engine, run gradio engine list to see the engines you have created. You can now run your model on this new engine by
gradio model model_to_poC –train 10 –auto
where model_to_poC is the name of your model method and auto is an optional parameter.
It will execute your model in parallel on different machines according to the number of GPUs and CPUs available for each machine. After all the processes have finished, you will be given a tfrb_model.dat file, which you can use for other machine learning models.
Add gradient boosting on top of this model
After creating a new engine, run gradio engine list to see the engines you have created. You can now run your model on this new engine by gradio model model_to_poC –train 10 –auto –gboost 1 where model_to_poC is the name of your model method and auto is an optional parameter.
It will execute your model in parallel on different machines according to the number of GPUs and CPUs available for each machine. After all the processes have finished, you will be given a tfrb_model.dat file, which you can use for other machine learning models.
Gradio is written in C++ but it makes use of the Python bindings to communicate with the engine. In this scenario, using Python is unnecessary, and we are able to use CPU only nodes with just a switch in Gradio’s configuration file. For example, we can add another node to our model by adding “–node id:num_cpus –gpuid:1” in the command above (where num_cpus is the number of CPUs to use).
This is a powerful feature that allows you to run your models in parallel on a machine by running GPU-intensive ones with several GPUs, and CPU-intensive ones with multiple CPUs.
It is worth noting that the TensorFlow-DL model used in this example was a prototype, as it was not optimized for speed. However, it still ran faster on more machines than on one machine.
In conclusion, Gradio can be used to launch any kind of model without knowing how the engine works. It doesn’t matter whether you are using a deep neural network or another algorithm that needs to be distributed across multiple machines, you can just set up Gradio and run your model in parallel with just one command. If you want to learn more about Artificial Intelligence or Machine Learning, you can check out Best AI Training institute in Kochi.