vllm_mlx.mllm_batch_generator¶
MLLM Batch Generator for multimodal continuous batching.
View the complete module source at #L1-L3073.
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.
vllm_mlx.mllm_batch_generator
¶
MLLM Batch Generator for multimodal continuous batching.
This module implements continuous batching for Multimodal Language Models (MLLMs) like Qwen3-VL, following the same architecture as LLM continuous batching but adapted for vision models.
Key insight: VLM models have a model.language_model which is a standard LLM.
After the initial forward pass with vision encoding, text generation uses only
the language model - which CAN be batched using the same BatchKVCache pattern.
Architecture: 1. Vision inputs are processed per-request (not batched) 2. Initial VLM forward pass extracts cross-attention states / encoder outputs 3. Language model generation is batched using BatchKVCache (like LLM batching)
vllm_mlx.mllm_batch_generator.PrefillAbortedError
¶
Bases: Exception
Raised when a prefill is aborted due to client disconnect.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.PrefillAbortedError.request_id
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest
dataclass
¶
MLLMBatchRequest(uid: int, request_id: str, prompt: str, images: Optional[List[str]] = None, videos: Optional[List[str]] = None, audio: Optional[List[str]] = None, max_tokens: int = 256, temperature: float = 0.7, top_p: float = 0.9, top_k: int = 0, min_p: float = 0.0, presence_penalty: float = 0.0, repetition_penalty: float = 1.0, logits_processors: Optional[List[Callable]] = None, input_ids: Optional[array] = None, pixel_values: Optional[array] = None, attention_mask: Optional[array] = None, image_grid_thw: Optional[array] = None, extra_kwargs: Dict[str, Any] = dict(), is_text_only: bool = False, num_tokens: int = 0, output_tokens: List[int] = list(), vision_encoded: bool = False, cross_attention_states: Optional[Any] = None, encoder_outputs: Optional[Any] = None)
Request data for MLLM batch processing.
Contains all information needed to process a multimodal request within the batch generator.
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.images
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.videos
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.audio
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.max_tokens
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.temperature
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.top_p
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.top_k
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.min_p
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.presence_penalty
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.repetition_penalty
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.logits_processors
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.input_ids
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.pixel_values
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.attention_mask
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.image_grid_thw
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.extra_kwargs
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.is_text_only
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.num_tokens
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.output_tokens
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.vision_encoded
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.cross_attention_states
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchRequest.encoder_outputs
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchResponse
dataclass
¶
MLLMBatchResponse(uid: int, request_id: str, token: int, logprobs: array, finish_reason: Optional[str] = None, prompt_cache: Optional[Callable[[], List[Any]]] = None, from_draft: bool = False, mtp_attempted: bool = False, mtp_attempted_count: int = 0)
Response from a batch generation step.
Contains the generated token and metadata for a single request.
vllm_mlx.mllm_batch_generator.MLLMBatchResponse.finish_reason
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchResponse.prompt_cache
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchResponse.from_draft
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchResponse.mtp_attempted
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchResponse.mtp_attempted_count
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatch
dataclass
¶
MLLMBatch(uids: List[int], request_ids: List[str], y: array, logprobs: List[array], max_tokens: List[int], num_tokens: List[int], cache: List[Any], requests: List[MLLMBatchRequest], logits_processors: Optional[List[Optional[List[Callable]]]] = None, samplers: Optional[List[Optional[Callable]]] = None)
Represents an active batch of MLLM requests.
Manages the batch state including tokens, caches, and metadata for all requests being processed together.
vllm_mlx.mllm_batch_generator.MLLMBatch.requests
instance-attribute
¶
requests: List[MLLMBatchRequest]
vllm_mlx.mllm_batch_generator.MLLMBatch.logits_processors
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatch.samplers
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatch.__len__
¶
vllm_mlx.mllm_batch_generator.MLLMBatch.filter
¶
Filter batch to keep only requests at specified indices.
Parameters:
-
keep_idx(List[int]) –Indices of requests to keep
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatch.extend
¶
extend(other: MLLMBatch) -> None
Extend this batch with another batch.
Parameters:
-
other(MLLMBatch) –Batch to merge into this one
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatch.extract_cache
¶
Extract cache for a single request (for prefix caching).
Handles BatchRotatingKVCache negative left_padding bug: during generation with rotation, left_padding becomes negative, causing extract() to use Python negative indexing and truncate the buffer to only generation tokens instead of the full window.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchStats
¶
Statistics for MLLM batch generation.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchStats.prompt_tokens
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchStats.prompt_time
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchStats.generation_tokens
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchStats.generation_time
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchStats.vision_encoding_time
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchStats.num_images_processed
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchStats.peak_memory
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchStats.prompt_tps
property
¶
Return measured multimodal prompt throughput in tokens per second.
vllm_mlx.mllm_batch_generator.MLLMBatchStats.generation_tps
property
¶
Return measured decode throughput in tokens per second.
vllm_mlx.mllm_batch_generator.MLLMBatchStats.to_dict
¶
Return token, timing, vision, and peak-memory statistics.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator
¶
MLLMBatchGenerator(model: Module, processor: Any, mm_processor: Optional[MultimodalProcessor] = None, max_tokens: int = 256, stop_tokens: Optional[set] = None, sampler: Optional[Callable[[array], array]] = None, prefill_batch_size: int = 4, completion_batch_size: int = 16, prefill_step_size: int = 1024, enable_vision_cache: bool = True, vision_cache_size: int = 100, prefix_cache_config: Optional[MemoryCacheConfig] = None, max_kv_size: int = 0)
Batch generator for Vision Language Models.
This class manages continuous batching for MLLM requests:
- Vision Encoding Phase:
- Process images/videos through vision encoder (per-request)
- Extract vision features and merge with text embeddings
-
Store cross-attention states for language model
-
Language Generation Phase:
- Use language model with BatchKVCache for batched generation
- Generate tokens for all requests simultaneously
- Same pattern as LLM BatchGenerator
Example
generator = MLLMBatchGenerator(model, processor) uids = generator.insert([request1, request2]) while responses := generator.next(): ... for resp in responses: ... print(f"Request {resp.request_id}: token={resp.token}")
Initialize MLLM batch generator.
Parameters:
-
model(Module) –The VLM model (must have model.language_model)
-
processor(Any) –The VLM processor for tokenization and image processing
-
mm_processor(Optional[MultimodalProcessor], default:None) –Optional MultimodalProcessor for input preparation
-
max_tokens(int, default:256) –Default max tokens per request
-
stop_tokens(Optional[set], default:None) –Set of stop token IDs
-
sampler(Optional[Callable[[array], array]], default:None) –Sampling function (default: argmax)
-
prefill_batch_size(int, default:4) –Max requests to prefill together
-
completion_batch_size(int, default:16) –Max requests for completion batching
-
prefill_step_size(int, default:1024) –Tokens to process per prefill step
-
enable_vision_cache(bool, default:True) –Enable vision embedding caching
-
vision_cache_size(int, default:100) –Max entries in vision cache
-
prefix_cache_config(Optional[MemoryCacheConfig], default:None) –Config for KV prefix cache (text-only requests)
-
max_kv_size(int, default:0) –Maximum KV cache size per sequence (0 = unbounded)
Source code in vllm_mlx/mllm_batch_generator.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._stream
class-attribute
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.processor
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.mm_processor
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.max_kv_size
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.language_model
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.is_vlm
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.max_tokens
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.stop_tokens
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.sampler
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.prefill_batch_size
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.completion_batch_size
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.prefill_step_size
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.unprocessed_requests
instance-attribute
¶
unprocessed_requests: List[MLLMBatchRequest] = []
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.active_batch
instance-attribute
¶
active_batch: Optional[MLLMBatch] = None
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._stats
instance-attribute
¶
_stats = MLLMBatchStats()
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._pending_error_responses
instance-attribute
¶
_pending_error_responses: List[MLLMBatchResponse] = []
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._prefill_progress
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._aborted_request_ids
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._pending_removal_uids
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._pending_removal_lock
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.vision_cache
instance-attribute
¶
vision_cache = VisionEmbeddingCache(max_pixel_entries=vision_cache_size, max_encoding_entries=vision_cache_size // 2, enabled=enable_vision_cache)
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.prefix_cache
instance-attribute
¶
prefix_cache: Optional[MemoryAwarePrefixCache] = None
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._think_suffix_len
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._old_wired_limit
instance-attribute
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._normalize_chat_template_for_prefix_cache
¶
Patch chat template so historical assistant turns are prefix-stable.
Qwen3.5's chat template computes last_query_index — the position
of the last non-tool-response user message — and conditionally wraps
assistant turns after that index in <think>...\n</think>\n\n.
When a new user text message is appended, last_query_index jumps
forward, retroactively removing these <think> wrappers from
earlier assistant turns. This shifts tokens mid-sequence and breaks
prefix cache.
Fix: replace the conditional with the plain (ELSE) branch so ALL
historical assistant messages use <|im_start|>assistant\ncontent
without any injected <think> block. The generation prompt still
adds <think>\n at the very end, so the model generates thinking.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._compute_think_suffix_len
¶
Compute how many extra tokens enable_thinking=True adds at the END.
Compares the generation prompt suffix with and without
enable_thinking to find the think-tag suffix length
(typically <think>\n = 2 tokens for Qwen3/Qwen3.5).
Returns 0 if the template doesn't support enable_thinking.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.close
¶
Release resources and reset wired limit.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.abort_prefill
¶
Signal that a request's prefill should be aborted.
Called from the event loop thread when a client disconnects. The prefill loop checks this set between chunks and raises PrefillAbortedError to exit early.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.schedule_removal
¶
Thread-safe deferred removal of UIDs from the batch.
Safe to call from any thread (typically the event loop during
client-disconnect cleanup). The actual remove(), which creates
mx.array instances and filters the KV cache, runs on the
scheduler thread via :meth:process_pending_removals at the next
batch boundary. This avoids the Metal encodeSignalEvent:
uncommitted encoder crash that occurs when two threads submit
GPU work on the same stream concurrently.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.process_pending_removals
¶
Remove any UIDs enqueued via :meth:schedule_removal.
MUST be called from the scheduler thread only, at a safe point
(e.g. the start of :meth:MLLMScheduler.step before any forward
pass has been issued). Safe to call even when the queue is
empty (no-op).
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.__del__
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.insert
¶
insert(requests: List[MLLMBatchRequest]) -> List[int]
Insert requests for batch processing.
Parameters:
-
requests(List[MLLMBatchRequest]) –List of MLLMBatchRequest to process
Returns:
-
List[int]–List of UIDs assigned to requests
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.remove
¶
Remove requests from processing.
Parameters:
-
uids(List[int]) –List of UIDs to remove
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._preprocess_request
¶
_preprocess_request(request: MLLMBatchRequest) -> None
Preprocess a single MLLM request (vision encoding).
This prepares the inputs by: 1. Processing images/videos through the processor 2. Tokenizing the prompt with image tokens 3. Running vision encoder to get features
Uses vision cache to skip processing for repeated images. Idempotent: if input_ids is already set, returns immediately.
Parameters:
-
request(MLLMBatchRequest) –Request to preprocess
Source code in vllm_mlx/mllm_batch_generator.py
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 | |
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._copy_prefix_cache
staticmethod
¶
Create shallow copies of cache objects to prevent mutation of stored prefix cache.
MLX arrays are immutable and safe to share, but cache objects have mutable Python attributes (offset, _idx) that get modified by update_and_fetch(). Without copying, the stored prefix cache entry is corrupted after each use.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._has_empty_rotating_cache
staticmethod
¶
Check if any RotatingKVCache layer has no data (keys=None).
This happens when prefix cache stores a long response where all sliding-window entries were trimmed (entries_to_keep=0). Using such a cache produces garbage — fall through to full prefill.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._trim_rotating_caches
staticmethod
¶
Trim RotatingKVCache buffers restored from prefix cache.
Prefix cache stores the full KV state (offset may exceed max_size for
sliding-window layers). RotatingKVCache._update_in_place computes
new_size = min(step, max_size - prev) which goes negative when
prev > max_size, crashing with "Negative dimensions not allowed".
Trimming the buffer to max_size and clamping offset/idx prevents this.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._run_chunked_text_prefill
¶
_run_chunked_text_prefill(request: MLLMBatchRequest, cache: List[Any]) -> array
Run prefill in chunks for text-only requests, reporting real progress.
Processes input_ids in prefill_step_size chunks through the language
model, updating _prefill_progress after each chunk so the status
endpoint can report accurate prefill percentage.
Returns:
-
array–Logits from the last chunk (same contract as _run_vision_encoding).
Source code in vllm_mlx/mllm_batch_generator.py
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 | |
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._run_vision_encoding
¶
_run_vision_encoding(request: MLLMBatchRequest, cache: Optional[List[Any]] = None) -> array
Run the initial VLM forward pass to encode vision and get first logits.
This runs the full VLM model (vision + language) on the prompt, which encodes the images and fills the provided KV cache.
Parameters:
-
request(MLLMBatchRequest) –Preprocessed request with input_ids and pixel_values
-
cache(Optional[List[Any]], default:None) –KV cache list for the language model. If provided, the language model writes its KV state directly into this cache during the forward pass.
Returns:
-
array–Logits from the forward pass
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._process_prompts
¶
_process_prompts(requests: List[MLLMBatchRequest]) -> MLLMBatch
Process a batch of requests through vision encoding and initial prefill.
For MLLM, this is more complex than LLM: 1. Preprocess each request (tokenize, process images) 2. Run vision encoding per-request with individual KVCache objects 3. Merge individual caches into a BatchKVCache for generation
Parameters:
-
requests(List[MLLMBatchRequest]) –Requests to process
Returns:
-
MLLMBatch–MLLMBatch ready for generation
Source code in vllm_mlx/mllm_batch_generator.py
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 | |
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._step
¶
_step(input_tokens: array, cache: List[Any], logits_processors: Optional[List[Optional[List[Callable]]]] = None, output_tokens: Optional[List[List[int]]] = None, samplers: Optional[List[Optional[Callable]]] = None) -> Tuple[array, List[array]]
Run one generation step through the language model.
Parameters:
-
input_tokens(array) –Input tokens [batch_size, 1] or [batch_size]
-
cache(List[Any]) –BatchKVCache for the language model
-
logits_processors(Optional[List[Optional[List[Callable]]]], default:None) –Per-request logits processors (e.g. repetition penalty)
-
output_tokens(Optional[List[List[int]]], default:None) –Per-request generated tokens so far (needed by processors)
-
samplers(Optional[List[Optional[Callable]]], default:None) –Per-request sampler functions (for top_k/min_p)
Returns:
-
Tuple[array, List[array]]–Tuple of (sampled tokens, logprobs list)
Source code in vllm_mlx/mllm_batch_generator.py
1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 | |
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._next
¶
_next() -> List[MLLMBatchResponse]
Internal next() implementation.
Returns:
-
List[MLLMBatchResponse]–List of MLLMBatchResponse for this step
Source code in vllm_mlx/mllm_batch_generator.py
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 | |
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.next
¶
next() -> List[MLLMBatchResponse]
Generate next token for all requests in the batch.
Returns:
-
List[MLLMBatchResponse]–List of MLLMBatchResponse, one per active request
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.stats
¶
stats() -> MLLMBatchStats
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._maybe_store_prefix_cache
¶
_maybe_store_prefix_cache(batch: MLLMBatch, end_indices: List[int]) -> None
Store KV caches for finished text-only requests into prefix cache.
Must be called BEFORE batch.filter() so that indices are still valid.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.get_prefill_progress
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.get_vision_cache_stats
¶
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.get_prefix_cache_stats
¶
Get KV prefix cache statistics.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.has_pending
¶
vllm_mlx.mllm_batch_generator._processors_can_retire
¶
True when any processor advertises a retire-to-content transition.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator._mark_mtp_attempts_on_primary_responses
¶
_mark_mtp_attempts_on_primary_responses(responses: List[MLLMBatchResponse], attempted_drafts_by_uid: Dict[int, int]) -> None
Mark only responses from steps that actually attempted MTP drafts.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator._drop_retired_processors
¶
_drop_retired_processors(processors: Optional[List[Callable]]) -> tuple[Optional[List[Callable]], int]
Drop retire-capable processors that have completed their work.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator._request_uses_stochastic_sampling
¶
Return whether a request needs sampler-aware speculative verification.
Greedy (temperature 0) requests are excluded regardless of top_p/top_k/ min_p: _sampling_logprobs() collapses to an argmax delta distribution for temperature 0 and never applies those filters, so a greedy request left at a non-default top_p/top_k/min_p is not actually stochastic.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator._sampling_logprobs
¶
Match mlx-lm's request sampler in log-probability space.
Speculative decoding compares the post-filter distributions, not the raw target and draft logits. Keep this transformation here rather than reusing a greedy verifier for sampled requests.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator._residual_logprobs
¶
Return the normalized residual max(target - draft, 0) distribution.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator._accept_sampled_draft
¶
Apply the exact min(1, p/q) stochastic speculative acceptance rule.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator._cache_eval_tensors
¶
Return realized tensors that break lazy cache graphs between chunks.
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator._eval_prompt_cache
¶
Evaluate all cache tensors used by hybrid chunked prefill.
vllm_mlx.mllm_batch_generator._left_pad_prompts
¶
Left-pad prompts to uniform length.
Parameters:
-
prompts(List[List[int]]) –List of token lists
-
max_length(Optional[int], default:None) –Target length (computed if not provided)
Returns:
-
array–Padded prompts as mx.array [batch_size, seq_len]
Source code in vllm_mlx/mllm_batch_generator.py
vllm_mlx.mllm_batch_generator.install_mtp_mllm
¶
install_mtp_mllm(batch_gen: MLLMBatchGenerator, language_model: Any, num_draft_tokens: int = 1) -> None
Install MTP (Multi-Token Prediction) on an MLLMBatchGenerator.
Adapts the always-advance MTP strategy from scheduler._install_mtp for the MLLM batched generation path. Handles hybrid model caches (BatchKVCache for attention + ArraysCache for recurrent layers).
Flow per generation step: 1. Use skip_state logits/hidden OR run model forward -> sample primary 2. MTP head drafts one token 3. Verify [primary, draft] in one model call (always advances cache) 4. Accept: skip_state from pos 1, defer draft for next step emission Reject: trim KV by 2 + restore RNN state + re-advance with primary 5. Draft is emitted in the NEXT generation step after primary
Source code in vllm_mlx/mllm_batch_generator.py
2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 | |
vllm_mlx.mllm_batch_generator.install_chunked_prefill_mllm
¶
install_chunked_prefill_mllm(batch_gen: MLLMBatchGenerator, budget: int = 1024) -> None
Install interleaved prefill/decode on an MLLMBatchGenerator.
When a long text-only request arrives, instead of blocking the entire
event loop for 20-60+ seconds during prefill, this processes ONE chunk
of the new request's prefill per step() call. Between steps the
scheduler yields to the event loop (await asyncio.sleep(0)), so
health/status/metrics endpoints remain responsive.
When an active batch is generating, prefill chunks are interleaved with generation steps to keep throughput for existing requests at 30-50 tok/s.
Parameters:
-
batch_gen(MLLMBatchGenerator) –The MLLMBatchGenerator to patch.
-
budget(int, default:1024) –Max tokens to prefill per step (chunk size).
Source code in vllm_mlx/mllm_batch_generator.py
2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 | |
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.
vllm_mlx.mllm_batch_generator._processors_can_retire · function
True when any processor advertises a retire-to-content transition.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
processors |
Optional[List[Callable]] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
False;bool(processors) and any((isinstance(getattr(p, 'is_retired', None), bool) for p in processors))
Exceptions and behavior
Function _processors_can_retire calls os.getenv, bool, any, isinstance; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator._mark_mtp_attempts_on_primary_responses · function
vllm_mlx.mllm_batch_generator._mark_mtp_attempts_on_primary_responses(responses: List['MLLMBatchResponse'], attempted_drafts_by_uid: Dict[int, int]) -> None
Mark only responses from steps that actually attempted MTP drafts.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
responses |
List['MLLMBatchResponse'] |
yes |
none |
Required positional or keyword input. |
attempted_drafts_by_uid |
Dict[int, int] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Function _mark_mtp_attempts_on_primary_responses calls attempted_drafts_by_uid.pop, attempted_drafts_by_uid.clear.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator._drop_retired_processors · function
vllm_mlx.mllm_batch_generator._drop_retired_processors(processors: Optional[List[Callable]]) -> tuple[Optional[List[Callable]], int]
Drop retire-capable processors that have completed their work.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
processors |
Optional[List[Callable]] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
tuple[Optional[List[Callable]], int] - Direct return expressions:
(processors, 0);(remaining or None, retired_count)
Exceptions and behavior
Function _drop_retired_processors calls getattr, remaining.append; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator._request_uses_stochastic_sampling · function
Return whether a request needs sampler-aware speculative verification.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
False;getattr(request, 'top_p', 1.0) < 1.0 or getattr(request, 'top_k', 0) != 0 or getattr(request, 'min_p', 0.0) != 0.0
Exceptions and behavior
Function _request_uses_stochastic_sampling calls getattr; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator._sampling_logprobs · function
Match mlx-lm's request sampler in log-probability space.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
logits |
mx.array |
yes |
none |
Required positional or keyword input. |
request |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
mx.array - Direct return expressions:
mx.put_along_axis(result, token[:, None], 0.0, axis=-1);logprobs - mx.logsumexp(logprobs, axis=-1, keepdims=True)
Exceptions and behavior
Function _sampling_logprobs calls getattr, mx.logsumexp, mx.argmax, mx.full; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator._residual_logprobs · function
vllm_mlx.mllm_batch_generator._residual_logprobs(target_logprobs: mx.array, draft_logprobs: mx.array) -> mx.array
Return the normalized residual max(target - draft, 0) distribution.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
target_logprobs |
mx.array |
yes |
none |
Required positional or keyword input. |
draft_logprobs |
mx.array |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
mx.array - Direct return expressions:
mx.where(mass > 1e-12, normalized, fallback)
Exceptions and behavior
Function _residual_logprobs calls mx.maximum, mx.exp, mx.sum, mx.where; returns mx.where(mass > 1e-12, normalized, fallback).
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator._accept_sampled_draft · function
vllm_mlx.mllm_batch_generator._accept_sampled_draft(target_logprob: float, draft_logprob: float, uniform_draw: float) -> bool
Apply the exact min(1, p/q) stochastic speculative acceptance rule.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
target_logprob |
float |
yes |
none |
Required positional or keyword input. |
draft_logprob |
float |
yes |
none |
Required positional or keyword input. |
uniform_draw |
float |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
log_acceptance >= 0.0 or math.log(max(uniform_draw, 1e-35)) < log_acceptance
Exceptions and behavior
Function _accept_sampled_draft calls math.log, max; returns log_acceptance >= 0.0 or math.log(max(uniform_draw, 1e-35)) < log_acceptance.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.PrefillAbortedError · class
Raised when a prefill is aborted due to client disconnect.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Constructs:
vllm_mlx.mllm_batch_generator.PrefillAbortedError
Exceptions and behavior
Class PrefillAbortedError derives from Exception and declares 1 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.PrefillAbortedError.__init__ · method
Method PrefillAbortedError.__init__ updates self.request_id; calls super().__init__, super.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated
Exceptions and behavior
Method PrefillAbortedError.__init__ updates self.request_id; calls super().__init__, super.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator._cache_eval_tensors · function
Return realized tensors that break lazy cache graphs between chunks.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache |
List[Any] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
List[Any] - Direct return expressions:
tensors
Exceptions and behavior
Function _cache_eval_tensors calls getattr, tensors.append, isinstance, tensors.extend; returns tensors.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator._eval_prompt_cache · function
Evaluate all cache tensors used by hybrid chunked prefill.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache |
List[Any] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Function _eval_prompt_cache calls _cache_eval_tensors, mx.eval.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchRequest · class
vllm_mlx.mllm_batch_generator.MLLMBatchRequest(uid: int, request_id: str, prompt: str, images: Optional[List[str]] = None, videos: Optional[List[str]] = None, audio: Optional[List[str]] = None, max_tokens: int = 256, temperature: float = 0.7, top_p: float = 0.9, top_k: int = 0, min_p: float = 0.0, presence_penalty: float = 0.0, repetition_penalty: float = 1.0, logits_processors: Optional[List[Callable]] = None, input_ids: Optional[mx.array] = None, pixel_values: Optional[mx.array] = None, attention_mask: Optional[mx.array] = None, image_grid_thw: Optional[mx.array] = None, extra_kwargs: Dict[str, Any] = field(default_factory=dict), is_text_only: bool = False, num_tokens: int = 0, output_tokens: List[int] = field(default_factory=list), vision_encoded: bool = False, cross_attention_states: Optional[Any] = None, encoder_outputs: Optional[Any] = None)
Request data for MLLM batch processing.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
uid |
int |
yes |
none |
Required constructor field. |
request_id |
str |
yes |
none |
Required constructor field. |
prompt |
str |
yes |
none |
Required constructor field. |
images |
Optional[List[str]] |
no |
None |
Optional constructor field; defaults to None. |
videos |
Optional[List[str]] |
no |
None |
Optional constructor field; defaults to None. |
audio |
Optional[List[str]] |
no |
None |
Optional constructor field; defaults to None. |
max_tokens |
int |
no |
256 |
Optional constructor field; defaults to 256. |
temperature |
float |
no |
0.7 |
Optional constructor field; defaults to 0.7. |
top_p |
float |
no |
0.9 |
Optional constructor field; defaults to 0.9. |
top_k |
int |
no |
0 |
Optional constructor field; defaults to 0. |
min_p |
float |
no |
0.0 |
Optional constructor field; defaults to 0.0. |
presence_penalty |
float |
no |
0.0 |
Optional constructor field; defaults to 0.0. |
repetition_penalty |
float |
no |
1.0 |
Optional constructor field; defaults to 1.0. |
logits_processors |
Optional[List[Callable]] |
no |
None |
Optional constructor field; defaults to None. |
input_ids |
Optional[mx.array] |
no |
None |
Optional constructor field; defaults to None. |
pixel_values |
Optional[mx.array] |
no |
None |
Optional constructor field; defaults to None. |
attention_mask |
Optional[mx.array] |
no |
None |
Optional constructor field; defaults to None. |
image_grid_thw |
Optional[mx.array] |
no |
None |
Optional constructor field; defaults to None. |
extra_kwargs |
Dict[str, Any] |
no |
field(default_factory=dict) |
Optional constructor field; defaults to field(default_factory=dict). |
is_text_only |
bool |
no |
False |
Optional constructor field; defaults to False. |
num_tokens |
int |
no |
0 |
Optional constructor field; defaults to 0. |
output_tokens |
List[int] |
no |
field(default_factory=list) |
Optional constructor field; defaults to field(default_factory=list). |
vision_encoded |
bool |
no |
False |
Optional constructor field; defaults to False. |
cross_attention_states |
Optional[Any] |
no |
None |
Optional constructor field; defaults to None. |
encoder_outputs |
Optional[Any] |
no |
None |
Optional constructor field; defaults to None. |
Returns
- Constructs:
vllm_mlx.mllm_batch_generator.MLLMBatchRequest
Exceptions and behavior
Class MLLMBatchRequest declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchResponse · class
vllm_mlx.mllm_batch_generator.MLLMBatchResponse(uid: int, request_id: str, token: int, logprobs: mx.array, finish_reason: Optional[str] = None, prompt_cache: Optional[Callable[[], List[Any]]] = None, from_draft: bool = False, mtp_attempted: bool = False, mtp_attempted_count: int = 0)
Response from a batch generation step.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
uid |
int |
yes |
none |
Required constructor field. |
request_id |
str |
yes |
none |
Required constructor field. |
token |
int |
yes |
none |
Required constructor field. |
logprobs |
mx.array |
yes |
none |
Required constructor field. |
finish_reason |
Optional[str] |
no |
None |
Optional constructor field; defaults to None. |
prompt_cache |
Optional[Callable[[], List[Any]]] |
no |
None |
Optional constructor field; defaults to None. |
from_draft |
bool |
no |
False |
Optional constructor field; defaults to False. |
mtp_attempted |
bool |
no |
False |
Optional constructor field; defaults to False. |
mtp_attempted_count |
int |
no |
0 |
Optional constructor field; defaults to 0. |
Returns
- Constructs:
vllm_mlx.mllm_batch_generator.MLLMBatchResponse
Exceptions and behavior
Class MLLMBatchResponse declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatch · class
vllm_mlx.mllm_batch_generator.MLLMBatch(uids: List[int], request_ids: List[str], y: mx.array, logprobs: List[mx.array], max_tokens: List[int], num_tokens: List[int], cache: List[Any], requests: List[MLLMBatchRequest], logits_processors: Optional[List[Optional[List[Callable]]]] = None, samplers: Optional[List[Optional[Callable]]] = None)
Represents an active batch of MLLM requests.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
uids |
List[int] |
yes |
none |
Required constructor field. |
request_ids |
List[str] |
yes |
none |
Required constructor field. |
y |
mx.array |
yes |
none |
Required constructor field. |
logprobs |
List[mx.array] |
yes |
none |
Required constructor field. |
max_tokens |
List[int] |
yes |
none |
Required constructor field. |
num_tokens |
List[int] |
yes |
none |
Required constructor field. |
cache |
List[Any] |
yes |
none |
Required constructor field. |
requests |
List[MLLMBatchRequest] |
yes |
none |
Required constructor field. |
logits_processors |
Optional[List[Optional[List[Callable]]]] |
no |
None |
Optional constructor field; defaults to None. |
samplers |
Optional[List[Optional[Callable]]] |
no |
None |
Optional constructor field; defaults to None. |
Returns
- Constructs:
vllm_mlx.mllm_batch_generator.MLLMBatch
Exceptions and behavior
Class MLLMBatch declares 4 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatch.__len__ · method
Method MLLMBatch.__len__ calls len; returns len(self.uids).
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
len(self.uids)
Exceptions and behavior
Method MLLMBatch.__len__ calls len; returns len(self.uids).
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatch.filter · method
Filter batch to keep only requests at specified indices.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
keep_idx |
List[int] |
yes |
none |
Indices of requests to keep |
Returns
- Type:
None
Exceptions and behavior
Method MLLMBatch.filter updates self.uids, self.request_ids, self.logprobs, self.max_tokens; calls mx.array, hasattr, c.filter.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatch.extend · method
Extend this batch with another batch.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
other |
'MLLMBatch' |
yes |
none |
Batch to merge into this one |
Returns
- Type:
None
Exceptions and behavior
Method MLLMBatch.extend updates self.y, self.logits_processors, self.samplers; calls self.uids.extend, self.request_ids.extend, mx.concatenate, self.logprobs.extend.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatch.extract_cache · method
Extract cache for a single request (for prefix caching).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
idx |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
List[Any] - Direct return expressions:
result
Exceptions and behavior
Method MLLMBatch.extract_cache calls hasattr, result.append, isinstance, RotatingKVCache; returns result.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchStats · class
Statistics for MLLM batch generation.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.mllm_batch_generator.MLLMBatchStats
Exceptions and behavior
Class MLLMBatchStats declares 4 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchStats.__init__ · method
Method MLLMBatchStats.__init__ updates self.prompt_tokens, self.prompt_time, self.generation_tokens, self.generation_time.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated
Exceptions and behavior
Method MLLMBatchStats.__init__ updates self.prompt_tokens, self.prompt_time, self.generation_tokens, self.generation_time.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchStats.prompt_tps · method
Return measured multimodal prompt throughput in tokens per second.
Parameters
This callable has no explicit inputs.
Returns
- Type:
float - Direct return expressions:
0;self.prompt_tokens / self.prompt_time
Exceptions and behavior
Method MLLMBatchStats.prompt_tps has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchStats.generation_tps · method
Return measured decode throughput in tokens per second.
Parameters
This callable has no explicit inputs.
Returns
- Type:
float - Direct return expressions:
0;self.generation_tokens / self.generation_time
Exceptions and behavior
Method MLLMBatchStats.generation_tps has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchStats.to_dict · method
Return token, timing, vision, and peak-memory statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Dict[str, Any] - Direct return expressions:
{'prompt_tokens': self.prompt_tokens, 'prompt_time': self.prompt_time, 'prompt_tps': self.prompt_tps, 'generation_token…
Exceptions and behavior
Method MLLMBatchStats.to_dict returns {'prompt_tokens': self.prompt_tokens, 'prompt_time': self.prompt_time, 'prompt_tps': self.prompt_tps, 'generation_token….
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator._left_pad_prompts · function
vllm_mlx.mllm_batch_generator._left_pad_prompts(prompts: List[List[int]], max_length: Optional[int] = None) -> mx.array
Left-pad prompts to uniform length.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
prompts |
List[List[int]] |
yes |
none |
List of token lists |
max_length |
Optional[int] |
no |
None |
Target length (computed if not provided) |
Returns
- Type:
mx.array - Direct return expressions:
mx.array([[0] * (max_length - len(p)) + list(p) for p in prompts])
Exceptions and behavior
Function _left_pad_prompts calls max, len, mx.array, list; returns mx.array([[0] * (max_length - len(p)) + list(p) for p in prompts]).
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator · class
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator(model: nn.Module, processor: Any, mm_processor: Optional[MultimodalProcessor] = None, max_tokens: int = 256, stop_tokens: Optional[set] = None, sampler: Optional[Callable[[mx.array], mx.array]] = None, prefill_batch_size: int = 4, completion_batch_size: int = 16, prefill_step_size: int = 1024, enable_vision_cache: bool = True, vision_cache_size: int = 100, prefix_cache_config: Optional[MemoryCacheConfig] = None, max_kv_size: int = 0)
Batch generator for Vision Language Models.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model |
nn.Module |
yes |
none |
The VLM model (must have model.language_model) |
processor |
Any |
yes |
none |
The VLM processor for tokenization and image processing |
mm_processor |
Optional[MultimodalProcessor] |
no |
None |
Optional MultimodalProcessor for input preparation |
max_tokens |
int |
no |
256 |
Default max tokens per request |
stop_tokens |
Optional[set] |
no |
None |
Set of stop token IDs |
sampler |
Optional[Callable[[mx.array], mx.array]] |
no |
None |
Sampling function (default: argmax) |
prefill_batch_size |
int |
no |
4 |
Max requests to prefill together |
completion_batch_size |
int |
no |
16 |
Max requests for completion batching |
prefill_step_size |
int |
no |
1024 |
Tokens to process per prefill step |
enable_vision_cache |
bool |
no |
True |
Enable vision embedding caching |
vision_cache_size |
int |
no |
100 |
Max entries in vision cache |
prefix_cache_config |
Optional[MemoryCacheConfig] |
no |
None |
Config for KV prefix cache (text-only requests) |
max_kv_size |
int |
no |
0 |
Maximum KV cache size per sequence (0 = unbounded) |
Returns
- Constructs:
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator
Exceptions and behavior
Class MLLMBatchGenerator declares 26 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.__init__ · method
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.__init__(model: nn.Module, processor: Any, mm_processor: Optional[MultimodalProcessor] = None, max_tokens: int = 256, stop_tokens: Optional[set] = None, sampler: Optional[Callable[[mx.array], mx.array]] = None, prefill_batch_size: int = 4, completion_batch_size: int = 16, prefill_step_size: int = 1024, enable_vision_cache: bool = True, vision_cache_size: int = 100, prefix_cache_config: Optional[MemoryCacheConfig] = None, max_kv_size: int = 0) -> not annotated
Initialize MLLM batch generator.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model |
nn.Module |
yes |
none |
The VLM model (must have model.language_model) |
processor |
Any |
yes |
none |
The VLM processor for tokenization and image processing |
mm_processor |
Optional[MultimodalProcessor] |
no |
None |
Optional MultimodalProcessor for input preparation |
max_tokens |
int |
no |
256 |
Default max tokens per request |
stop_tokens |
Optional[set] |
no |
None |
Set of stop token IDs |
sampler |
Optional[Callable[[mx.array], mx.array]] |
no |
None |
Sampling function (default: argmax) |
prefill_batch_size |
int |
no |
4 |
Max requests to prefill together |
completion_batch_size |
int |
no |
16 |
Max requests for completion batching |
prefill_step_size |
int |
no |
1024 |
Tokens to process per prefill step |
enable_vision_cache |
bool |
no |
True |
Enable vision embedding caching |
vision_cache_size |
int |
no |
100 |
Max entries in vision cache |
prefix_cache_config |
Optional[MemoryCacheConfig] |
no |
None |
Config for KV prefix cache (text-only requests) |
max_kv_size |
int |
no |
0 |
Maximum KV cache size per sequence (0 = unbounded) |
Returns
- Type:
not annotated
Exceptions and behavior
Method MLLMBatchGenerator.__init__ updates self.model, self.processor, self.mm_processor, self.max_kv_size; calls getattr, hasattr, logger.info, logger.warning.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._normalize_chat_template_for_prefix_cache · method
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._normalize_chat_template_for_prefix_cache() -> None
Patch chat template so historical assistant turns are prefix-stable.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method MLLMBatchGenerator._normalize_chat_template_for_prefix_cache updates self.processor.chat_template; calls getattr, re.sub, hasattr, logger.info; returns None.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._compute_think_suffix_len · method
Compute how many extra tokens enable_thinking=True adds at the END.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
0;max(0, suffix_len)
Exceptions and behavior
Method MLLMBatchGenerator._compute_think_suffix_len calls getattr, hasattr, applicator.apply_chat_template, text_with.endswith; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.close · method
Release resources and reset wired limit.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method MLLMBatchGenerator.close updates self._old_wired_limit; calls mx.synchronize, mx.set_wired_limit.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.abort_prefill · method
Signal that a request's prefill should be aborted.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method MLLMBatchGenerator.abort_prefill calls self._aborted_request_ids.add, logger.info.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.schedule_removal · method
Thread-safe deferred removal of UIDs from the batch.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
uids |
List[int] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method MLLMBatchGenerator.schedule_removal calls self._pending_removal_uids.update.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.process_pending_removals · method
Remove any UIDs enqueued via :meth:schedule_removal.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method MLLMBatchGenerator.process_pending_removals updates self._pending_removal_uids; calls set, list, self.remove; returns None.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.__del__ · method
Method MLLMBatchGenerator.__del__ calls self.close.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated
Exceptions and behavior
Method MLLMBatchGenerator.__del__ calls self.close.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.insert · method
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.insert(requests: List[MLLMBatchRequest]) -> List[int]
Insert requests for batch processing.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
requests |
List[MLLMBatchRequest] |
yes |
none |
List of MLLMBatchRequest to process |
Returns
- Type:
List[int] - Direct return expressions:
uids
Exceptions and behavior
Method MLLMBatchGenerator.insert updates self.uid_counter, self.unprocessed_requests; calls self.unprocessed_requests.append, uids.append, sorted, logger.debug; returns uids.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.remove · method
Remove requests from processing.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
uids |
List[int] |
yes |
none |
List of UIDs to remove |
Returns
- Type:
None
Exceptions and behavior
Method MLLMBatchGenerator.remove updates self.active_batch, self.unprocessed_requests; calls set, enumerate, self.active_batch.filter.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._preprocess_request · method
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._preprocess_request(request: MLLMBatchRequest) -> None
Preprocess a single MLLM request (vision encoding).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request |
MLLMBatchRequest |
yes |
none |
Request to preprocess |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method MLLMBatchGenerator._preprocess_request updates self._stats.num_images_processed, self._stats.vision_encoding_time; calls time.perf_counter, process_image_input, all_images.append, logger.warning; returns None.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._copy_prefix_cache · method
Create shallow copies of cache objects to prevent mutation of stored prefix cache.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache_list |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
copies
Exceptions and behavior
Method MLLMBatchGenerator._copy_prefix_cache calls isinstance, RotatingKVCache, copies.append, KVCache; returns copies.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._has_empty_rotating_cache · method
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._has_empty_rotating_cache(cache_list) -> not annotated
Check if any RotatingKVCache layer has no data (keys=None).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache_list |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
True;False
Exceptions and behavior
Method MLLMBatchGenerator._has_empty_rotating_cache calls isinstance; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._trim_rotating_caches · method
Trim RotatingKVCache buffers restored from prefix cache.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache_list |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated
Exceptions and behavior
Method MLLMBatchGenerator._trim_rotating_caches calls isinstance, layer_cache._trim, min, logger.warning.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._run_chunked_text_prefill · method
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._run_chunked_text_prefill(request: MLLMBatchRequest, cache: List[Any]) -> mx.array
Run prefill in chunks for text-only requests, reporting real progress.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request |
MLLMBatchRequest |
yes |
none |
Required positional or keyword input. |
cache |
List[Any] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
mx.array - Direct return expressions:
output.logits;output
Exceptions and behavior
Method MLLMBatchGenerator._run_chunked_text_prefill calls self.language_model, request.extra_kwargs.clear, hasattr, logger.info; can raise PrefillAbortedError; has 2 explicit return paths.
Directly raised exceptions: PrefillAbortedError.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._run_vision_encoding · method
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._run_vision_encoding(request: MLLMBatchRequest, cache: Optional[List[Any]] = None) -> mx.array
Run the initial VLM forward pass to encode vision and get first logits.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request |
MLLMBatchRequest |
yes |
none |
Preprocessed request with input_ids and pixel_values |
cache |
Optional[List[Any]] |
no |
None |
KV cache list for the language model. If provided, the language model writes its KV state directly into this cache during the forward pass. |
Returns
- Type:
mx.array - Direct return expressions:
output.logits;output
Exceptions and behavior
Method MLLMBatchGenerator._run_vision_encoding calls dict, self.model, request.extra_kwargs.clear, hasattr; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._process_prompts · method
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._process_prompts(requests: List[MLLMBatchRequest]) -> MLLMBatch
Process a batch of requests through vision encoding and initial prefill.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
requests |
List[MLLMBatchRequest] |
yes |
none |
Requests to process |
Returns
- Type:
MLLMBatch - Direct return expressions:
None;MLLMBatch(uids=[req.uid for req in requests], request_ids=[req.request_id for req in requests], y=y, logprobs=all_logpr…
Exceptions and behavior
Method MLLMBatchGenerator._process_prompts updates self._stats.prompt_tokens, self._stats.prompt_time; calls time.perf_counter, self._preprocess_request, logger.error, type; can raise PrefillAbortedError; has 2 explicit return paths.
Directly raised exceptions: PrefillAbortedError.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._process_prompts._sample_first_token · nested function
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._process_prompts._sample_first_token(req: MLLMBatchRequest, logits: mx.array) -> not annotated
Nested Function MLLMBatchGenerator._process_prompts._sample_first_token calls logits_processors_by_request.get, mx.array, processor, mx.logsumexp; returns (sampled, logprobs).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
req |
MLLMBatchRequest |
yes |
none |
Required positional or keyword input. |
logits |
mx.array |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
(sampled, logprobs)
Exceptions and behavior
Nested Function MLLMBatchGenerator._process_prompts._sample_first_token calls logits_processors_by_request.get, mx.array, processor, mx.logsumexp; returns (sampled, logprobs).
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._step · method
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._step(input_tokens: mx.array, cache: List[Any], logits_processors: Optional[List[Optional[List[Callable]]]] = None, output_tokens: Optional[List[List[int]]] = None, samplers: Optional[List[Optional[Callable]]] = None) -> Tuple[mx.array, List[mx.array]]
Run one generation step through the language model.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
input_tokens |
mx.array |
yes |
none |
Input tokens [batch_size, 1] or [batch_size] |
cache |
List[Any] |
yes |
none |
BatchKVCache for the language model |
logits_processors |
Optional[List[Optional[List[Callable]]]] |
no |
None |
Per-request logits processors (e.g. repetition penalty) |
output_tokens |
Optional[List[List[int]]] |
no |
None |
Per-request generated tokens so far (needed by processors) |
samplers |
Optional[List[Optional[Callable]]] |
no |
None |
Per-request sampler functions (for top_k/min_p) |
Returns
- Type:
Tuple[mx.array, List[mx.array]] - Direct return expressions:
(sampled, list(logprobs))
Exceptions and behavior
Method MLLMBatchGenerator._step calls self.language_model, hasattr, any, range; returns (sampled, list(logprobs)).
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._next · method
Internal next() implementation.
Parameters
This callable has no explicit inputs.
Returns
- Type:
List[MLLMBatchResponse] - Direct return expressions:
[];error_responses;error_responses + responses
Exceptions and behavior
Method MLLMBatchGenerator._next updates self.active_batch, self.unprocessed_requests, self._stats.prompt_time, self._stats.generation_time; calls time.perf_counter, len, self._process_prompts, logger.error; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.next · method
Generate next token for all requests in the batch.
Parameters
This callable has no explicit inputs.
Returns
- Type:
List[MLLMBatchResponse] - Direct return expressions:
self._next()
Exceptions and behavior
Method MLLMBatchGenerator.next calls mx.stream, self._next; returns self._next().
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.stats · method
Get generation statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
MLLMBatchStats - Direct return expressions:
self._stats
Exceptions and behavior
Method MLLMBatchGenerator.stats updates self._stats.peak_memory; calls mx.get_peak_memory; returns self._stats.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._maybe_store_prefix_cache · method
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator._maybe_store_prefix_cache(batch: MLLMBatch, end_indices: List[int]) -> None
Store KV caches for finished text-only requests into prefix cache.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
batch |
MLLMBatch |
yes |
none |
Required positional or keyword input. |
end_indices |
List[int] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method MLLMBatchGenerator._maybe_store_prefix_cache calls batch.extract_cache, req.input_ids.reshape(-1).tolist, req.input_ids.reshape, _trim_cache_offset; returns None.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.get_prefill_progress · method
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.get_prefill_progress(request_id: str) -> Optional[Tuple[int, int]]
Return (processed_tokens, total_tokens) or None.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Optional[Tuple[int, int]] - Direct return expressions:
self._prefill_progress.get(request_id)
Exceptions and behavior
Method MLLMBatchGenerator.get_prefill_progress calls self._prefill_progress.get; returns self._prefill_progress.get(request_id).
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.get_vision_cache_stats · method
Get vision cache statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Dict[str, Any] - Direct return expressions:
self.vision_cache.get_stats()
Exceptions and behavior
Method MLLMBatchGenerator.get_vision_cache_stats calls self.vision_cache.get_stats; returns self.vision_cache.get_stats().
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.get_prefix_cache_stats · method
Get KV prefix cache statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Dict[str, Any] - Direct return expressions:
self.prefix_cache.get_stats();{'hits': 0, 'misses': 0, 'hit_rate': 0.0, 'evictions': 0, 'tokens_saved': 0, 'current_memory_mb': 0.0, 'max_memory_mb':…
Exceptions and behavior
Method MLLMBatchGenerator.get_prefix_cache_stats calls self.prefix_cache.get_stats; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.MLLMBatchGenerator.has_pending · method
Check if there are pending or active requests.
Parameters
This callable has no explicit inputs.
Returns
- Type:
bool - Direct return expressions:
bool(self.unprocessed_requests or self.active_batch)
Exceptions and behavior
Method MLLMBatchGenerator.has_pending calls bool; returns bool(self.unprocessed_requests or self.active_batch).
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.install_mtp_mllm · function
vllm_mlx.mllm_batch_generator.install_mtp_mllm(batch_gen: 'MLLMBatchGenerator', language_model: Any, num_draft_tokens: int = 1) -> None
Install MTP (Multi-Token Prediction) on an MLLMBatchGenerator.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
batch_gen |
'MLLMBatchGenerator' |
yes |
none |
Required positional or keyword input. |
language_model |
Any |
yes |
none |
Required positional or keyword input. |
num_draft_tokens |
int |
no |
1 |
Optional positional or keyword input; defaults to 1. |
Returns
- Type:
None
Exceptions and behavior
Function install_mtp_mllm calls make_sampler, threading.Lock, logger.warning, logger.info.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.install_mtp_mllm._get_mtp_stats · nested function
Nested Function install_mtp_mllm._get_mtp_stats calls dict; returns {'enabled': True, 'requested_draft_tokens': num_draft_tokens, 'effective_draft_tokens': 1, 'mode': 'request_local_sampl….
Parameters
This callable has no explicit inputs.
Returns
- Type:
Dict[str, Any] - Direct return expressions:
{'enabled': True, 'requested_draft_tokens': num_draft_tokens, 'effective_draft_tokens': 1, 'mode': 'request_local_sampl…
Exceptions and behavior
Nested Function install_mtp_mllm._get_mtp_stats calls dict; returns {'enabled': True, 'requested_draft_tokens': num_draft_tokens, 'effective_draft_tokens': 1, 'mode': 'request_local_sampl….
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.install_mtp_mllm._mtp_step · nested function
vllm_mlx.mllm_batch_generator.install_mtp_mllm._mtp_step(input_tokens: mx.array, cache: List[Any], logits_processors: Optional[List[Optional[List[Callable]]]] = None, output_tokens: Optional[List[List[int]]] = None, samplers: Optional[List[Optional[Callable]]] = None) -> Tuple[mx.array, List[mx.array]]
Extended _step with MTP always-advance strategy.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
input_tokens |
mx.array |
yes |
none |
Required positional or keyword input. |
cache |
List[Any] |
yes |
none |
Required positional or keyword input. |
logits_processors |
Optional[List[Optional[List[Callable]]]] |
no |
None |
Optional positional or keyword input; defaults to None. |
output_tokens |
Optional[List[List[int]]] |
no |
None |
Optional positional or keyword input; defaults to None. |
samplers |
Optional[List[Optional[Callable]]] |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
Tuple[mx.array, List[mx.array]] - Direct return expressions:
_orig_step(input_tokens, cache, logits_processors, output_tokens, samplers);(primary_tokens, list(logprobs))
Exceptions and behavior
Nested Function install_mtp_mllm._mtp_step calls list, any, _skip_state_by_uid.clear, _orig_step; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.install_mtp_mllm._mtp_next · nested function
Wrapper around _next that emits deferred MTP draft tokens.
Parameters
This callable has no explicit inputs.
Returns
- Type:
List[MLLMBatchResponse] - Direct return expressions:
augmented
Exceptions and behavior
Nested Function install_mtp_mllm._mtp_next calls _skip_state_by_uid.clear, _deferred_drafts.clear, _attempted_drafts_by_uid.clear, _deferred_drafts.pop; returns augmented.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.install_chunked_prefill_mllm · function
vllm_mlx.mllm_batch_generator.install_chunked_prefill_mllm(batch_gen: 'MLLMBatchGenerator', budget: int = 1024) -> None
Install interleaved prefill/decode on an MLLMBatchGenerator.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
batch_gen |
'MLLMBatchGenerator' |
yes |
none |
The MLLMBatchGenerator to patch. |
budget |
int |
no |
1024 |
Max tokens to prefill per step (chunk size). |
Returns
- Type:
None
Exceptions and behavior
Function install_chunked_prefill_mllm calls logger.info.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.install_chunked_prefill_mllm._generation_step · nested function
vllm_mlx.mllm_batch_generator.install_chunked_prefill_mllm._generation_step() -> List[MLLMBatchResponse]
Run one generation step for the active batch.
Parameters
This callable has no explicit inputs.
Returns
- Type:
List[MLLMBatchResponse] - Direct return expressions:
error_responses;error_responses + responses
Exceptions and behavior
Nested Function install_chunked_prefill_mllm._generation_step calls list, batch_gen._pending_error_responses.clear, time.perf_counter, batch_gen._step; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.install_chunked_prefill_mllm._chunked_next · nested function
vllm_mlx.mllm_batch_generator.install_chunked_prefill_mllm._chunked_next() -> List[MLLMBatchResponse]
Interleaved prefill/decode: one prefill chunk + one gen step.
Parameters
This callable has no explicit inputs.
Returns
- Type:
List[MLLMBatchResponse] - Direct return expressions:
_generation_step();[];_orig_next()
Exceptions and behavior
Nested Function install_chunked_prefill_mllm._chunked_next calls batch_gen._aborted_request_ids.discard, mx.clear_cache, batch_gen._prefill_progress.pop, batch_gen._pending_error_responses.append; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_batch_generator.install_chunked_prefill_mllm._patched_remove · nested function
Nested Function install_chunked_prefill_mllm._patched_remove calls set, mx.clear_cache, _orig_remove.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
uids |
List[int] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Nested Function install_chunked_prefill_mllm._patched_remove calls set, mx.clear_cache, _orig_remove.
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 |
|---|---|---|---|---|
_processors_can_retire |
function | _processors_can_retire(processors: Optional[List[Callable]]) -> bool |
True when any processor advertises a retire-to-content transition. | #L37-L43 |
_mark_mtp_attempts_on_primary_responses |
function | _mark_mtp_attempts_on_primary_responses(responses: List['MLLMBatchResponse'], attempted_drafts_by_uid: Dict[int, int]) -> None |
Mark only responses from steps that actually attempted MTP drafts. | #L46-L57 |
_drop_retired_processors |
function | _drop_retired_processors(processors: Optional[List[Callable]]) -> tuple[Optional[List[Callable]], int] |
Drop retire-capable processors that have completed their work. | #L60-L74 |
_request_uses_stochastic_sampling |
function | _request_uses_stochastic_sampling(request: Any) -> bool |
Return whether a request needs sampler-aware speculative verification. | #L77-L92 |
_sampling_logprobs |
function | _sampling_logprobs(logits: mx.array, request: Any) -> mx.array |
Match mlx-lm's request sampler in log-probability space. | #L95-L123 |
_residual_logprobs |
function | _residual_logprobs(target_logprobs: mx.array, draft_logprobs: mx.array) -> mx.array |
Return the normalized residual max(target - draft, 0) distribution. | #L126-L139 |
_accept_sampled_draft |
function | _accept_sampled_draft(target_logprob: float, draft_logprob: float, uniform_draw: float) -> bool |
Apply the exact min(1, p/q) stochastic speculative acceptance rule. | #L142-L149 |
PrefillAbortedError |
class | PrefillAbortedError(request_id: str) |
Raised when a prefill is aborted due to client disconnect. | #L152-L157 |
PrefillAbortedError.__init__ |
method | PrefillAbortedError.__init__(request_id: str) -> not annotated |
Method PrefillAbortedError.__init__ updates self.request_id; calls super().__init__, super. |
#L155-L157 |
_cache_eval_tensors |
function | _cache_eval_tensors(cache: List[Any]) -> List[Any] |
Return realized tensors that break lazy cache graphs between chunks. | #L160-L183 |
_eval_prompt_cache |
function | _eval_prompt_cache(cache: List[Any]) -> None |
Evaluate all cache tensors used by hybrid chunked prefill. | #L186-L190 |
MLLMBatchRequest |
class | MLLMBatchRequest(uid: int, request_id: str, prompt: str, images: Optional[List[str]] = None, videos: Optional[List[str]] = None, audio: Optional[List[str]] = None, max_tokens: int = 256, temperature: float = 0.7, top_p: float = 0.9, top_k: int = 0, min_p: float = 0.0, presence_penalty: float = 0.0, repetition_penalty: float = 1.0, logits_processors: Optional[List[Callable]] = None, input_ids: Optional[mx.array] = None, pixel_values: Optional[mx.array] = None, attention_mask: Optional[mx.array] = None, image_grid_thw: Optional[mx.array] = None, extra_kwargs: Dict[str, Any] = field(default_factory=dict), is_text_only: bool = False, num_tokens: int = 0, output_tokens: List[int] = field(default_factory=list), vision_encoded: bool = False, cross_attention_states: Optional[Any] = None, encoder_outputs: Optional[Any] = None) |
Request data for MLLM batch processing. | #L194-L237 |
MLLMBatchResponse |
class | MLLMBatchResponse(uid: int, request_id: str, token: int, logprobs: mx.array, finish_reason: Optional[str] = None, prompt_cache: Optional[Callable[[], List[Any]]] = None, from_draft: bool = False, mtp_attempted: bool = False, mtp_attempted_count: int = 0) |
Response from a batch generation step. | #L241-L256 |
MLLMBatch |
class | MLLMBatch(uids: List[int], request_ids: List[str], y: mx.array, logprobs: List[mx.array], max_tokens: List[int], num_tokens: List[int], cache: List[Any], requests: List[MLLMBatchRequest], logits_processors: Optional[List[Optional[List[Callable]]]] = None, samplers: Optional[List[Optional[Callable]]] = None) |
Represents an active batch of MLLM requests. | #L260-L392 |
MLLMBatch.__len__ |
method | MLLMBatch.__len__() -> int |
Method MLLMBatch.__len__ calls len; returns len(self.uids). |
#L279-L280 |
MLLMBatch.filter |
method | MLLMBatch.filter(keep_idx: List[int]) -> None |
Filter batch to keep only requests at specified indices. | #L282-L306 |
MLLMBatch.extend |
method | MLLMBatch.extend(other: 'MLLMBatch') -> None |
Extend this batch with another batch. | #L308-L351 |
MLLMBatch.extract_cache |
method | MLLMBatch.extract_cache(idx: int) -> List[Any] |
Extract cache for a single request (for prefix caching). | #L353-L392 |
MLLMBatchStats |
class | MLLMBatchStats() |
Statistics for MLLM batch generation. | #L395-L436 |
MLLMBatchStats.__init__ |
method | MLLMBatchStats.__init__() -> not annotated |
Method MLLMBatchStats.__init__ updates self.prompt_tokens, self.prompt_time, self.generation_tokens, self.generation_time. |
#L398-L405 |
MLLMBatchStats.prompt_tps |
method | MLLMBatchStats.prompt_tps() -> float |
Return measured multimodal prompt throughput in tokens per second. | #L408-L413 |
MLLMBatchStats.generation_tps |
method | MLLMBatchStats.generation_tps() -> float |
Return measured decode throughput in tokens per second. | #L416-L421 |
MLLMBatchStats.to_dict |
method | MLLMBatchStats.to_dict() -> Dict[str, Any] |
Return token, timing, vision, and peak-memory statistics. | #L423-L436 |
_left_pad_prompts |
function | _left_pad_prompts(prompts: List[List[int]], max_length: Optional[int] = None) -> mx.array |
Left-pad prompts to uniform length. | #L439-L454 |
MLLMBatchGenerator |
class | MLLMBatchGenerator(model: nn.Module, processor: Any, mm_processor: Optional[MultimodalProcessor] = None, max_tokens: int = 256, stop_tokens: Optional[set] = None, sampler: Optional[Callable[[mx.array], mx.array]] = None, prefill_batch_size: int = 4, completion_batch_size: int = 16, prefill_step_size: int = 1024, enable_vision_cache: bool = True, vision_cache_size: int = 100, prefix_cache_config: Optional[MemoryCacheConfig] = None, max_kv_size: int = 0) |
Batch generator for Vision Language Models. | #L457-L2042 |
MLLMBatchGenerator.__init__ |
method | MLLMBatchGenerator.__init__(model: nn.Module, processor: Any, mm_processor: Optional[MultimodalProcessor] = None, max_tokens: int = 256, stop_tokens: Optional[set] = None, sampler: Optional[Callable[[mx.array], mx.array]] = None, prefill_batch_size: int = 4, completion_batch_size: int = 16, prefill_step_size: int = 1024, enable_vision_cache: bool = True, vision_cache_size: int = 100, prefix_cache_config: Optional[MemoryCacheConfig] = None, max_kv_size: int = 0) -> not annotated |
Initialize MLLM batch generator. | #L484-L632 |
MLLMBatchGenerator._normalize_chat_template_for_prefix_cache |
method | MLLMBatchGenerator._normalize_chat_template_for_prefix_cache() -> None |
Patch chat template so historical assistant turns are prefix-stable. | #L634-L697 |
MLLMBatchGenerator._compute_think_suffix_len |
method | MLLMBatchGenerator._compute_think_suffix_len() -> int |
Compute how many extra tokens enable_thinking=True adds at the END. | #L699-L758 |
MLLMBatchGenerator.close |
method | MLLMBatchGenerator.close() -> None |
Release resources and reset wired limit. | #L760-L765 |
MLLMBatchGenerator.abort_prefill |
method | MLLMBatchGenerator.abort_prefill(request_id: str) -> None |
Signal that a request's prefill should be aborted. | #L767-L775 |
MLLMBatchGenerator.schedule_removal |
method | MLLMBatchGenerator.schedule_removal(uids: List[int]) -> None |
Thread-safe deferred removal of UIDs from the batch. | #L777-L789 |
MLLMBatchGenerator.process_pending_removals |
method | MLLMBatchGenerator.process_pending_removals() -> None |
Remove any UIDs enqueued via :meth:schedule_removal. |
#L791-L808 |
MLLMBatchGenerator.__del__ |
method | MLLMBatchGenerator.__del__() -> not annotated |
Method MLLMBatchGenerator.__del__ calls self.close. |
#L810-L814 |
MLLMBatchGenerator.insert |
method | MLLMBatchGenerator.insert(requests: List[MLLMBatchRequest]) -> List[int] |
Insert requests for batch processing. | #L816-L846 |
MLLMBatchGenerator.remove |
method | MLLMBatchGenerator.remove(uids: List[int]) -> None |
Remove requests from processing. | #L848-L870 |
MLLMBatchGenerator._preprocess_request |
method | MLLMBatchGenerator._preprocess_request(request: MLLMBatchRequest) -> None |
Preprocess a single MLLM request (vision encoding). | #L872-L1023 |
MLLMBatchGenerator._copy_prefix_cache |
method | MLLMBatchGenerator._copy_prefix_cache(cache_list) -> not annotated |
Create shallow copies of cache objects to prevent mutation of stored prefix cache. | #L1026-L1054 |
MLLMBatchGenerator._has_empty_rotating_cache |
method | MLLMBatchGenerator._has_empty_rotating_cache(cache_list) -> not annotated |
Check if any RotatingKVCache layer has no data (keys=None). | #L1057-L1069 |
MLLMBatchGenerator._trim_rotating_caches |
method | MLLMBatchGenerator._trim_rotating_caches(cache_list) -> not annotated |
Trim RotatingKVCache buffers restored from prefix cache. | #L1072-L1106 |
MLLMBatchGenerator._run_chunked_text_prefill |
method | MLLMBatchGenerator._run_chunked_text_prefill(request: MLLMBatchRequest, cache: List[Any]) -> mx.array |
Run prefill in chunks for text-only requests, reporting real progress. | #L1108-L1206 |
MLLMBatchGenerator._run_vision_encoding |
method | MLLMBatchGenerator._run_vision_encoding(request: MLLMBatchRequest, cache: Optional[List[Any]] = None) -> mx.array |
Run the initial VLM forward pass to encode vision and get first logits. | #L1208-L1258 |
MLLMBatchGenerator._process_prompts |
method | MLLMBatchGenerator._process_prompts(requests: List[MLLMBatchRequest]) -> MLLMBatch |
Process a batch of requests through vision encoding and initial prefill. | #L1260-L1682 |
MLLMBatchGenerator._process_prompts._sample_first_token |
nested function | MLLMBatchGenerator._process_prompts._sample_first_token(req: MLLMBatchRequest, logits: mx.array) -> not annotated |
Nested Function MLLMBatchGenerator._process_prompts._sample_first_token calls logits_processors_by_request.get, mx.array, processor, mx.logsumexp; returns (sampled, logprobs). |
#L1348-L1362 |
MLLMBatchGenerator._step |
method | MLLMBatchGenerator._step(input_tokens: mx.array, cache: List[Any], logits_processors: Optional[List[Optional[List[Callable]]]] = None, output_tokens: Optional[List[List[int]]] = None, samplers: Optional[List[Optional[Callable]]] = None) -> Tuple[mx.array, List[mx.array]] |
Run one generation step through the language model. | #L1684-L1746 |
MLLMBatchGenerator._next |
method | MLLMBatchGenerator._next() -> List[MLLMBatchResponse] |
Internal next() implementation. | #L1748-L1964 |
MLLMBatchGenerator.next |
method | MLLMBatchGenerator.next() -> List[MLLMBatchResponse] |
Generate next token for all requests in the batch. | #L1966-L1974 |
MLLMBatchGenerator.stats |
method | MLLMBatchGenerator.stats() -> MLLMBatchStats |
Get generation statistics. | #L1976-L1984 |
MLLMBatchGenerator._maybe_store_prefix_cache |
method | MLLMBatchGenerator._maybe_store_prefix_cache(batch: MLLMBatch, end_indices: List[int]) -> None |
Store KV caches for finished text-only requests into prefix cache. | #L1986-L2014 |
MLLMBatchGenerator.get_prefill_progress |
method | MLLMBatchGenerator.get_prefill_progress(request_id: str) -> Optional[Tuple[int, int]] |
Return (processed_tokens, total_tokens) or None. | #L2016-L2018 |
MLLMBatchGenerator.get_vision_cache_stats |
method | MLLMBatchGenerator.get_vision_cache_stats() -> Dict[str, Any] |
Get vision cache statistics. | #L2020-L2022 |
MLLMBatchGenerator.get_prefix_cache_stats |
method | MLLMBatchGenerator.get_prefix_cache_stats() -> Dict[str, Any] |
Get KV prefix cache statistics. | #L2024-L2038 |
MLLMBatchGenerator.has_pending |
method | MLLMBatchGenerator.has_pending() -> bool |
Check if there are pending or active requests. | #L2040-L2042 |
install_mtp_mllm |
function | install_mtp_mllm(batch_gen: 'MLLMBatchGenerator', language_model: Any, num_draft_tokens: int = 1) -> None |
Install MTP (Multi-Token Prediction) on an MLLMBatchGenerator. | #L2045-L2590 |
install_mtp_mllm._get_mtp_stats |
nested function | install_mtp_mllm._get_mtp_stats() -> Dict[str, Any] |
Nested Function install_mtp_mllm._get_mtp_stats calls dict; returns {'enabled': True, 'requested_draft_tokens': num_draft_tokens, 'effective_draft_tokens': 1, 'mode': 'request_local_sampl…. |
#L2089-L2110 |
install_mtp_mllm._mtp_step |
nested function | install_mtp_mllm._mtp_step(input_tokens: mx.array, cache: List[Any], logits_processors: Optional[List[Optional[List[Callable]]]] = None, output_tokens: Optional[List[List[int]]] = None, samplers: Optional[List[Optional[Callable]]] = None) -> Tuple[mx.array, List[mx.array]] |
Extended _step with MTP always-advance strategy. | #L2114-L2455 |
install_mtp_mllm._mtp_next |
nested function | install_mtp_mllm._mtp_next() -> List[MLLMBatchResponse] |
Wrapper around _next that emits deferred MTP draft tokens. | #L2460-L2576 |
install_chunked_prefill_mllm |
function | install_chunked_prefill_mllm(batch_gen: 'MLLMBatchGenerator', budget: int = 1024) -> None |
Install interleaved prefill/decode on an MLLMBatchGenerator. | #L2593-L3073 |
install_chunked_prefill_mllm._generation_step |
nested function | install_chunked_prefill_mllm._generation_step() -> List[MLLMBatchResponse] |
Run one generation step for the active batch. | #L2623-L2713 |
install_chunked_prefill_mllm._chunked_next |
nested function | install_chunked_prefill_mllm._chunked_next() -> List[MLLMBatchResponse] |
Interleaved prefill/decode: one prefill chunk + one gen step. | #L2715-L3058 |
install_chunked_prefill_mllm._patched_remove |
nested function | install_chunked_prefill_mllm._patched_remove(uids: List[int]) -> None |
Nested Function install_chunked_prefill_mllm._patched_remove calls set, mx.clear_cache, _orig_remove. |
#L3063-L3068 |