TensorFlow Serve (TFServe)
Deploying sample MNIST model with TensorFlow Serve
TensorFlow Serving is a flexible, high-performance serving system for machine learning models, designed for production environments. TensorFlow Serving makes it easy to deploy new algorithms and experiments, while keeping the same server architecture and APIs. TensorFlow Serving provides out-of-the-box integration with TensorFlow models, but can be easily extended to serve other types of models and data.
In this example, we will deploy a simple MNIST model using TensorFlow Serving. You can find the code for this example here.
Live Demo
You can view this example deployed here.
The key files are:
train.py
: Trains the model and exports it inSavedModel
format.batching.config
: Contains dynamic batching configuration.requirements.txt
: Contains the dependencies.
Usually the SavedModel
format checkpoint is self contained and can be deployed without writing any extra code.
Exporting the model in SavedModel format
Running the server locally
- Install the dependencies
- Run the server
- Test the server
The output should look like this:
Deploying the model with TrueFoundry
To deploy the model, we need to package both the model file and the code. To do this, we can follow the steps below:
Log the Model To Model Registry
Log the saved model to the registry. You can follow the guide here to log the model to the registry.
Make sure to log the parent directory containing the model version.
Push the code to a Git repository or directly deploy from local machine
Once you have tested your code locally, we highly recommend pushing the code a Git repository. This allows you to version control the code and also makes the deployment process much easier. However, if you don’t have access to a Git repository, or the Git repositories are not integrated with Truefoundry, you can directly deploy from local laptop.
You can follow the guide here to deploy your code.
Configure the source code and build settings as follows:
The command looks like this which references the MODEL_DIR
environment variable where the model will be downloaded to.
Download Model from Model Registry in the deployment configuration
TrueFoundry can automatically download the model at the path specified in the MODEL_DIR
environment variable to the deployed service.
Add the model id and revision from HuggingFace Hub in Artifacts Download
section
View the deployment, logs and metrics
Once the deployment goes through, you can view the deployment, the pods, logs, metrics and events to debug any issues.