Skip to content

Commit

Permalink
feat: switch all object detection models to Triton (#622)
Browse files Browse the repository at this point in the history
- switch to Triton, use gRPC protocol for faster transfer
- only request needed output fields (resolves #942)
- get rid of CategoryIndex and protobuf-generated files
  • Loading branch information
raphael0202 committed Nov 8, 2022
1 parent 58ae4a9 commit 3c786c4
Show file tree
Hide file tree
Showing 17 changed files with 426 additions and 2,089 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_EXPOSE=127.0.0.1:5432

# Triton ML inference server
TRITON_HOST=triton

# InfluxDB
INFLUXDB_HOST=
INFLUXDB_PORT=8086
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/container-deploy-ml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- master
- tf-serving-deploy-*
- ml-deploy-*
# only update on push if ml.yml changed (does not apply to tags)
paths:
- docker/ml.yml
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/container-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ jobs:
echo "OFF_PASSWORD=${{ secrets.OFF_PASSWORD }}" >> .env
echo "SENTRY_DSN=${{ secrets.SENTRY_DSN }}" >> .env
echo "ELASTICSEARCH_HOSTS=elasticsearch" >> .env
# TODO remove when triton is deployed, and category model is retrained for triton
echo "TF_SERVING_HOST=${{ secrets.TF_SERVING_HOST }}" >> .env
echo "TRITON_HOST=${{ secrets.TRITON_HOST }}" >> .env
echo "INFLUXDB_HOST=${{ secrets.INFLUXDB_HOST }}" >> .env
echo "INFLUXDB_PORT=8086" >> .env
echo "INFLUXDB_DB_NAME=${{ matrix.env == 'robotoff-org' && 'off_metrics' || 'off_net_metrics' }}" >> .env
Expand Down
29 changes: 13 additions & 16 deletions .github/workflows/models-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
name: Sync Tensorflow models to Proxmox VM
on:
name: Sync ML models to Proxmox VM
on:
push:
branches:
- master
- deploy-*
tags:
tags:
- v*.*.*
- model-deploy*
jobs:
tfmodels-sync:
name: Sync TF models
ml-models-sync:
name: Sync ML models
runs-on: ubuntu-latest
environment: ${{ matrix.env }}
concurrency: ${{ matrix.env }}-${{ matrix.asset_name }}
Expand All @@ -35,17 +33,17 @@ jobs:
proxy_username: ${{ secrets.USERNAME }}
proxy_key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd ${{ matrix.env }}/tf_models
cd ${{ matrix.env }}/models
dir=`echo ${{ matrix.asset_name }} | sed 's/tf-//g'`
mkdir -p ${dir} ${dir}/1
wget -cO - /~https://github.com/openfoodfacts/robotoff-models/releases/download/${{ matrix.asset_name }}-1.0/label_map.pbtxt > ${dir}/labels.pbtxt
wget -cO - /~https://github.com/openfoodfacts/robotoff-models/releases/download/${{ matrix.asset_name }}-1.0/saved_model.tar.gz > ${dir}/1/saved_model.tar.gz
cd ${dir}/1
tar -xzvf saved_model.tar.gz --strip-component=1
rm saved_model.tar.gz
wget -cO - /~https://github.com/openfoodfacts/robotoff-models/releases/download/${{ matrix.asset_name }}-1.0/labels.txt > ${dir}/labels.txt
if [ ${{ matrix.env }} = 'robotoff-ml' ]; then
wget -cO - /~https://github.com/openfoodfacts/robotoff-models/releases/download/${{ matrix.asset_name }}-1.0/model.onnx > ${dir}/1/model.onnx
fi
# The category classifier has the pre- and post-processing built in, therefore
# it requires a slightly different sequence of steps to the 'tfmodels-sync' above.
# it requires a slightly different sequence of steps to the 'ml-models-sync' above.
tfmodels-category-classifier-sync:
name: Sync Category Classifier
runs-on: ubuntu-latest
Expand Down Expand Up @@ -76,4 +74,3 @@ jobs:
cd ${dir}/1
tar -xzvf saved_model.tar.gz --strip-component=1
rm saved_model.tar.gz
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ x-robotoff-base-env: &robotoff-base-env
SENTRY_DSN:
ELASTICSEARCH_HOSTS:
TF_SERVING_HOST:
TRITON_HOST:


services:
api:
Expand Down
20 changes: 20 additions & 0 deletions docker/ml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,25 @@ services:
networks:
- webnet

triton:
restart: $RESTART_POLICY
# This is a custom built of Triton with:
# - GRPC/HTTP support
# - CPU only (we don't have GPU in production)
# - Tensorflow 2 SavedModel and ONNX support
# This allows us to reduce significantly the image size
# See https://gist.github.com/raphael0202/091e521f2c79a8db8c6e9aceafb6e0b9 for build script
image: ghcr.io/openfoodfacts/triton:latest
ports:
- ${TRITON_EXPOSE_HTTP:-8000}:8000
- ${TRITON_EXPOSE_GRPC:-8001}:8001
- ${TRITON_EXPOSE_METRICS:-8002}:8002
volumes:
- ./models:/models
entrypoint: "tritonserver --model-repository=/models"
mem_limit: 10g
networks:
- webnet

networks:
webnet:
Loading

0 comments on commit 3c786c4

Please sign in to comment.