examples.test_batching¶
Example: Test continuous batching with vllm-mlx.
View the complete module source at #L1-L195.
API details¶
Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.
examples.test_batching
¶
Example: Test continuous batching with vllm-mlx.
This script demonstrates the continuous batching capability by sending multiple concurrent requests and measuring throughput.
Usage
python examples/test_batching.py python examples/test_batching.py --model mlx-community/Qwen2.5-3B-Instruct-4bit python examples/test_batching.py --num-requests 10 --max-tokens 50
examples.test_batching.run_single_request
async
¶
run_single_request(engine: AsyncEngineCore, request_id: str, prompt: str, sampling_params: SamplingParams) -> dict
Run a single request and collect timing.
Source code in examples/test_batching.py
examples.test_batching.run_concurrent_requests
async
¶
run_concurrent_requests(engine: AsyncEngineCore, prompts: List[str], sampling_params: SamplingParams) -> List[dict]
Run multiple requests concurrently.
Source code in examples/test_batching.py
examples.test_batching.print_results
¶
Print benchmark results.
Source code in examples/test_batching.py
examples.test_batching.main
async
¶
Source code in examples/test_batching.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
Complete contract reference¶
Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.
examples.test_batching.run_single_request · function
async examples.test_batching.run_single_request(engine: AsyncEngineCore, request_id: str, prompt: str, sampling_params: SamplingParams) -> dict
Run a single request and collect timing.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
engine |
AsyncEngineCore |
yes |
none |
Required positional or keyword input. |
request_id |
str |
yes |
none |
Required positional or keyword input. |
prompt |
str |
yes |
none |
Required positional or keyword input. |
sampling_params |
SamplingParams |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict - Direct return expressions:
{'request_id': request_id, 'prompt_length': len(prompt.split()), 'num_tokens': len(tokens), 'ttft': ttft, 'total_time':…
Exceptions and behavior
Function run_single_request calls time.perf_counter, engine.add_request, engine.stream_outputs, tokens.extend; awaits asynchronous work; returns {'request_id': request_id, 'prompt_length': len(prompt.split()), 'num_tokens': len(tokens), 'ttft': ttft, 'total_time':….
No direct raise statement appears in this definition.
examples.test_batching.run_concurrent_requests · function
async examples.test_batching.run_concurrent_requests(engine: AsyncEngineCore, prompts: List[str], sampling_params: SamplingParams) -> List[dict]
Run multiple requests concurrently.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
engine |
AsyncEngineCore |
yes |
none |
Required positional or keyword input. |
prompts |
List[str] |
yes |
none |
Required positional or keyword input. |
sampling_params |
SamplingParams |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
List[dict] - Direct return expressions:
await asyncio.gather(*tasks)
Exceptions and behavior
Function run_concurrent_requests calls enumerate, run_single_request, tasks.append, asyncio.gather; awaits asynchronous work; returns await asyncio.gather(*tasks).
No direct raise statement appears in this definition.
examples.test_batching.print_results · function
Print benchmark results.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
results |
List[dict] |
yes |
none |
Required positional or keyword input. |
total_time |
float |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated
Exceptions and behavior
Function print_results calls print, sum, len.
No direct raise statement appears in this definition.
examples.test_batching.main · function
Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, print; awaits asynchronous work.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated
Exceptions and behavior
Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, print; awaits asynchronous work.
No direct raise statement appears in this definition.
Complete symbol map¶
This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.
| Symbol | Kind | Signature and inputs | What it does | Source |
|---|---|---|---|---|
run_single_request |
function | async run_single_request(engine: AsyncEngineCore, request_id: str, prompt: str, sampling_params: SamplingParams) -> dict |
Run a single request and collect timing. | #L29-L65 |
run_concurrent_requests |
function | async run_concurrent_requests(engine: AsyncEngineCore, prompts: List[str], sampling_params: SamplingParams) -> List[dict] |
Run multiple requests concurrently. | #L68-L79 |
print_results |
function | print_results(results: List[dict], total_time: float) -> not annotated |
Print benchmark results. | #L82-L113 |
main |
function | async main() -> not annotated |
Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, print; awaits asynchronous work. |
#L116-L191 |