Mnist serve
This is an example of a LitServe api for the Mnist LightningModule.
MNISTServeAPI
#
Bases: LitAPI
LitServe API for serving the MNIST model.
Source code in src/serve_apis/mnist_serve.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
__init__(model_class, checkpoint_path)
#
Initialize the MNISTServeAPI.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_class
|
LightningModule
|
The LightningModule class to serve. |
required |
checkpoint_path
|
str
|
The path to the model checkpoint. |
required |
Source code in src/serve_apis/mnist_serve.py
13 14 15 16 17 18 19 20 21 |
|
decode_request(request)
#
Decode the incoming request and prepare the input for the model.
Source code in src/serve_apis/mnist_serve.py
37 38 39 40 41 42 43 |
|
encode_response(output)
#
Encode the model's output into a response payload.
Source code in src/serve_apis/mnist_serve.py
53 54 55 56 |
|
predict(x)
#
Run inference using the MNIST model and return the prediction.
Source code in src/serve_apis/mnist_serve.py
45 46 47 48 49 50 51 |
|
setup(device)
#
Setup is called once at startup.
Load the model, set the device, and prepare any other necessary components.
Source code in src/serve_apis/mnist_serve.py
23 24 25 26 27 28 29 30 31 32 33 34 35 |
|