Skip to content

[Serve] Support keyword inputs with custom batch sizing - #66321

Merged
abrarsheikh merged 8 commits into
ray-project:masterfrom
jayeshsuyal:jayeshsuyal/fix-batch-keyword-payload
Oct 13, 2026
Merged

abrarsheikh merged 8 commits into
ray-project:masterfrom
jayeshsuyal:jayeshsuyal/fix-batch-keyword-payload

Conversation

@jayeshsuyal

@jayeshsuyal jayeshsuyal commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

When a single-input batched handler uses batch_size_fn, passing its input by keyword leaves no positional argument for _compute_batch_size to read. The resulting IndexError escapes batch assembly. A local Serve deployment reproduces positional success, keyword timeout, then another positional timeout because the batching task has stopped.

Read the first payload value from the existing flattened argument representation, after self has already been removed. This preserves successful positional calls and supports a single explicitly supplied input passed by keyword, including keyword-only parameters. Existing multi-input positional calls remain supported. Multi-input keyword calls and variadic keyword (**kwargs) handlers are rejected before queueing because their flattened keyword order is not stable across a batch, and omitting a defaulted input is rejected because there is no explicit value to size. These errors affect only the caller and do not stop the batching worker. General callback-error isolation remains outside this change.

The tests exercise functions and bound methods, coroutine and streaming handlers, mixed positional/keyword arrivals in both orders, keyword-only signatures, oversized keyword input recovery, omitted defaults, second-keyword-first ordering, variadic keyword signatures, positional multi-input compatibility, and worker survival after invalid requests. The batching guide describes the supported call forms.

Related work and attribution

This addresses the finding already raised in the review of #59059; it is not a new discovery. Searches for custom sizing and keyword/kwargs fixes found no matching open PR. #66141 fixes callback-error isolation and explicitly excludes keyword compatibility. #64595 restructures per-model queues but leaves this payload extraction unchanged; it touches the same file and may require rebasing.

Validation

macOS arm64, Python 3.12.14, official Ray 3.0.0.dev0 wheel at 39882c660a6d7b579e39d724ce85d9074d6180fb, with the branch's current Python Serve sources linked into the environment. Because the branch includes newer master changes, the source and wheel revisions are not exact; the focused suite required a runner-local shim for a newer test-fixture helper.

.venv/bin/python - <<'PYTEST'
import ray, pytest
raise SystemExit(pytest.main([
    '--import-mode=importlib',
    'python/ray/serve/tests/unit/test_batching.py',
    '--tb=short', '-q',
]))
PYTEST
  • 15 keyword regressions from the original change fail on the original implementation; seven review-fix cases fail before their respective fixes.
  • Full batching unit file: 87 passed, including 26 cases added by this PR.
  • Real CPU-only local Serve deployment: positional and keyword requests succeed; invalid omitted-default, multi-input-keyword, and variadic-keyword calls return bounded TypeErrors; a subsequent valid request succeeds and all batching tasks remain alive.
  • All hooks applicable to the changed files pass; git diff --check passes. Vale is excluded for this documentation path and its environment separately failed to compile on this Mac because the C++ cassert header was unavailable.
  • The test runner prints pending-task teardown diagnostics that were already present in the earlier 61-test baseline; the run exits successfully. The local demo logs include the existing batch-size/ongoing-request advisory and Ray shutdown messages.
  • Independent Astra Low reviews of each exact review-fix diff found no actionable issues in argument mapping, exception propagation, unresolved futures, cancellation, streaming, or worker survival.

No GPU performance, full-Ray suite, docs build, or upstream CI result is claimed.

@jayeshsuyal
jayeshsuyal requested review from a team as code owners September 19, 2026 23:49

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request simplifies the extraction of batch items in _compute_batch_size by directly accessing the flattened arguments, which enables support for both positional and keyword arguments (including keyword-only parameters) when using a custom batch_size_fn. The documentation has been updated to reflect this behavior, and comprehensive unit tests have been added to verify various calling styles and edge cases. There are no review comments, and I have no additional feedback to provide.

@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue community-contribution Contributed by the community labels Sep 20, 2026
Comment thread python/ray/serve/batching.py Resolved
Comment thread python/ray/serve/batching.py Resolved
Comment thread python/ray/serve/batching.py Resolved
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Oct 8, 2026
@YashwanthRanjanSingaravel
YashwanthRanjanSingaravel requested a review from a team as a code owner October 9, 2026 18:28
@YashwanthRanjanSingaravel YashwanthRanjanSingaravel added go add ONLY when ready to merge, run all tests and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @YashwanthRanjanSingaravel for refining the first-input validation, adding the compatibility coverage, and improving the docs. Really appreciate the careful review and follow-up fixes!

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 50487c2. Configure here.

Comment thread python/ray/serve/batching.py Resolved
@abrarsheikh
abrarsheikh merged commit 7f91ae3 into ray-project:master Oct 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants