Skip to content

Commit

Permalink
feat(sagemaker): support batch-transform
Browse files Browse the repository at this point in the history
  • Loading branch information
deepankarm committed Sep 26, 2023
1 parent f51950a commit a7faa6f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/integration/docarray_v2/sagemaker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM jinaai/jina:test-pip

COPY . /executor_root/

WORKDIR /executor_root/SampleExecutor

ENTRYPOINT ["jina", "executor", "--uses", "config.yml"]
39 changes: 39 additions & 0 deletions tests/integration/docarray_v2/sagemaker/test_sagemaker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import time
from contextlib import AbstractContextManager

import pytest
Expand All @@ -8,6 +9,21 @@
from jina.orchestrate.pods import Pod
from jina.parsers import set_pod_parser

cur_dir = os.path.dirname(os.path.abspath(__file__))


@pytest.fixture
def replica_docker_image_built():
import docker

client = docker.from_env()
client.images.build(path=cur_dir, tag='sampler-executor')
client.close()
yield
time.sleep(2)
client = docker.from_env()
client.containers.prune()


class chdir(AbstractContextManager):
def __init__(self, path):
Expand Down Expand Up @@ -153,6 +169,29 @@ def test_provider_sagemaker_deployment_inference():
assert len(resp_json['data'][0]['embeddings'][0]) == 64


def test_provider_sagemaker_deployment_inference_docker(replica_docker_image_built):
with Deployment(uses='docker://sampler-executor', provider='sagemaker', port=12345):
# Test the `GET /ping` endpoint (added by jina for sagemaker)
rsp = requests.get('http://localhost:12345/ping')
assert rsp.status_code == 200
assert rsp.json() == {}

# Test the `POST /invocations` endpoint
# Note: this endpoint is not implemented in the sample executor
rsp = requests.post(
'http://localhost:12345/invocations',
json={
'data': [
{'text': 'hello world'},
]
},
)
assert rsp.status_code == 200
resp_json = rsp.json()
assert len(resp_json['data']) == 1
assert len(resp_json['data'][0]['embeddings'][0]) == 64


@pytest.mark.skip('Sagemaker with Deployment for batch-transform is not supported yet')
def test_provider_sagemaker_deployment_batch():
with chdir(os.path.join(os.path.dirname(__file__), 'SampleExecutor')):
Expand Down

0 comments on commit a7faa6f

Please sign in to comment.