Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom mira container #88

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/mira/sagemaker_custom_model/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM 763104351884.dkr.ecr.us-west-2.amazonaws.com/tensorflow-inference:1.14-cpu
COPY requirements.txt /home/requirements.txt
RUN pip install -r /home/requirements.txt
# ENV PATH="/opt/ml/code:${PATH}"
# # COPY ../models/mira-large/code /opt/ml/code
# # WORKDIR /opt/ml/code
# ENV SAGEMAKER_SUBMIT_DIRECTORY /opt/ml/code
# ENV SAGEMAKER_PROGRAM inference.py
24 changes: 24 additions & 0 deletions api/mira/sagemaker_custom_model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### Local Testing (in development, required to deploy custom container of MIRA on Sagemaker Serverless, an upgrade from Realtime endpoints use dby the above instructions)

Get the model and inference code for MIRA-Large
```
bash download_untar_model.sh
```

Build the custom docker container we need to use Sagemaker Serverless and for local testing. this installs pillow and numpy in the sagemaker container for TF 1.14.

```
docker build -t test/tf-1.14-pillow-nump:latest .
```

Start the model server with docker.

```
bash docker_mira.sh
```

Attempt to send a request following this example that base64 encodes https://www.tensorflow.org/tfx/serving/api_rest

```
python local_test.py
```
3 changes: 3 additions & 0 deletions api/mira/sagemaker_custom_model/docker_mira.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# dockerized version of the above, ran into dependency issue for termcolor
# https://github.com/pytorch/serve/tree/master/docker
docker run --rm -p 8080:8080 -p 8081:8081 -p 8082:8082 -p 8501:8501 -p 7070:7070 -p 7071:7071 -v "$(pwd)":/app -it test/tf-1.14-pillow-nump:latest bash /app/serve_mira.sh
2 changes: 2 additions & 0 deletions api/mira/sagemaker_custom_model/download_untar_model.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
aws s3 cp s3://sagemaker-us-west-2-830244800171/model-mira-large/model.tar.gz ./
tar -xvzf model.tar.gz
16 changes: 16 additions & 0 deletions api/mira/sagemaker_custom_model/local_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import base64
import requests
import json
API_URL = 'http://localhost:8501/v1/models/mira-large:classify'
IMG_PATH = '/home/rave/animl/animl-ml/input/sample-img-fox.jpg'
# Open and read image as bitstring
input_image = open(IMG_PATH, "rb").read()
print("Raw bitstring: " + str(input_image[:10]) + " ... " + str(input_image[-10:]))

# Encode image in b64
encoded_input_string = base64.b64encode(input_image)
input_string = encoded_input_string.decode("utf-8")
print("Base64 encoded string: " + input_string[:10] + " ... " + input_string[-10:])
predict_request = '{"instances" : [{"b64": "%s"}]}' % input_string
response = requests.post(API_URL, data=predict_request)
print(response.json())
2 changes: 2 additions & 0 deletions api/mira/sagemaker_custom_model/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pillow==8.3.2
numpy==1.18.2
1 change: 1 addition & 0 deletions api/mira/sagemaker_custom_model/serve_mira.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow_model_server --port=8500 --rest_api_port=8501 --model_name=mira-large --model_base_path=/app/export/Servo/