1.8 KiB
Train and Deploy Scikit-Learn model
training mock model
Run the mock python training code
python3 train_model.py
The output will be a model created on the project "serving examples", by the name "train sklearn model"
setting up the serving service
-
Create serving Service:
clearml-serving create --name "serving example"
(write down the service ID) -
Create model endpoint:
clearml-serving --id <service_id> model add --engine sklearn --endpoint "test_model_sklearn" --preprocess "preprocess.py" --name "train sklearn model" --project "serving examples"
Or auto updateclearml-serving --id <service_id> model auto-update --engine sklearn --endpoint "test_model_sklearn_auto" --preprocess "preprocess.py" --name "train sklearn model" --project "serving examples" --max-versions 2
Or add Canary endpointclearml-serving --id <service_id> model canary --endpoint "test_model_sklearn_auto" --weights 0.1 0.9 --input-endpoint-prefix test_model_sklearn_auto
-
Run the clearml-serving container
docker run -v ~/clearml.conf:/root/clearml.conf -p 8080:8080 -e CLEARML_SERVING_TASK_ID=<service_id> clearml-serving:latest
-
Test new endpoint:
curl -X POST "http://127.0.0.1:8080/serve/test_model_sklearn" -H "accept: application/json" -H "Content-Type: application/json" -d '{"x0": 1, "x1": 2}'
Notice: You can also change the serving service while it is already running! This includes adding/removing endpoints, adding canary model routing etc.
Running / debugging the serving service manually
Once you have setup the Serving Service Task
$ pip3 install -r clearml_serving/serving/requirements.txt
$ CLEARML_SERVING_TASK_ID=<service_id> PYHTONPATH=$(pwd) python3 -m gunicorn \
--preload clearml_serving.serving.main:app \
--workers 4 \
--worker-class uvicorn.workers.UvicornWorker \
--bind 0.0.0.0:8080