Repository navigation
[Python] Add prefix-aware batching and capacity-based GPU autoscaling signal for vLLM RunInference - #40760
Draft
AMOOOMA wants to merge 2 commits into
Draft
[Python] Add prefix-aware batching and capacity-based GPU autoscaling signal for vLLM RunInference#40760AMOOOMA wants to merge 2 commits into
AMOOOMA wants to merge 2 commits into
Conversation
… fix uuid identifier test after apache#40671 annotation scoping
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #40760 +/- ##
==========================================
- Coverage 80.04% 79.96% -0.09%
==========================================
Files 490 495 +5
Lines 82916 83893 +977
==========================================
+ Hits 66373 67081 +708
- Misses 16543 16812 +269
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Productionizes prefix-aware batching and a capacity-based GPU autoscaling signal for vLLM
RunInferencepipelines (the approach evaluated in https://arxiv.org/abs/2610.22731).Two problems today:
num_loaded_models_<model_identifier>as "messages each worker can hold", but a model server such as vLLM always has exactly one loaded copy per worker, so the pool cannot scale on actual serving capacity.BatchElementsassembles batches per worker regardless of prompt prefix, so vLLM's prefix (KV) cache is thrashed by heterogeneous batches.Changes
Keyed / prefix-aware batching (
transforms/util.py,ml/inference/base.py)BatchElements(key_fn=..., num_shards=...): a newWithBatchKeyDoFn keys elements without the per-worker UUID thatWithSharedKey/WithLengthBucketKeyadd, thenGroupIntoBatchesshuffles elements sharing a key to the same worker so each batch is homogeneous.num_shards(int, per-key mapping, or callable) bounds hot-key fanout.ModelHandler(batch_key_fn=..., batch_key_num_shards=...)forwards these toBatchElements.ModelHandler.set_model_identifier()hook:_RunInferenceDoFn.setup()reports themodel_identifier(explicit or generated) to the handler before the firstload_model(), so handlers that publishnum_loaded_models_<tag>themselves use the exact tag the runner annotates the step with (stable across side-input model updates).Autoscaling signal (
ml/inference/autoscaling_metrics.py, new)CompletionRateSignalscrapes a server's Prometheus/metricsand estimates per-worker capacity as per-slot throughput × p90 in-flight concurrency over a trailing window (load-independent, so a briefly starved worker after a rebalance does not report a collapsed rate).NumLoadedModelsPublisherpublishes it on a background thread into the process-wideBeamML_ModelManagerdistribution (resetting the cell so the latest value, not a lifetime mean, is reported). Optional'lifetime_max'/ windowed'max'/'pNN'/'mean'policies on top; default'last'since the signal is already smoothed.AutoscalingMetricConfigholds the user-facing knobs.Prefix batching config (
ml/inference/prefix_batching.py, new)PrefixBatchingConfigplus default key extractorsPromptPrefixKeyFn(completions) andChatPrefixKeyFn(chat).vLLM handlers (
ml/inference/vllm_inference.py)VLLMCompletionsModelHandler/VLLMChatModelHandlergainprefix_batching_config,enable_autoscaling_metric(defaultTrue), andautoscaling_config._VLLMModelServerstarts the publisher once the server is reachable and stops it on teardown.Depends on #40671 (already merged), which scopes the
model_identifierannotation to theBeamML_RunInferencestep; without it the keying stage added byGroupIntoBatcheswould also be sized by the GPU autoscaler.Testing
autoscaling_metrics_test.py,prefix_batching_test.py,vllm_inference_test.py,base_test.py(identifier hook, end-to-end prefix batching throughRunInference), andutil_test.py(WithBatchKey, sharding specs,BatchElements(key_fn=...)).RunInferencestage scaled 1 → 32–46 → 1 GPU workers in both cycles and the worker pool followed it down (50 → 13 and 50 → 6 VMs), with ~302k results written to BigQuery.Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123orfixes #456).CHANGES.mdwith noteworthy changes.