damccorm opened a new pull request, #41839:
URL: https://github.com/apache/beam/pull/41839
Note: this PR was auto-generated by tooling. Before moving it out of draft,
the author has done a full review of the PR, specifically evaluating it on the
following criteria:
- The PR is an appropriate fix for the issue (e.g. we're not changing a test
to avoid a bug)
- The PR is a simple fix to the issue (e.g. we're not adding infra when we
could just modify a test)
- The PR is not covering for other problems (e.g. if we're bumping timeouts,
it is not because we're covering for a performance problem)
Full details of the methodology of generation and review can be found here -
https://docs.google.com/document/d/14lj7ECVov4T4EdwmIzNlWrRGE3lLDMOwX5xUMGzaLoc/edit?usp=sharing
If you have concerns with the PR or with the underlying methodology used to
generate this, please comment below - they will be addressed by the author not
the tooling :)
## Summary
Bounds concurrent in-flight HTTP requests per batch inside
`VLLMCompletionsModelHandler._async_run_inference` and
`VLLMChatModelHandler._async_run_inference` using an `asyncio.Semaphore`
(`_MAX_CONCURRENT_REQUESTS = 100`, matching `openai`'s default keep-alive pool
size).
## Observed Failure
- **`Inference Python Benchmarks Dataflow` ([run
46572116483](https://github.com/apache/beam/actions/runs/46572116483), attempt
2, [job
142531335931](https://github.com/apache/beam/actions/runs/46572116483/job/142531335931),
[build scan](https://develocity.apache.org/s/7g325ro75iju4))**: `Run VLLM
Gemma Batch Test` (Dataflow job
[`2026-12-01_01_57_07-17462368327896577911`](https://console.cloud.google.com/dataflow/jobs/us-central1/2026-12-01_01_57_07-17462368327896577911?project=apache-beam-testing))
failed after 4 work-item retries (`10:47:10Z`, `10:50:40Z`, `10:54:23Z`,
`11:02:16Z`) with `httpcore.ConnectTimeout` -> `openai.APITimeoutError: Request
timed out.` in `apache_beam/ml/inference/vllm_inference.py:525`
(`_async_run_inference`).
- Attempt 1 ([job
142385537438](https://github.com/apache/beam/actions/runs/46572116483/job/142385537438))
also logged 4 identical `openai.APITimeoutError` tracebacks (`04:51Z–05:36Z`)
in the same step before later hitting T4 GPU quota exhaustion on a subsequent
step.
## Root Cause
- `VLLMCompletionsModelHandler._async_run_inference` and
`VLLMChatModelHandler._async_run_inference` create a fresh `AsyncOpenAI` client
per batch and submit every prompt in `batch` to `asyncio.gather(...)`
simultaneously without bounding concurrency.
- When `max_batch_size` is not set on the model handler (e.g.,
`vllm_gemma_batch.py`, which passes an unrecognized `inference_batch_size=32`
kwarg to `RunInference` instead of `max_batch_size` on `ModelHandler`),
`BatchElements` defaults to `max_batch_size=10000`.
- Enqueuing thousands of simultaneous requests into
`httpcore.AsyncConnectionPool` (with `openai`'s default `max_connections=1000`)
triggers quadratic scanning inside
`httpcore._async.connection_pool._assign_requests_to_connections()`. Worker
`benchmark-tests-vllm-with-12010157-5cit-harness-72sw` logged an `Operation
ongoing ... for at least 402.61 seconds` stall directly inside
`_assign_requests_to_connections()` (`connection_pool.py:305`) while the local
vLLM server (`APIServer pid=446`) sat idle (`Running: 0 reqs, Waiting: 0 reqs`)
and responded normally to `model.check_connectivity()` (`models.list()`).
- Because the single-threaded `asyncio` event loop was starved for >400s,
pending TCP connect coroutines blew past `openai`'s 5.0s `connect` timeout
(`httpcore.ConnectTimeout` -> `openai.APITimeoutError`).
## Fix
- Added `_MAX_CONCURRENT_REQUESTS = 100` (matching `openai`'s default
`max_keepalive_connections=100`) and `_gather_bounded(...)` in
`sdks/python/apache_beam/ml/inference/vllm_inference.py`, gating both
`VLLMCompletionsModelHandler._async_run_inference` and
`VLLMChatModelHandler._async_run_inference` with an `asyncio.Semaphore`.
- Keeps `httpcore.AsyncConnectionPool`'s active request/connection lists
small (`<= 100`), maximizes HTTP/1.1 keep-alive connection reuse across large
batches, preserves exact input/output ordering and `model.check_connectivity()`
error handling, and leaves multi-worker continuous batching throughput
saturated (e.g. `8 * 100 = 800` in-flight requests per `n1-standard-8` VM vs
vLLM's default `max_num_seqs=256`).
- Added unit tests in
`sdks/python/apache_beam/ml/inference/vllm_inference_test.py` verifying bounded
concurrency, output order preservation, and `check_connectivity()` on failure
for both handlers.
## Verification
- Verified syntax, 80-char formatting, and ran the 3 new unit tests locally
(`3/3` passed in `0.108s`).
- Triggered `PreCommit Python ML tests with ML deps installed`
(`beam_PreCommit_Python_ML.yml`) on this branch (`PreCommit Python Formatter`
also runs automatically on push).
### Verification
- Triggered `.github/workflows/beam_PreCommit_Python_ML.yml` workflow run on
branch: [`46635658480`](https://github.com/apache/beam/actions/runs/46635658480)
--
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]