Deploying sample MNIST model with TorchServe
mnist.py
: The pytorch model definition.model/mnist_cnn.pt
: The trained pytorch model checkpoint.mnist_handler.py
: Contains the main handler that runs the inference.requirements.txt
: Contains the dependencies.config.properties
: Contains the configuration for the model server.handle
that takes in data
and context
as inputs and returns the inference output.
In this case we are inheriting from the ImageClassifier
class which is a default handler for image classification models. It already comes with the implementation for the entire pipeline. We just modify the postprocess
method to return the predicted class.
Please see TorchServe Custom Service docs for more details on how to write a custom handler.
.mar
file
mnist.mar
file.
Log the MAR Model To Model Registry
mnist.mar
file to the model registry. You can follow the guide here to log the model to the registry.mnist.mar
file.Push the code to a Git repository or directly deploy from local machine
MODEL_DIR
environment variable where the model will be downloaded to.Download Model from Model Registry in the deployment configuration
MODEL_DIR
environment variable to the deployed service.Add the model id and revision from HuggingFace Hub in Artifacts Download
sectionView the deployment, logs and metrics