In this article
A custom batch-size function changes the unit of the batching threshold; it does not automatically make an approximate text count a safe model-work bound.
A token budget is implemented as word counting
A text service introduces a custom batching function that sums whitespace-separated words. Its documentation calls the resulting threshold a token budget. Inputs containing code, unusual punctuation or another language can produce a very different tokenizer length for the same word count.
Name the metric after what it actually measures. If the operational limit concerns model tokens, the counting method and tokenizer revision must reflect that contract rather than borrowing a convenient string-processing approximation.
Ray Serve lets the application define effective size
The batch API documents batch_size_fn as a function returning an effective batch size. Without that function, ordinary item counting is used. A custom metric therefore changes the meaning of the configured size threshold.
The mechanism cannot determine whether the chosen measure is a correct predictor of model cost. That relationship belongs to the application’s input preparation and inference implementation, including any padding or expanded representation created after grouping.
Examples demonstrate a pattern rather than your tokenizer
The dynamic-batching guide demonstrates custom metrics for variable workloads. Treat simplified text-counting examples as illustrations of the API pattern, not proof that word splitting matches the tokenizer of a deployed language model.
Tokenizer release identity explains why the actual tokenizer matters. A changed tokenizer or prompt construction can alter the measured work even when the raw request string and the serving threshold remain unchanged.
Request admission still uses another boundary
The deployment configuration guide describes ongoing-request controls. These count admitted requests rather than the custom metric used by a batch handler, so review both units when planning the complete request path.
Tensor memory representation provides background on separating logical workload from physical representation. Even accurate token totals need validation against real model-memory behavior; padding and temporary tensors can make cost depend on more than the sum alone.
Validate the metric with adversarial supported inputs
Compare the custom size calculation with actual prepared model inputs across supported languages, code and long individual requests. Verify handling when a single item is itself larger than the intended application budget rather than assuming grouping alone solves that case.
Record the metric definition beside the threshold. A defensible policy explains its units, the preparation stage it measures and the observed resource envelope, instead of publishing an approximate counter as a universal memory guarantee.
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.