TECHNOLOGY

BentoML composite batch inputs: keep each image paired with its own threshold

In this article
THE QUICK TAKE

Batch related per-request values together; independent lists or a shared mutable threshold can lose the association the model API needs.

A shared threshold changes another request’s result

An image detector accepts an image and a confidence threshold. A wrapper stores the latest threshold in shared state while sending images to a batchable endpoint. Concurrent requests can then use another caller’s threshold. The detector may process every image successfully while violating the request’s intended parameters.

Make the image and its threshold one semantic input item. The same principle applies to text with language settings or embeddings with per-request normalization options. Related fields should cross the batching boundary together rather than being reconstructed from ambient state.

Batchable APIs use a single input contract

The adaptive batching guide documents the batchable endpoint signature and a composite-input pattern for multiple request parameters. It also notes that request order inside a batch is not guaranteed. Client arrival timing is therefore not a safe substitute for carrying the association in the item itself.

Represent the collection as complete request items and derive each output from the corresponding item. Avoid independently sorting images and thresholds or assuming their positions can be reconstructed later from logs.

Schema validation should preserve the relation

The input and output guide describes structured service schemas. Define required fields and their meanings in a composite type rather than hiding per-request parameters in a global variable. The schema should make it obvious which threshold belongs to which image.

Explicit table contracts provide a related lesson: valid field types are useful, but the relationship between fields is also part of the data contract. A numeric threshold does not identify its intended sample automatically.

The wrapper and batch service have different roles

The client guide explains endpoint calls and argument passing. A wrapper can accept a convenient individual request and transform it into the batch service’s composite representation. Preserve the same semantic item through that conversion.

Keep request identity in diagnostic evidence where needed. Request correlation scope illustrates why a correlation label is useful but does not itself prevent data-association errors or turn independent lists into a coherent request object.

Exercise concurrent distinct parameters

Send recognizable images with deliberately different thresholds concurrently and compare each response with its isolated reference. Confirm that changing another request’s threshold cannot alter the first request’s interpretation through shared state.

Inspect the full returned item association rather than only aggregate detection counts. Once the composite contract is correct, batching can be tuned without sacrificing the per-request meaning that the public API promises its callers.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles