clearml-serving/examples/keras/readme.md

43 lines
2.5 KiB
Markdown
Raw Normal View History

# Train and Deploy Keras model with Nvidia Triton Engine
2022-03-06 00:05:52 +00:00
## training mnist digit classifier model
Run the mock python training code
```bash
2022-03-06 00:05:52 +00:00
pip install -r examples/keras/requirements.txt
python examples/keras/train_keras_mnist.py
```
The output will be a model created on the project "serving examples", by the name "train keras model"
## setting up the serving service
2022-03-20 23:00:19 +00:00
Prerequisites, Keras/Tensorflow models require Triton engine support, please use `docker-compose-triton.yml` / `docker-compose-triton-gpu.yml` or if running on Kubernetes, the matching helm chart.
1. Create serving Service: `clearml-serving create --name "serving example"` (write down the service ID)
2. Create model endpoint:
2022-03-06 00:14:33 +00:00
2023-04-12 22:02:27 +00:00
`clearml-serving --id <service_id> model add --engine triton --endpoint "test_model_keras" --preprocess "examples/keras/preprocess.py" --name "train keras model - serving_model" --project "serving examples" --input-size 1 784 --input-name "dense_input" --input-type float32 --output-size -1 10 --output-name "activation_2" --output-type float32
`
2022-03-06 00:14:33 +00:00
Or auto update
2022-03-06 00:14:33 +00:00
2023-04-12 22:02:27 +00:00
`clearml-serving --id <service_id> model auto-update --engine triton --endpoint "test_model_auto" --preprocess "examples/keras/preprocess.py" --name "train keras model - serving_model" --project "serving examples" --max-versions 2
--input-size 1 784 --input-name "dense_input" --input-type float32
2022-03-06 00:14:33 +00:00
--output-size -1 10 --output-name "activation_2" --output-type float32`
Or add Canary endpoint
2022-03-06 00:14:33 +00:00
`clearml-serving --id <service_id> model canary --endpoint "test_model_auto" --weights 0.1 0.9 --input-endpoint-prefix test_model_auto`
2022-03-21 15:54:57 +00:00
3. Make sure you have the `clearml-serving` `docker-compose-triton.yml` (or `docker-compose-triton-gpu.yml`) running, it might take it a minute or two to sync with the new endpoint.
2022-10-07 23:12:18 +00:00
4. Test new endpoint (do notice the first call will trigger the model pulling, so it might take longer, from here on, it's all in memory): \
2024-02-27 07:43:47 +00:00
`curl -X POST "http://127.0.0.1:8080/serve/test_model_keras" -H "accept: application/json" -H "Content-Type: application/json" -d '{"url": "https://raw.githubusercontent.com/allegroai/clearml-serving/main/examples/pytorch/5.jpg"}'`
2022-10-07 23:12:18 +00:00
\
or send a local file to be classified with \
`curl -X POST "http://127.0.0.1:8080/serve/test_model_keras" -H "Content-Type: image/jpeg" --data-binary "@5.jpg"`
> **_Notice:_** You can also change the serving service while it is already running!
This includes adding/removing endpoints, adding canary model routing etc.
2022-03-20 23:00:19 +00:00
by default new endpoints/models will be automatically updated after 1 minute