Skip to content

Commit

Permalink
feat(ray): support protobuf struct for input/output
Browse files Browse the repository at this point in the history
  • Loading branch information
heiruwu committed Jul 18, 2024
1 parent 89a2ca5 commit 548e784
Show file tree
Hide file tree
Showing 10 changed files with 1,070 additions and 1,299 deletions.
39 changes: 25 additions & 14 deletions instill/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
from instill.helpers.protobufs.parse import (
Metadata,
construct_image_to_image_infer_response,
construct_image_to_image_metadata_response,
construct_infer_response,
construct_metadata_response,
construct_text_generation_chat_infer_response,
construct_text_generation_chat_metadata_response,
construct_text_generation_infer_response,
construct_text_generation_metadata_response,
construct_text_to_image_infer_response,
construct_text_to_image_metadata_response,
construct_visual_question_answering_infer_response,
construct_visual_question_answering_metadata_response,
# pylint: disable=no-name-in-module
from instill.helpers.protobufs.ray_pb2 import TriggerRequest, TriggerResponse
from instill.helpers.ray_io import (
construct_task_classification_output,
construct_task_detection_output,
construct_task_image_to_image_output,
construct_task_instance_segmentation_output,
construct_task_keypoint_output,
construct_task_ocr_output,
construct_task_semantic_segmentation_output,
construct_task_text_generation_chat_output,
construct_task_text_generation_output,
construct_task_text_to_image_output,
construct_task_visual_question_answering_output,
parse_task_classification_to_vision_input,
parse_task_detection_to_vision_input,
parse_task_image_to_image_input,
parse_task_instance_segmentation_to_vision_input,
parse_task_keypoint_to_vision_input,
parse_task_ocr_to_vision_input,
parse_task_semantic_segmentation_to_vision_input,
parse_task_text_generation_chat_to_conversation_input,
parse_task_text_generation_to_conversation_input,
parse_task_text_to_image_input,
parse_task_visual_question_answering_to_conversation_multimodal_input,
)
60 changes: 24 additions & 36 deletions instill/helpers/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import numpy as np

PROMPT_ROLES = ["user", "assistant", "system"]


class DataType(Enum):
TYPE_BOOL = 1
Expand All @@ -21,63 +23,49 @@ class DataType(Enum):
TYPE_STRING = 13


class TextGenerationInput:
prompt = ""
class VisionInput:
image: np.ndarray


class ConversationInput:
conversation: List[Dict[str, str]]
max_new_tokens = 100
temperature = 0.8
top_k = 1
seed = 0
stop_words: Any = "" # Optional
extra_params: Dict[str, str] = {}


class ConversationMultiModelInput:
conversation: List[Union[Dict[str, Union[str, Dict[str, str]]]]]
prompt_images: Union[List[np.ndarray], None] = None
chat_history: Union[List[str], None] = None
system_message: Union[str, None] = None
max_new_tokens = 100
temperature = 0.8
top_k = 1
random_seed = 0
seed = 0
stop_words: Any = "" # Optional
extra_params: Dict[str, str] = {}


class TextToImageInput:
prompt_image: Union[np.ndarray, None] = None
prompt = ""
negative_prompt = ""
steps = 5
guidance_scale = 7.5
cfg_scale = 7.5
seed = 0
samples = 1
extra_params: Dict[str, str] = {}


class ImageToImageInput:
prompt_image: Union[np.ndarray, None] = None
prompt = ""
prompt_image: Union[np.ndarray, None] = None
steps = 5
guidance_scale = 7.5
cfg_scale = 7.5
seed = 0
samples = 1
extra_params: Dict[str, str] = {}


class TextGenerationChatInput:
prompt = ""
prompt_images: Union[List[np.ndarray], None] = None
chat_history: Union[List[str], None] = None
system_message: Union[str, None] = None
max_new_tokens = 100
temperature = 0.8
top_k = 1
random_seed = 0
stop_words: Any = "" # Optional
extra_params: Dict[str, str] = {}


class VisualQuestionAnsweringInput:
prompt = ""
prompt_images: Union[List[np.ndarray], None] = None
chat_history: Union[List[str], None] = None
system_message: Union[str, None] = None
max_new_tokens = 100
temperature = 0.8
top_k = 1
random_seed = 0
stop_words: Any = "" # Optional
low_threshold = 100
high_threshold = 200
extra_params: Dict[str, str] = {}


Expand Down
10 changes: 10 additions & 0 deletions instill/helpers/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ def __str__(
self,
) -> str:
return f"model config file `instill.yaml` is missing {self.field} field"


class InvalidInputException(Exception):
def __str__(self) -> str:
return "trigger request input error"


class InvalidOutputShapeException(Exception):
def __str__(self) -> str:
return "outputs length not matched"
Loading

0 comments on commit 548e784

Please sign in to comment.