Model Server for Apache MXNet adds support for serving Gluon models
Today AWS released Model Server for Apache MXNet (MMS) v0.4, which adds support for serving Gluon models. Gluon is an imperative and dynamic interface for MXNet, which enables rapid model development, while maintaining MXNet performance. With this release, MMS adds support for packaging and serving Gluon models at scale. In this blog post, we will describe the v0.4 release in detail and go over an example for serving a Gluon model.
What is Model Server for Apache MXNet (MMS)?
MMS is an open source model-serving framework, designed to simplify the task of serving deep learning models at scale. Here are some key advantages of MMS:
- Provides a packaging tool to generate a model archive containing the neural network model artifacts needed to serve MXNet, Gluon, and ONNX neural network models.
- Gives you the ability to customize every step in the inference execution pipeline using custom code packaged into the model archive, which enables overriding initialization, pre-processing, and post-processing.
- Comes with a preconfigured serving stack, including REST API endpoints, and an inference engine.
- Provides prebuilt and optimized container images for scalable model serving.
- Includes real-time operational metrics to monitor the server and its endpoints.
What is Gluon?
Gluon is a clear, concise, and simple Python interface to MXNet. It enables engineers to write imperative code to build neural networks, without losing the performance benefits of a symbolic implementation. Gluon is capable of automatically generating optimized symbolic code, based on imperative implementation.
Serving a Gluon model in MMS
Let’s go over an example of serving a Gluon model with MMS. In this example, we’ll use Gluon to implement a model based on Xiang Zhang’s Character-level Convolutional Neural Network (char-CNN). We’ll package the model and serve it with MMS. A char-CNN involves using CNN instead of a Recurrent Neural Network (RNN) to understand vocabulary and classify text. This enables classification, without the need to understand language semantics or syntax. When using this methodology, data errors such as spelling mistakes have a lesser impact on prediction performance.
Figure 1. Illustration of char-CNN model (source)
This image shows a basic char-CNN model structure. Words are transformed into a vocabulary tensor, then fed into the convolutional layers. The model is called the Crepe model. In the following GluonCrepe code, we use the Crepe model to predict a product category, based on text from a product review. The dataset the model is trained on is the Amazon product dataset. (For details on how the model is trained, please follow this detailed tutorial provided by Thomas Delteil.)
The model definition is as follows.
To run a model as a service on MMS, we require the following files:
- The custom service Python file – Defines the pre-process, inference, and post-process steps. It is also used to load pre-trained weights.
- The signature JSON file – Defines the expected input and output shapes of the model.
- The model file – This is a JSON file for regular MXNet model files. However, for Gluon models, they are class definitions placed within the service Python file.
- The parameters file – Stores the pre-trained weights of the model.
- The synset text file – Unique to classification models, this file contains the labels for the output classes.
Trained model weights are required to run inference on the model. Download the pre-trained weights. MMS uses custom service class derivations to define pre-process, inference, and post-process functionality. The custom services are specific to the model. For this example, Crepe model, we define the service as follows.
In the preprocess section the input text is truncated and encoded. The encoding is done based on 69 characters defined in the paper.
Next, we define the signature JSON file to inform MMS about the input and output shapes and their data types.
Both the inputs and outputs are text and are passed on in a JSON format. The input size of [1,1014] is a recommendation from the paper and the Amazon product dataset has seven output classes. The synset text file, stores the seven output classes of Amazon product dataset.
All these files can be packaged to a single archive, using the MMS export tool. A complete custom service file artifact is needed to build the archive. Install MMS and place the model artifacts in the same folder.
A pre-packaged model is available for download.
You can now serve the model, with following commands:
To get a prediction from the server, open a new terminal window and run the following command:
The output from the server will be as follows.
Let’s look at another example.
The response for this request follows.
Learn more and contribute
To learn more about MMS, start with our Single Shot Multi Object Detection (SSD) tutorial, which walks you through exporting and serving an SSD model. You can find more examples and documentation in the repository’s model zoo and documentation folder.
As we continue to develop MMS, we welcome community participation submitted as questions, requests, and contributions. If you are using MMS already, we welcome your feedback via the repository’s GitHub issues. Head over to awslabs/mxnet-model-server to get started!
Ups and downs: Modeling the visual evolution of fashion trends with one-class collaborative filtering
R. He, J. McAuley
About the Authors
Rakesh Vasudevan is a Software Development Engineer with AWS Deep Learning. He is passionate about building scalable deep learning systems. In spare time, he enjoys gaming, cricket and hanging out with friends and family.
Vamshidhar Dantu is a Software Developer with AWS Deep Learning. He focuses on building scalable and easily deployable deep learning systems. In his spare time, he enjoy spending time with family and playing badminton.
Hagay Lupesko is an Engineering Leader for AWS Deep Learning. He focuses on building deep learning systems that enable developers and scientists to build intelligent applications. In his spare time, he enjoys reading, hiking, and spending time with his family.