claudevdm commented on code in PR #41361:
URL: https://github.com/apache/beam/pull/41361#discussion_r4681274565
##########
sdks/python/apache_beam/ml/inference/gemini_inference.py:
##########
@@ -226,6 +228,14 @@ def __init__(
self._env_vars = kwargs.get('env_vars', {})
if min_batch_size is not None:
self._batching_kwargs["min_batch_size"] = min_batch_size
+ # With element_size_fn and no max_batch_weight, BatchElements counts
+ # max_batch_size in element_size_fn units (e.g. characters), not prompts,
+ # so the default number of prompts does not apply.
+ sized_by_element_size_fn = (
+ element_size_fn is not None and max_batch_weight is None)
+ if max_batch_size is None and not sized_by_element_size_fn:
Review Comment:
With an embeddings `request_fn` that sends up to 2,048 inputs per request
the default batch size might be too high?.
```suggestion
# A custom request_fn may send the whole batch in one request.
custom_request_fn = request_fn not in (
generate_from_string, generate_image_from_strings_and_images)
skip_default = sized_by_element_size_fn or custom_request_fn
if max_batch_size is None and not skip_default:
```
##########
sdks/python/apache_beam/ml/inference/openai_inference.py:
##########
@@ -297,7 +302,10 @@ def __init__(
min_batch_size: optional. the minimum batch size to use when
batching inputs.
max_batch_size: optional. the maximum batch size to use when
- batching inputs.
+ batching inputs. Defaults to 2048 with embedding_from_string, the
+ most inputs the API accepts in one request, and to 32 otherwise.
Review Comment:
```suggestion
most inputs the API accepts in one request, and to 32 with the other
built-in request functions. There is no default when element_size_fn
is set without max_batch_weight, or with a custom request_fn: set it
to the largest batch the function can send.
```
##########
sdks/python/apache_beam/ml/inference/openai_inference.py:
##########
@@ -320,6 +328,16 @@ def __init__(
self._env_vars = kwargs.get('env_vars', {})
if min_batch_size is not None:
self._batching_kwargs["min_batch_size"] = min_batch_size
+ # With element_size_fn and no max_batch_weight, BatchElements counts
+ # max_batch_size in element_size_fn units (e.g. characters), not prompts,
+ # so the default number of prompts does not apply.
+ sized_by_element_size_fn = (
+ element_size_fn is not None and max_batch_weight is None)
+ if max_batch_size is None and not sized_by_element_size_fn:
Review Comment:
The same change for the OpenAI handler.
```suggestion
# A custom request_fn may send the whole batch in one request.
custom_request_fn = request_fn not in (
chat_completion_from_string,
chat_completion_from_conversation,
embedding_from_string)
skip_default = sized_by_element_size_fn or custom_request_fn
if max_batch_size is None and not skip_default:
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]