Skip to content

Commit 164245a

Browse files
authored
Add back the support of Languagebind Models (#1188)
We removed the support for Languagebind Models in 2.17. Now we add them back. Languagebind Models are working again. This PR mainly includes the following changes: - 1. Add back the support of the Languagebind Models. - 2. Move the `MARQO_MAX_SEARCH_VIDEO_AUDIO_FILE_SIZE` and `MARQO_MAX_ADD_DOCS_VIDEO_AUDIO_FILE_SIZE` environment variables to the API part. The inference server will get this value from the request. - 3. Add unit tests for media downloading and preprocessing in the inference server.
1 parent 9bb7d9d commit 164245a

File tree

42 files changed

+2018
-912
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2018
-912
lines changed

src/marqo/api/configs.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,21 @@ def default_env_vars() -> dict:
6464
EnvVars.MARQO_INFERENCE_POOL_SIZE: 20, # Please adjust this based on the throttling config
6565
EnvVars.MARQO_INFERENCE_TIMEOUT: 300, # 300s to support inference of large batch of media files
6666

67+
# 370 megabytes in bytes, read in API and passed to inference server
68+
EnvVars.MARQO_MAX_SEARCH_VIDEO_AUDIO_FILE_SIZE: 387973120,
69+
# 370 megabytes in bytes, read in API and passed to inference server
70+
EnvVars.MARQO_MAX_ADD_DOCS_VIDEO_AUDIO_FILE_SIZE: 387973120,
6771

72+
# Read in API and passed to inference server
73+
EnvVars.MARQO_MEDIA_DOWNLOAD_THREAD_COUNT_PER_REQUEST: 5,
74+
EnvVars.MARQO_IMAGE_DOWNLOAD_THREAD_COUNT_PER_REQUEST: 20,
75+
76+
##########################################
6877
# Inference Server config (In Inference)
6978
EnvVars.MARQO_MODELS_TO_PRELOAD: [],
7079
EnvVars.MARQO_MAX_CPU_MODEL_MEMORY: 4,
7180
EnvVars.MARQO_MAX_CUDA_MODEL_MEMORY: 4, # For multi-GPU, this is the max memory for each GPU.
7281

73-
EnvVars.MARQO_MEDIA_DOWNLOAD_THREAD_COUNT_PER_REQUEST: 5,
74-
EnvVars.MARQO_IMAGE_DOWNLOAD_THREAD_COUNT_PER_REQUEST: 20,
75-
76-
EnvVars.MARQO_MAX_SEARCH_VIDEO_AUDIO_FILE_SIZE: 387973120, # 370 megabytes in bytes
77-
EnvVars.MARQO_MAX_ADD_DOCS_VIDEO_AUDIO_FILE_SIZE: 387973120, # 370 megabytes in bytes
78-
7982
EnvVars.MARQO_MAX_VECTORISE_BATCH_SIZE: 16, # static inference batching
8083
EnvVars.MARQO_INFERENCE_CACHE_SIZE: 0,
8184
EnvVars.MARQO_INFERENCE_CACHE_TYPE: "LRU",

src/marqo/api/models/add_docs_objects.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
from pydantic.v1 import BaseModel, root_validator
55
from pydantic.v1 import Field
66

7-
from marqo.tensor_search.enums import EnvVars
87
from marqo.tensor_search.models.private_models import ModelAuth
9-
from marqo.tensor_search.utils import read_env_vars_and_defaults_ints
108

119

1210
class AddDocsBodyParams(BaseModel):
@@ -24,18 +22,10 @@ class Config:
2422
modelAuth: Optional[ModelAuth] = None
2523
mappings: Optional[dict] = None
2624
documents: Sequence[Dict[str, Any]]
27-
imageDownloadThreadCount: int = Field(default_factory=lambda: read_env_vars_and_defaults_ints(EnvVars.MARQO_IMAGE_DOWNLOAD_THREAD_COUNT_PER_REQUEST))
25+
imageDownloadThreadCount: Optional[int] = None
2826
mediaDownloadThreadCount: Optional[int] = None
2927
textChunkPrefix: Optional[str] = None
3028

31-
@root_validator
32-
def validate_thread_counts(cls, values):
33-
image_count = values.get('imageDownloadThreadCount')
34-
media_count = values.get('mediaDownloadThreadCount')
35-
if media_count is not None and image_count != read_env_vars_and_defaults_ints(EnvVars.MARQO_IMAGE_DOWNLOAD_THREAD_COUNT_PER_REQUEST):
36-
raise ValueError("Cannot set both imageDownloadThreadCount and mediaDownloadThreadCount")
37-
return values
38-
3929
@root_validator(skip_on_failure=True)
4030
def _validate_image_download_headers_and_media_download_headers(cls, values):
4131
"""Validate imageDownloadHeaders and mediaDownloadHeaders. Raise an error if both are set.
@@ -53,4 +43,4 @@ def _validate_image_download_headers_and_media_download_headers(cls, values):
5343
"Use mediaDownloadHeaders instead.")
5444
if image_download_headers:
5545
values['mediaDownloadHeaders'] = image_download_headers
56-
return values
46+
return values

src/marqo/core/inference/api/exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ class MediaDownloadError(InferenceError):
2424
class UnsupportedModalityError(InferenceError):
2525
"""Raises if a modality is not supported by a specific model"""
2626
pass
27+
28+
29+
class MediaExceedsMaxSizeError(InferenceError):
30+
"""Raised when the media exceeds the maximum size limit"""
31+
pass

src/marqo/core/inference/api/preprocessing_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class AudioPreprocessingConfig(PreprocessingConfig):
8181
download_thread_count: Optional[int] = Field(default=None, alias='downloadThreadCount')
8282
download_header: Optional[Dict[str, str]] = Field(default=None, alias='downloadHeader')
8383
chunk_config: Optional[ChunkConfig] = Field(default=None, alias='chunkConfig')
84+
max_media_size_bytes: int = Field(ge=1, default=387973120, alias='maxMediaSizeBytes')
8485

8586
@root_validator
8687
def validate_chunk_config(cls, values):
@@ -99,6 +100,7 @@ class VideoPreprocessingConfig(PreprocessingConfig):
99100
download_thread_count: Optional[int] = Field(default=None, alias='downloadThreadCount')
100101
download_header: Optional[Dict[str, str]] = Field(default=None, alias='downloadHeader')
101102
chunk_config: Optional[ChunkConfig] = Field(default=None, alias='chunkConfig')
103+
max_media_size_bytes: int = Field(ge=1, default=387973120, alias='maxMediaSizeBytes')
102104

103105
@root_validator
104106
def validate_chunk_config(cls, values):

src/marqo/core/models/add_docs_params.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AddDocsParams(BaseModel):
2222
use_existing_tensors: Whether to use the vectors already in doc (for update docs)
2323
device: Device used to carry out the document update, if `None` is given, it will be determined inference
2424
image_download_thread_count: number of threads used to concurrently download images
25-
media_download_headers: headers to authenticate media download requests
25+
media_download_headers: headers to authenticate media download requests for audio and video
2626
mappings: a dictionary used to handle all the object field content in the doc,
2727
e.g., multimodal_combination field
2828
model_auth: an object used to authorise downloading an object from a datastore
@@ -39,9 +39,8 @@ class Config:
3939
index_name: str
4040
device: Optional[str]
4141
tensor_fields: Optional[List] = Field(default_factory=None)
42-
image_download_thread_count: int = Field(default_factory=lambda: read_env_vars_and_defaults_ints(
43-
EnvVars.MARQO_IMAGE_DOWNLOAD_THREAD_COUNT_PER_REQUEST))
44-
media_download_thread_count: Optional[int]
42+
image_download_thread_count: Optional[int] = None
43+
media_download_thread_count: Optional[int] = None
4544
media_download_headers: Optional[dict] = None
4645
use_existing_tensors: bool = False
4746
mappings: Optional[dict] = None
@@ -51,12 +50,39 @@ class Config:
5150
def __init__(self, **data: Any):
5251
super().__init__(**data)
5352

54-
@root_validator
53+
@root_validator(pre=True)
5554
def validate_thread_counts(cls, values):
55+
"""
56+
Set the values for image_download_thread_count and media_download_thread_count.
57+
There are 4 cases:
58+
1. Both not given -> Both reads default values
59+
2. Image given, media not given -> media reads default value, image uses given value
60+
3. Media set, image not set -> media uses given value, image uses media value
61+
4. Both set -> error:
62+
Once set, media_download_thread_count is used for audio and video, image_download_thread_count is
63+
used for images, when sending inference requests to the inference server.
64+
"""
5665
image_count = values.get('image_download_thread_count')
5766
media_count = values.get('media_download_thread_count')
58-
if media_count is not None and image_count != read_env_vars_and_defaults_ints(EnvVars.MARQO_IMAGE_DOWNLOAD_THREAD_COUNT_PER_REQUEST):
59-
raise ValueError("Cannot set both image_download_thread_count and media_download_thread_count")
67+
if media_count and image_count:
68+
raise ValueError("Cannot set both 'image_download_thread_count' and 'media_download_thread_count'.")
69+
elif image_count is None and media_count is None:
70+
# Set default values for both
71+
values['image_download_thread_count'] = (
72+
read_env_vars_and_defaults_ints(EnvVars.MARQO_IMAGE_DOWNLOAD_THREAD_COUNT_PER_REQUEST))
73+
values['media_download_thread_count'] = (
74+
read_env_vars_and_defaults_ints(EnvVars.MARQO_MEDIA_DOWNLOAD_THREAD_COUNT_PER_REQUEST)
75+
)
76+
elif image_count is None and media_count is not None:
77+
values['media_download_thread_count'] = media_count
78+
values['image_download_thread_count'] = media_count
79+
elif image_count is not None and media_count is None:
80+
values['media_download_thread_count'] = (
81+
read_env_vars_and_defaults_ints(EnvVars.MARQO_MEDIA_DOWNLOAD_THREAD_COUNT_PER_REQUEST)
82+
)
83+
values['image_download_thread_count'] = image_count
84+
else:
85+
raise ValueError("Invalid combination of image_download_thread_count and media_download_thread_count.")
6086
return values
6187

6288
@validator('docs')

src/marqo/core/vespa_index/add_documents_handler.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
from marqo.core.models.marqo_add_documents_response import MarqoAddDocumentsItem, MarqoAddDocumentsResponse
1616
from marqo.logging import get_logger
1717
from marqo.tensor_search import validation
18+
from marqo.tensor_search.enums import EnvVars
1819
from marqo.tensor_search.telemetry import RequestMetricsStore
20+
from marqo.tensor_search.utils import read_env_vars_and_defaults_ints
1921
from marqo.vespa.models import VespaDocument, FeedBatchResponse
2022
from marqo.vespa.models.get_document_response import Document
2123
from marqo.vespa.vespa_client import VespaClient
@@ -391,7 +393,7 @@ def _get_preprocessing_config(self, modality: Modality, for_top_level_field: boo
391393
should_chunk=for_top_level_field and patch_method is not None,
392394
download_thread_count=self.add_docs_params.image_download_thread_count,
393395
download_header=self.add_docs_params.media_download_headers,
394-
patch_method=None if not for_top_level_field or not patch_method else patch_method.value
396+
patch_method=None if not for_top_level_field or not patch_method else patch_method.value,
395397
)
396398
elif modality == Modality.AUDIO:
397399
return AudioPreprocessingConfig(
@@ -401,7 +403,8 @@ def _get_preprocessing_config(self, modality: Modality, for_top_level_field: boo
401403
chunk_config=ChunkConfig(
402404
split_length=self.marqo_index.audio_preprocessing.split_length,
403405
split_overlap=self.marqo_index.audio_preprocessing.split_overlap,
404-
)
406+
),
407+
max_media_size_bytes=read_env_vars_and_defaults_ints(EnvVars.MARQO_MAX_ADD_DOCS_VIDEO_AUDIO_FILE_SIZE)
405408
)
406409
elif modality == Modality.VIDEO:
407410
return VideoPreprocessingConfig(
@@ -411,7 +414,8 @@ def _get_preprocessing_config(self, modality: Modality, for_top_level_field: boo
411414
chunk_config=ChunkConfig(
412415
split_length=self.marqo_index.video_preprocessing.split_length,
413416
split_overlap=self.marqo_index.video_preprocessing.split_overlap,
414-
)
417+
),
418+
max_media_size_bytes=read_env_vars_and_defaults_ints(EnvVars.MARQO_MAX_ADD_DOCS_VIDEO_AUDIO_FILE_SIZE)
415419
)
416420
else:
417421
raise InternalError(f'The modality {modality} is not supported.')

0 commit comments

Comments
 (0)