Skip to content

Commit

Permalink
fix: increase CLIP max_batch_size to 32
Browse files Browse the repository at this point in the history
As we didn't configure any config.pbtxt file, max batch size was 4 by
default
  • Loading branch information
raphael0202 committed Mar 12, 2023
1 parent 118f7d9 commit a39d61a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
26 changes: 26 additions & 0 deletions models/clip/config.pbtxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
backend: "onnxruntime"
max_batch_size: 32
input [
{
name: "pixel_values"
data_type: TYPE_FP32
dims: [ -1, -1, -1 ]
},
{
name: "attention_mask"
data_type: TYPE_INT64
dims: [ -1 ]
},
{
name: "input_ids"
data_type: TYPE_INT64
dims: [ -1 ]
}
]
output [
{
name: "image_embeds"
data_type: TYPE_FP32
dims: [ 512 ]
}
]
9 changes: 5 additions & 4 deletions robotoff/triton.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

logger = get_logger(__name__)

# Maximum batch size for CLIP model set in CLIP config.pbtxt
CLIP_MAX_BATCH_SIZE = 32


@cachetools.cached(cachetools.Cache(maxsize=1))
def get_triton_inference_stub():
Expand Down Expand Up @@ -64,10 +67,8 @@ def generate_clip_embedding_request(images: list[Image.Image]):
def generate_clip_embedding(images: list[Image.Image]) -> np.ndarray:
embedding_batches = []
stub = get_triton_inference_stub()
# max_batch_size is currently set to default value of 4 for CLIP
# TODO(raphael): Supply a custom model config file to increase this
# value
for image_batch in chunked(images, 4):

for image_batch in chunked(images, CLIP_MAX_BATCH_SIZE):
request = generate_clip_embedding_request(image_batch)
response = stub.ModelInfer(request)
embedding_batch = np.frombuffer(
Expand Down

0 comments on commit a39d61a

Please sign in to comment.