FastApp application/base image for deployable hyperpackage
Once a .hyperpack.zip
has been generated by running a training session in the CLI, our deploy
sub command should be
able to just create an image from a Dockerfile that looks something like this:
FROM mlsdk-fast-app:cpu-latest
WORKDIR /tmp
ADD mystudy.hyperpack.zip
RUN unzip ./mystudy.hyperpack.zip -d /hyperpackage
The application will expose POST /batch
, POST /predict
and GET /info
endpoints for each model in the hyperpackage.
Off the root /
will use whichever trained model has been identified as the best run in _study.json
, but if you would
like to access a specific trial, you can prefix them by their ID These are accessible by prefixing with a specific trial
ID (ie /2/predict
. /000002/predict
or /000002-unwieldy-trial/predict
will also work)
If using the test data provided, the /predict
endpoint expects a post request with a raw json body including an array
of 4 floats. This curl request:
curl --location --request POST 'http://localhost:8001/predict' \
--header 'Content-Type: application/json' \
--data-raw '[
20.03,
112.59,
52.31,
39.38
]'
Will produce this response
{
"prediction": "cardio trainer"
}
The /batch
endpoint expects an array of the input signature for /predict
and returns an array instead of a singular
value. For example this curl request:
curl --location --request POST 'http://localhost:8001/batch' \
--header 'Content-Type: application/json' \
--data-raw '[
[20.03, 112.59, 52.31, 39.38],
[20.03, 112.59, 52.31, 39.38]
]'
Will produce this response
{
"predictions": [
"cardio trainer",
"cardio trainer"
]
}
Each model also exposes a /info
route, which will return the trial.json, in case you wish to inspect the trial run
info
curl --location --request GET 'http://localhost:8001/info'
Responds with
{
"metrics": {
"train_score": 1,
"test_score": 0.8695652173913043
},
"metadata": {
"notes": "This model was generated with extreme care.",
"run_time": 0.17840003967285156
},
"hyperparameters": {
"foo": 1
},
"input_signature": "ndarray: float64 (4,)",
"output_signature": "ndarray: object_ [1]",
"created_at": "2021-12-17 23:25"
}
To see an example of a hyperpack schema/structure, please see examples/my_study.hyperpack