Skip to content

Commit

Permalink
feat: fix batch handling in sagemaker for clip (#6216)
Browse files Browse the repository at this point in the history
Co-authored-by: Jina Dev Bot <dev-bot@jina.ai>
  • Loading branch information
zac-li and jina-bot authored Nov 4, 2024
1 parent 2f65ce1 commit 92d03f0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
6 changes: 2 additions & 4 deletions jina/orchestrate/flow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1776,10 +1776,8 @@ def build(self, copy_flow: bool = False, **kwargs) -> 'Flow':
op_flow._deployment_nodes[GATEWAY_NAME].args.graph_description = json.dumps(
op_flow._get_graph_representation()
)
op_flow._deployment_nodes[
GATEWAY_NAME
].args.deployments_addresses = json.dumps(
op_flow._get_deployments_addresses()
op_flow._deployment_nodes[GATEWAY_NAME].args.deployments_addresses = (
json.dumps(op_flow._get_deployments_addresses())
)

op_flow._deployment_nodes[GATEWAY_NAME].update_pod_args()
Expand Down
28 changes: 14 additions & 14 deletions jina/serve/executors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,21 +401,21 @@ def __init__(
self._init_monitoring()
self._init_workspace = workspace
if __dry_run_endpoint__ not in self.requests:
self.requests[
__dry_run_endpoint__
] = _FunctionWithSchema.get_function_with_schema(
self.__class__._dry_run_func
self.requests[__dry_run_endpoint__] = (
_FunctionWithSchema.get_function_with_schema(
self.__class__._dry_run_func
)
)
else:
self.logger.warning(
f' Endpoint {__dry_run_endpoint__} is defined by the Executor. Be aware that this endpoint is usually reserved to enable health checks from the Client through the gateway.'
f' So it is recommended not to expose this endpoint. '
)
if type(self) == BaseExecutor:
self.requests[
__default_endpoint__
] = _FunctionWithSchema.get_function_with_schema(
self.__class__._dry_run_func
self.requests[__default_endpoint__] = (
_FunctionWithSchema.get_function_with_schema(
self.__class__._dry_run_func
)
)

self._lock = contextlib.AsyncExitStack()
Expand Down Expand Up @@ -595,14 +595,14 @@ def _add_requests(self, _requests: Optional[Dict]):
_func = getattr(self.__class__, func)
if callable(_func):
# the target function is not decorated with `@requests` yet
self.requests[
endpoint
] = _FunctionWithSchema.get_function_with_schema(_func)
self.requests[endpoint] = (
_FunctionWithSchema.get_function_with_schema(_func)
)
elif typename(_func) == 'jina.executors.decorators.FunctionMapper':
# the target function is already decorated with `@requests`, need unwrap with `.fn`
self.requests[
endpoint
] = _FunctionWithSchema.get_function_with_schema(_func.fn)
self.requests[endpoint] = (
_FunctionWithSchema.get_function_with_schema(_func.fn)
)
else:
raise TypeError(
f'expect {typename(self)}.{func} to be a function, but receiving {typename(_func)}'
Expand Down
15 changes: 8 additions & 7 deletions jina/serve/runtimes/worker/http_csp_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,14 @@ def construct_model_from_line(
# Handle list of nested models
elif get_origin(field_type) is list:
list_item_type = get_args(field_type)[0]
parsed_list = json.loads(field_str)
if issubclass(list_item_type, BaseModel):
parsed_fields[field_name] = parse_obj_as(
List[list_item_type], parsed_list
)
else:
parsed_fields[field_name] = parsed_list
if field_str:
parsed_list = json.loads(field_str)
if issubclass(list_item_type, BaseModel):
parsed_fields[field_name] = parse_obj_as(
List[list_item_type], parsed_list
)
else:
parsed_fields[field_name] = parsed_list
# General parsing attempt for other types
else:
if field_str:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Optional, List

import numpy as np
from docarray import BaseDoc, DocList
Expand All @@ -13,6 +13,8 @@ class TextAndImageDoc(BaseDoc):
text: Optional[str] = None
url: Optional[AnyUrl] = None
bytes: Optional[ImageBytes] = None
num_tokens: Optional[int] = None
input_ids: Optional[List[int]] = None


class EmbeddingResponseModel(TextAndImageDoc):
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/docarray_v2/csp/valid_clip_input.csv

Large diffs are not rendered by default.

0 comments on commit 92d03f0

Please sign in to comment.