[Performance] Dynamic Batch Tokenizer #9382
Open
+1,550
−614
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.
Motivation
AsyncDynamicBatchTokenizer
that enables batching of tokenization requests to improve throughput and reduce latency for SGLang's tokenizer manager.Performance Impact:
Context
This PR builds upon the tokenization batching infrastructure introduced in PR #5141, which added
enable_tokenizer_batch_encode
for batching multiple texts within a single request.Tokenization Batching Options
enable_tokenizer_batch_encode
(PR #5141)enable_dynamic_batch_tokenizer
(This PR)Example scenarios:
enable_tokenizer_batch_encode
: Client sends{"input": ["text1", "text2", "text3"]}
in one requestenable_dynamic_batch_tokenizer
: Client sends multiple concurrent requests:{"input": "text1"}
,{"input": "text2"}
,{"input": "text3"}
Modifications
🚀 Dynamic Batching
max_batch_size
orbatch_wait_timeout_s
when queue has pending items⚙️ Server Args
max_batch_size
(default: 32): Maximum number of requests to batch togetherbatch_wait_timeout_s
(default: 0.002s): Maximum time to wait for additional requestsenable_dynamic_batch_tokenizer
: Feature flag to enable/disable the functionality🔄 Async Processing
asyncio
andThreadPoolExecutor
Benchmarking and Profiling
Baseline Results
Batch Tokenizer Results
Checklist