examples.mllm_benchmark¶
MLLM Benchmark Script for vllm-mlx Tests Multimodal Language Models with real images of dogs from Wikimedia Commons at different resolutions and measures performance metrics.
View the complete module source at #L1-L443.
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.mllm_benchmark
¶
MLLM Benchmark Script for vllm-mlx
Tests Multimodal Language Models with real images of dogs from Wikimedia Commons at different resolutions and measures performance metrics.
Usage
Start the MLLM server first:¶
python -m vllm_mlx.server --model mlx-community/Qwen3-VL-4B-Instruct-3bit --port 8000
Run benchmark:¶
python examples/mllm_benchmark.py
Or specify server URL:¶
python examples/mllm_benchmark.py --server-url http://localhost:8000
examples.mllm_benchmark.TEST_IMAGES
module-attribute
¶
TEST_IMAGES = {'golden_retriever': {'url': 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bd/Golden_Retriever_Dukedestiny01_dbread_loose.jpg/1280px-Golden_Retriever_Dukedestiny01_dread_loose.jpg', 'description': 'Golden Retriever', 'fallback': 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bd/Golden_Retriever_Dukedestiny01_dread_loose.jpg/800px-Golden_Retriever_Dukedestiny01_dread_loose.jpg'}, 'german_shepherd': {'url': 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/d0/German_Shepherd_-_DSC_0346_%2810096362833%29.jpg/1280px-German_Shepherd_-_DSC_0346_%2810096362833%29.jpg', 'description': 'German Shepherd'}, 'labrador': {'url': 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/YellowLabradorLooking_new.jpg/1200px-YellowLabradorLooking_new.jpg', 'description': 'Yellow Labrador'}, 'beagle': {'url': 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/55/Beagle_600.jpg/1200px-Beagle_600.jpg', 'description': 'Beagle'}, 'husky': {'url': 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/Camponotus_flavomarginatus_ant.jpg/800px-Camponotus_flavomarginatus_ant.jpg', 'fallback': 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/4e/Husky_IMG_0921.jpg/800px-Husky_IMG_0921.jpg', 'description': 'Siberian Husky'}}
examples.mllm_benchmark.PRIMARY_DOG_IMAGE
module-attribute
¶
PRIMARY_DOG_IMAGE = 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/YellowLabradorLooking_new.jpg/1200px-YellowLabradorLooking_new.jpg'
examples.mllm_benchmark.BenchmarkResult
dataclass
¶
BenchmarkResult(resolution: str, width: int, height: int, pixels: int, time_seconds: float, tokens_generated: int, tokens_per_second: float, response_preview: str)
Result from a single benchmark run.
examples.mllm_benchmark.BenchmarkResult.tokens_per_second
instance-attribute
¶
examples.mllm_benchmark.download_image
¶
Download image from URL and return PIL Image.
Source code in examples/mllm_benchmark.py
examples.mllm_benchmark.resize_image
¶
examples.mllm_benchmark.image_to_base64
¶
Convert PIL Image to base64 data URL.
Source code in examples/mllm_benchmark.py
examples.mllm_benchmark.run_mllm_request
¶
run_mllm_request(server_url: str, image_b64: str, prompt: str = 'Describe this image in detail. What do you see?', max_tokens: int = 256, model: str = 'default') -> tuple[str, float, int]
Send an MLLM request to the server.
Returns:
-
tuple[str, float, int]–(response_text, time_seconds, tokens_generated)
Source code in examples/mllm_benchmark.py
examples.mllm_benchmark.benchmark_resolution
¶
benchmark_resolution(server_url: str, base_image: Image, width: int, height: int, model: str, warmup: bool = False) -> BenchmarkResult
Run benchmark for a specific resolution.
Source code in examples/mllm_benchmark.py
examples.mllm_benchmark.run_benchmark
¶
run_benchmark(server_url: str = 'http://localhost:8000', resolutions: list[tuple[int, int]] = None, warmup_runs: int = 1, image_url: str = None) -> list[BenchmarkResult]
Run full MLLM benchmark across multiple resolutions.
Parameters:
-
server_url(str, default:'http://localhost:8000') –URL of the vllm-mlx server
-
resolutions(list[tuple[int, int]], default:None) –List of (width, height) tuples to test
-
warmup_runs(int, default:1) –Number of warmup runs before measuring
-
image_url(str, default:None) –URL of image to use (default: dog from Wikimedia)
Returns:
-
list[BenchmarkResult]–List of BenchmarkResult objects
Source code in examples/mllm_benchmark.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
examples.mllm_benchmark.print_results
¶
print_results(results: list[BenchmarkResult])
Print benchmark results in a nice table.
Source code in examples/mllm_benchmark.py
examples.mllm_benchmark.save_results
¶
save_results(results: list[BenchmarkResult], output_path: str)
Save benchmark results to JSON file.
Source code in examples/mllm_benchmark.py
examples.mllm_benchmark.main
¶
Source code in examples/mllm_benchmark.py
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.mllm_benchmark.BenchmarkResult · class
examples.mllm_benchmark.BenchmarkResult(resolution: str, width: int, height: int, pixels: int, time_seconds: float, tokens_generated: int, tokens_per_second: float, response_preview: str)
Result from a single benchmark run.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
resolution |
str |
yes |
none |
Required constructor field. |
width |
int |
yes |
none |
Required constructor field. |
height |
int |
yes |
none |
Required constructor field. |
pixels |
int |
yes |
none |
Required constructor field. |
time_seconds |
float |
yes |
none |
Required constructor field. |
tokens_generated |
int |
yes |
none |
Required constructor field. |
tokens_per_second |
float |
yes |
none |
Required constructor field. |
response_preview |
str |
yes |
none |
Required constructor field. |
Returns
- Constructs:
examples.mllm_benchmark.BenchmarkResult
Exceptions and behavior
Class BenchmarkResult declares 0 direct member(s).
No direct raise statement appears in this definition.
examples.mllm_benchmark.download_image · function
Download image from URL and return PIL Image.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
url |
str |
yes |
none |
Required positional or keyword input. |
timeout |
int |
no |
30 |
Optional positional or keyword input; defaults to 30. |
Returns
- Type:
Image.Image - Direct return expressions:
Image.open(io.BytesIO(response.content))
Exceptions and behavior
Function download_image calls requests.get, response.raise_for_status, Image.open, io.BytesIO; returns Image.open(io.BytesIO(response.content)).
No direct raise statement appears in this definition.
examples.mllm_benchmark.resize_image · function
Resize image to specified dimensions.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
img |
Image.Image |
yes |
none |
Required positional or keyword input. |
width |
int |
yes |
none |
Required positional or keyword input. |
height |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Image.Image - Direct return expressions:
img.resize((width, height), Image.Resampling.LANCZOS)
Exceptions and behavior
Function resize_image calls img.resize; returns img.resize((width, height), Image.Resampling.LANCZOS).
No direct raise statement appears in this definition.
examples.mllm_benchmark.image_to_base64 · function
Convert PIL Image to base64 data URL.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
img |
Image.Image |
yes |
none |
Required positional or keyword input. |
format |
str |
no |
'JPEG' |
Optional positional or keyword input; defaults to 'JPEG'. |
Returns
- Type:
str - Direct return expressions:
f'data:{mime};base64,{b64}'
Exceptions and behavior
Function image_to_base64 calls Image.new, background.paste, img.split, img.convert; returns f'data:{mime};base64,{b64}'.
No direct raise statement appears in this definition.
examples.mllm_benchmark.run_mllm_request · function
examples.mllm_benchmark.run_mllm_request(server_url: str, image_b64: str, prompt: str = 'Describe this image in detail. What do you see?', max_tokens: int = 256, model: str = 'default') -> tuple[str, float, int]
Send an MLLM request to the server.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
server_url |
str |
yes |
none |
Required positional or keyword input. |
image_b64 |
str |
yes |
none |
Required positional or keyword input. |
prompt |
str |
no |
'Describe this image in detail. What do you see?' |
Optional positional or keyword input; defaults to 'Describe this image in detail. What do you see?'. |
max_tokens |
int |
no |
256 |
Optional positional or keyword input; defaults to 256. |
model |
str |
no |
'default' |
Optional positional or keyword input; defaults to 'default'. |
Returns
- Type:
tuple[str, float, int] - Direct return expressions:
(text, elapsed, tokens)
Exceptions and behavior
Function run_mllm_request calls time.perf_counter, requests.post, response.raise_for_status, response.json; returns (text, elapsed, tokens).
No direct raise statement appears in this definition.
examples.mllm_benchmark.benchmark_resolution · function
examples.mllm_benchmark.benchmark_resolution(server_url: str, base_image: Image.Image, width: int, height: int, model: str, warmup: bool = False) -> BenchmarkResult
Run benchmark for a specific resolution.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
server_url |
str |
yes |
none |
Required positional or keyword input. |
base_image |
Image.Image |
yes |
none |
Required positional or keyword input. |
width |
int |
yes |
none |
Required positional or keyword input. |
height |
int |
yes |
none |
Required positional or keyword input. |
model |
str |
yes |
none |
Required positional or keyword input. |
warmup |
bool |
no |
False |
Optional positional or keyword input; defaults to False. |
Returns
- Type:
BenchmarkResult - Direct return expressions:
BenchmarkResult(resolution=resolution_name, width=width, height=height, pixels=pixels, time_seconds=elapsed, tokens_gen…
Exceptions and behavior
Function benchmark_resolution calls resize_image, image_to_base64, print, run_mllm_request; returns BenchmarkResult(resolution=resolution_name, width=width, height=height, pixels=pixels, time_seconds=elapsed, tokens_gen….
No direct raise statement appears in this definition.
examples.mllm_benchmark.run_benchmark · function
examples.mllm_benchmark.run_benchmark(server_url: str = 'http://localhost:8000', resolutions: list[tuple[int, int]] = None, warmup_runs: int = 1, image_url: str = None) -> list[BenchmarkResult]
Run full MLLM benchmark across multiple resolutions.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
server_url |
str |
no |
'http://localhost:8000' |
URL of the vllm-mlx server |
resolutions |
list[tuple[int, int]] |
no |
None |
List of (width, height) tuples to test |
warmup_runs |
int |
no |
1 |
Number of warmup runs before measuring |
image_url |
str |
no |
None |
URL of image to use (default: dog from Wikimedia) |
Returns
- Type:
list[BenchmarkResult] - Direct return expressions:
[];results
Exceptions and behavior
Function run_benchmark calls print, requests.get, health.raise_for_status, health.json; has 2 explicit return paths.
No direct raise statement appears in this definition.
examples.mllm_benchmark.print_results · function
Print benchmark results in a nice table.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
results |
list[BenchmarkResult] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
None
Exceptions and behavior
Function print_results calls print, table_data.append, tabulate, sum; returns None.
No direct raise statement appears in this definition.
examples.mllm_benchmark.save_results · function
examples.mllm_benchmark.save_results(results: list[BenchmarkResult], output_path: str) -> not annotated
Save benchmark results to JSON file.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
results |
list[BenchmarkResult] |
yes |
none |
Required positional or keyword input. |
output_path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated
Exceptions and behavior
Function save_results calls time.strftime, open, json.dump, print.
No direct raise statement appears in this definition.
examples.mllm_benchmark.main · function
Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, run_benchmark.
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, run_benchmark.
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 |
|---|---|---|---|---|
BenchmarkResult |
class | BenchmarkResult(resolution: str, width: int, height: int, pixels: int, time_seconds: float, tokens_generated: int, tokens_per_second: float, response_preview: str) |
Result from a single benchmark run. | #L65-L74 |
download_image |
function | download_image(url: str, timeout: int = 30) -> Image.Image |
Download image from URL and return PIL Image. | #L77-L84 |
resize_image |
function | resize_image(img: Image.Image, width: int, height: int) -> Image.Image |
Resize image to specified dimensions. | #L87-L89 |
image_to_base64 |
function | image_to_base64(img: Image.Image, format: str = 'JPEG') -> str |
Convert PIL Image to base64 data URL. | #L92-L106 |
run_mllm_request |
function | run_mllm_request(server_url: str, image_b64: str, prompt: str = 'Describe this image in detail. What do you see?', max_tokens: int = 256, model: str = 'default') -> tuple[str, float, int] |
Send an MLLM request to the server. | #L109-L153 |
benchmark_resolution |
function | benchmark_resolution(server_url: str, base_image: Image.Image, width: int, height: int, model: str, warmup: bool = False) -> BenchmarkResult |
Run benchmark for a specific resolution. | #L156-L198 |
run_benchmark |
function | run_benchmark(server_url: str = 'http://localhost:8000', resolutions: list[tuple[int, int]] = None, warmup_runs: int = 1, image_url: str = None) -> list[BenchmarkResult] |
Run full MLLM benchmark across multiple resolutions. | #L201-L293 |
print_results |
function | print_results(results: list[BenchmarkResult]) -> not annotated |
Print benchmark results in a nice table. | #L296-L338 |
save_results |
function | save_results(results: list[BenchmarkResult], output_path: str) -> not annotated |
Save benchmark results to JSON file. | #L341-L364 |
main |
function | main() -> not annotated |
Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, run_benchmark. |
#L367-L439 |