vllm_mlx.scheduler¶
Scheduler for vllm-mlx continuous batching.
View the complete module source at #L1-L3518.
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.scheduler
¶
Scheduler for vllm-mlx continuous batching.
This module provides a Scheduler class that manages request scheduling using mlx-lm's BatchGenerator for efficient continuous batching.
The scheduler follows vLLM's design with: - Waiting queue for pending requests - Running set for active requests - Continuous batching via BatchGenerator
vllm_mlx.scheduler.CACHE_CORRUPTION_PATTERNS
module-attribute
¶
vllm_mlx.scheduler.SchedulingPolicy
¶
vllm_mlx.scheduler.SchedulerConfig
dataclass
¶
SchedulerConfig(max_num_seqs: int = 256, max_num_batched_tokens: int = 8192, policy: SchedulingPolicy = FCFS, prefill_batch_size: int = 8, completion_batch_size: int = 32, prefill_step_size: int = 2048, mllm_prefill_step_size: Optional[int] = None, enable_prefix_cache: bool = True, prefix_cache_size: int = 100, use_memory_aware_cache: bool = True, cache_memory_mb: Optional[int] = None, cache_memory_percent: float = 0.2, kv_cache_quantization: bool = False, kv_cache_quantization_bits: int = 8, kv_cache_quantization_group_size: int = 64, kv_cache_min_quantize_tokens: int = 256, use_paged_cache: bool = False, paged_cache_block_size: int = 64, max_cache_blocks: int = 1000, chunked_prefill_tokens: int = 0, mid_prefill_save_interval: int = 8192, ssd_cache_dir: Optional[str] = None, ssd_cache_max_gb: float = 10.0, max_kv_size: int = 0, enable_mtp: bool = False, mtp_num_draft_tokens: int = 1, mtp_optimistic: bool = False)
Configuration for the scheduler.
vllm_mlx.scheduler.SchedulerConfig.max_num_seqs
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.max_num_batched_tokens
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.policy
class-attribute
instance-attribute
¶
policy: SchedulingPolicy = SchedulingPolicy.FCFS
vllm_mlx.scheduler.SchedulerConfig.prefill_batch_size
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.completion_batch_size
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.prefill_step_size
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.mllm_prefill_step_size
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.enable_prefix_cache
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.prefix_cache_size
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.use_memory_aware_cache
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.cache_memory_mb
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.cache_memory_percent
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.kv_cache_quantization
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.kv_cache_quantization_bits
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.kv_cache_quantization_group_size
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.kv_cache_min_quantize_tokens
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.use_paged_cache
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.paged_cache_block_size
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.max_cache_blocks
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.chunked_prefill_tokens
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.mid_prefill_save_interval
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.ssd_cache_dir
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.ssd_cache_max_gb
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.max_kv_size
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.enable_mtp
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.mtp_num_draft_tokens
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.mtp_optimistic
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerConfig.__post_init__
¶
vllm_mlx.scheduler.SchedulerOutput
dataclass
¶
SchedulerOutput(scheduled_request_ids: List[str] = list(), num_scheduled_tokens: int = 0, finished_request_ids: Set[str] = set(), outputs: List[RequestOutput] = list(), has_work: bool = False)
Output from a scheduling step.
Contains information about what was scheduled and results.
vllm_mlx.scheduler.SchedulerOutput.scheduled_request_ids
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerOutput.num_scheduled_tokens
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerOutput.finished_request_ids
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.SchedulerOutput.outputs
class-attribute
instance-attribute
¶
outputs: List[RequestOutput] = field(default_factory=list)
vllm_mlx.scheduler.SchedulerOutput.has_work
class-attribute
instance-attribute
¶
vllm_mlx.scheduler._MTPStatsState
dataclass
¶
_MTPStatsState(counters: Dict[str, int] = (lambda: {'attempted': 0, 'accepted': 0, 'rejected': 0, 'errors': 0})(), bypass_counts: Dict[str, int] = (lambda: {'prefill': 0, 'no_active_batch': 0, 'cache_mismatch': 0})(), lock: Any = Lock())
Cumulative native-MTP counters shared across generator instances.
vllm_mlx.scheduler._MTPStatsState.counters
class-attribute
instance-attribute
¶
counters: Dict[str, int] = field(default_factory=lambda: {'attempted': 0, 'accepted': 0, 'rejected': 0, 'errors': 0})
vllm_mlx.scheduler._MTPStatsState.bypass_counts
class-attribute
instance-attribute
¶
bypass_counts: Dict[str, int] = field(default_factory=lambda: {'prefill': 0, 'no_active_batch': 0, 'cache_mismatch': 0})
vllm_mlx.scheduler._MTPStatsState.lock
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.Scheduler
¶
Scheduler(model: Any, tokenizer: Any, config: Optional[SchedulerConfig] = None)
Scheduler for continuous batching using mlx-lm BatchGenerator.
This scheduler manages the lifecycle of requests: 1. Requests arrive and are added to the waiting queue 2. Scheduler moves requests from waiting to running (via BatchGenerator) 3. BatchGenerator processes all running requests together 4. Finished requests are removed and outputs returned
The key insight is that mlx-lm's BatchGenerator already implements continuous batching at the token level, so we use it as the backend.
Initialize the scheduler.
Parameters:
-
model(Any) –The MLX model
-
tokenizer(Any) –The tokenizer
-
config(Optional[SchedulerConfig], default:None) –Scheduler configuration
Source code in vllm_mlx/scheduler.py
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 | |
vllm_mlx.scheduler.Scheduler._actual_tokenizer
instance-attribute
¶
vllm_mlx.scheduler.Scheduler._detokenizer_pool
instance-attribute
¶
vllm_mlx.scheduler.Scheduler.finished_req_ids
instance-attribute
¶
vllm_mlx.scheduler.Scheduler.request_id_to_uid
instance-attribute
¶
vllm_mlx.scheduler.Scheduler.uid_to_request_id
instance-attribute
¶
vllm_mlx.scheduler.Scheduler.batch_generator
instance-attribute
¶
vllm_mlx.scheduler.Scheduler._current_sampler_params
instance-attribute
¶
vllm_mlx.scheduler.Scheduler.prefix_cache
instance-attribute
¶
prefix_cache: Optional[PrefixCacheManager] = None
vllm_mlx.scheduler.Scheduler.memory_aware_cache
instance-attribute
¶
memory_aware_cache: Optional[MemoryAwarePrefixCache] = None
vllm_mlx.scheduler.Scheduler.paged_cache_manager
instance-attribute
¶
paged_cache_manager: Optional[PagedCacheManager] = None
vllm_mlx.scheduler.Scheduler.block_aware_cache
instance-attribute
¶
block_aware_cache: Optional[BlockAwarePrefixCache] = None
vllm_mlx.scheduler.Scheduler._ssd_tier
instance-attribute
¶
_ssd_tier: Optional[SSDCacheTier] = None
vllm_mlx.scheduler.Scheduler._pending_abort_ids
instance-attribute
¶
vllm_mlx.scheduler.Scheduler.total_completion_tokens
instance-attribute
¶
vllm_mlx.scheduler.Scheduler._mtp_stats_state
instance-attribute
¶
_mtp_stats_state = _MTPStatsState()
vllm_mlx.scheduler.Scheduler.SNAPSHOT_REFRESH_TOKENS
class-attribute
instance-attribute
¶
vllm_mlx.scheduler.Scheduler._get_actual_tokenizer
¶
Get the actual tokenizer from a processor or tokenizer.
MLLM models use processors (e.g., Qwen3VLProcessor) which wrap the tokenizer. This method extracts the actual tokenizer.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._decode_tokens
¶
Decode token IDs to text, handling both tokenizers and processors.
vllm_mlx.scheduler.Scheduler._get_detokenizer
¶
Get or create a streaming detokenizer for a request.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._cleanup_detokenizer
¶
vllm_mlx.scheduler.Scheduler._get_stop_tokens
¶
Get stop token IDs from tokenizer or processor.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._create_batch_generator
¶
_create_batch_generator(sampling_params: SamplingParams) -> BatchGenerator
Create a BatchGenerator with the given sampling parameters.
Source code in vllm_mlx/scheduler.py
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 | |
vllm_mlx.scheduler.Scheduler._make_prompt_cache_save_callback
¶
Create a callback that stores prompt-only KV/Mamba cache.
Called from _generation_step right before the first output token
is fed into the model. At that point num_tokens == 0 and the
batch cache contains the exact prompt-only state (correct for both
KVCache and MambaCache/ArraysCache layers).
The cache is stored with key = prompt_token_ids so that a future request with the identical prompt gets an exact hit.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._make_mid_prefill_save_callback
¶
Create a callback for saving intermediate KV cache during chunked prefill.
The callback is called after each chunk with (uid, processed_tokens, prompt_cache). It extracts the cache state (immutable MLX array snapshots), reconstructs KVCache objects, and stores them in the memory-aware prefix cache so that a subsequent request with the same prompt prefix can skip the already-computed tokens.
Source code in vllm_mlx/scheduler.py
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 | |
vllm_mlx.scheduler.Scheduler._close_batch_generator
¶
Properly close BatchGenerator to restore wired_limit.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._ensure_batch_generator
¶
_ensure_batch_generator(sampling_params: SamplingParams) -> None
Ensure BatchGenerator exists with compatible settings.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._validate_cache
¶
Validate that a cache object is usable.
Checks for None references AND shape compatibility. Restored cache entries must have batch_size == 1 (single sequence) so they can be merged into the running batch by _merge_caches. A shape mismatch here (e.g. batch=2 from a stale entry) would cause a concatenation crash inside _merge_caches.
Parameters:
-
cache(Any) –The cache object to validate
Returns:
-
bool–True if cache is valid and usable
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._extract_cache_states
¶
Extract actual tensor state from each layer cache.
This extracts the real KV data using mlx-lm's cache.state property, allowing the data to be stored and reconstructed later even after the BatchGenerator is recreated.
Parameters:
-
raw_cache(List[Any]) –List of KVCache objects from mlx-lm
Returns:
-
List[Dict[str, Any]]–List of dicts with {state: (keys, values), meta_state: (offset,), class_name: str}
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._reconstruct_cache_from_states
¶
Reconstruct cache objects from extracted cache states.
This is the inverse of _extract_cache_states(). Uses mlx-lm's _BaseCache.from_state() to reconstruct any cache type (KVCache, MambaCache, etc.) from its state/meta_state.
Parameters:
-
extracted_states(List[Dict[str, Any]]) –List of dicts from _extract_cache_states()
Returns:
-
Optional[List[Any]]–List of cache objects, or None if reconstruction fails
Source code in vllm_mlx/scheduler.py
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 | |
vllm_mlx.scheduler.Scheduler.add_request
¶
add_request(request: Request) -> None
Add a new request to the scheduler.
Parameters:
-
request(Request) –The request to add
Source code in vllm_mlx/scheduler.py
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 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 | |
vllm_mlx.scheduler.Scheduler.abort_request
¶
Queue request for abort. Thread-safe, called from any thread.
The actual abort is deferred to the executor thread (inside step()) to avoid race conditions with in-flight Metal GPU operations.
Parameters:
-
request_id(str) –The request ID to abort
Returns:
-
bool–True (abort is always enqueued)
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._process_pending_aborts
¶
Drain and process pending abort requests. Called from executor thread.
vllm_mlx.scheduler.Scheduler._do_abort_request
¶
Actually abort a request. Must be called from the executor thread.
Handles the case where the request was already removed from self.requests by _cleanup_request() but still lives in the BatchGenerator (e.g. in _partial or active_batch).
Parameters:
-
request_id(str) –The request ID to abort
Returns:
-
bool–True if any cleanup was performed, False otherwise
Source code in vllm_mlx/scheduler.py
2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 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 | |
vllm_mlx.scheduler.Scheduler.has_requests
¶
vllm_mlx.scheduler.Scheduler.get_num_waiting
¶
vllm_mlx.scheduler.Scheduler.get_num_running
¶
vllm_mlx.scheduler.Scheduler._schedule_waiting
¶
_schedule_waiting() -> List[Request]
Move requests from waiting queue to running.
Returns:
-
List[Request]–List of requests that were scheduled
Source code in vllm_mlx/scheduler.py
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 | |
vllm_mlx.scheduler.Scheduler._copy_cache_state
staticmethod
¶
Deep-copy a cache state payload.
Sharing the arrays is not safe: RotatingKVCache writes into its ring
buffer and PoolingCache writes into its remainder buffer, both in
place, so a snapshot that aliases them would be rewritten by the very
generation it is supposed to predate. x + 0 forces a fresh array
while staying on the GPU.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._prompt_output_entry_is_useless
staticmethod
¶
Would a prompt+output entry built from this cache ever be reusable?
Only via a trim: any later query is shorter than a prompt+output key, so the generated tail has to come off first. When the cache cannot be trimmed the entry is dead weight — and far from free, since each one holds a full-length KV copy and Metal runs out of buffers long before the byte budget is reached.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._extract_cache_for_uid
¶
Pull one sequence's cache out of the live BatchGenerator batch.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._make_snapshot_destination
¶
Build a destination cache with the same topology as the live one.
make_prompt_cache(model) is not a safe source for this. A plain
KVCache destination cannot take a RotatingKVCache's state or
meta_state; the assignment raises, the broad handler below logs a
warning, and the snapshot is silently never stored — on exactly the
sliding-window configurations this feature exists for.
Deriving it from config.max_kv_size instead is also wrong, which I
only found by measuring: _create_batch_generator does not pass
max_kv_size to BatchGenerator, so with max_kv_size=512
configured the live layers were still plain KVCache and a
config-derived destination mismatched in the opposite direction.
So mirror the live objects themselves. A shallow copy keeps the class
and every scalar attribute (max_size, keep, step, _idx)
and the caller overwrites the arrays, which is the only part that must
not be shared.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._cache_coverage
staticmethod
¶
How many tokens the live cache actually holds.
Containers have to be descended into: CacheList carries no
offset of its own, so reading the attribute off the layer returns
None and the caller silently falls back to a prompt-only key — the
misalignment this is here to prevent, on exactly the architectures
(DeepSeek-V4) that group several caches per layer.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._cache_key_for_snapshot
¶
Key the entry by the tokens the cache covers, not by the prompt.
The snapshot is taken while processing the response that carries the
first generated token, and by then the batch has already fed that token
through the cache: measured prompt_len=5, cache_offset=6. Storing
that under prompt_token_ids leaves every warm reuse one token ahead
of its key.
Trimming the overshoot off is not available here — these are precisely the caches that cannot be trimmed — so the key is extended instead. The extra token is the first token of the reply, which the next turn's prompt also contains, so the entry still matches by strict prefix.
Returns None rather than storing a misaligned entry.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._store_prompt_only_cache
¶
Store the post-prefill cache under the prompt tokens alone.
Called once per request, at the point where the cache covers exactly the prompt. Entries keyed this way are reusable without any trimming, which is what models with sliding-window or pooled KV need.
Source code in vllm_mlx/scheduler.py
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 | |
vllm_mlx.scheduler.Scheduler._process_batch_responses
¶
_process_batch_responses(responses: List[Any]) -> Tuple[List[RequestOutput], Set[str]]
Process responses from BatchGenerator.
Parameters:
-
responses(List[Any]) –List of BatchGenerator.Response objects
Returns:
-
Tuple[List[RequestOutput], Set[str]]–Tuple of (outputs, finished_request_ids)
Source code in vllm_mlx/scheduler.py
2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 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 | |
vllm_mlx.scheduler.Scheduler._cleanup_finished
¶
Clean up finished requests and store caches for reuse.
Source code in vllm_mlx/scheduler.py
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 | |
vllm_mlx.scheduler.Scheduler._is_cache_corruption_error
¶
Check if an error indicates cache corruption.
vllm_mlx.scheduler.Scheduler._is_stream_thread_error
¶
Check if an error indicates MLX stream/thread ownership mismatch.
vllm_mlx.scheduler.Scheduler._recover_from_cache_error
¶
Recover from cache corruption error.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._recover_from_generation_error
¶
Recover from fatal generation error (OOM, Metal crash).
Aborts all running requests and resets batch state. Unlike cache corruption recovery, does NOT reschedule — the request that OOMed would just OOM again.
Returns:
-
Set[str]–Set of aborted request IDs.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler._reschedule_running_requests
¶
Move running requests back to waiting queue for retry.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler.step
¶
step(max_retries: int = 1) -> SchedulerOutput
Execute one scheduling step with automatic error recovery.
This method: 1. Schedules waiting requests into the batch 2. Runs one generation step via BatchGenerator 3. Processes outputs and handles finished requests 4. Automatically recovers from cache corruption errors
Parameters:
-
max_retries(int, default:1) –Number of times to retry on cache errors (default 1)
Returns:
-
SchedulerOutput–SchedulerOutput with results of this step
Source code in vllm_mlx/scheduler.py
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 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 | |
vllm_mlx.scheduler.Scheduler.remove_finished_request
¶
remove_finished_request(request_id: str) -> Optional[Request]
vllm_mlx.scheduler.Scheduler.get_running_requests_info
¶
Per-request details for status endpoint.
Source code in vllm_mlx/scheduler.py
3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 | |
vllm_mlx.scheduler.Scheduler.get_stats
¶
Get scheduler statistics.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler.get_cache_stats
¶
Get cache statistics.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler.clear_runtime_caches
¶
Clear prefix-cache state without resetting scheduler/request state.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler.reset
¶
Reset the scheduler state.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler.deep_reset
¶
Deep reset that clears ALL cache state including model-level caches.
This is more aggressive than reset() and should be used when switching engines or recovering from errors.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler.save_cache_to_disk
¶
Save prefix cache to disk for persistence across restarts.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler.load_cache_from_disk
¶
Load prefix cache from disk. Returns number of entries loaded.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler.clear_prefix_cache
¶
Clear the in-memory prefix cache (keeps disk cache untouched).
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler.Scheduler.close_ssd_tier
¶
Shut down the SSD cache tier if present.
vllm_mlx.scheduler.Scheduler._try_promote_ssd_pending
¶
Attempt synchronous SSD promotion for waiting requests tagged ssd_pending.
Called from _schedule_waiting() before requests are moved to running. Reads SSD entries synchronously (disk I/O stays out of fetch() per spec).
Source code in vllm_mlx/scheduler.py
3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 | |
vllm_mlx.scheduler.Scheduler.promote_from_ssd
async
¶
Promote a cold-tier cache entry for a request (async version).
Alternative to _try_promote_ssd_pending() for callers with an async event loop. Uses asyncio.to_thread for non-blocking disk I/O.
Returns True if promotion succeeded and request was updated.
Source code in vllm_mlx/scheduler.py
3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 | |
vllm_mlx.scheduler.Scheduler._reconstruct_ssd_layers
¶
Reconstruct cache objects from deserialized layer dicts.
Converts numpy arrays back to MLX arrays and creates KVCache objects.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler._normalize_logits_processors
¶
Normalize empty per-sequence processor slots to lists.
vllm_mlx.scheduler._sanitize_batch_generator_logits_processors
¶
Sanitize stale BatchGenerator processor state before decode.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler._install_prompt_cache_save
¶
Monkey-patch _process_prompts to capture prompt-only cache state.
Can be installed independently of chunked prefill. If chunked prefill is
also installed, it takes over _process_prompts and invokes the
callback itself, so call this before _install_chunked_prefill.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler._install_chunked_prefill
¶
_install_chunked_prefill(batch_gen: BatchGenerator, budget: int, mid_prefill_save=None, prompt_cache_save=None, pending_abort_ids: Optional[Set[str]] = None, uid_to_request_id: Optional[Dict[int, str]] = None, requests: Optional[Dict[str, Any]] = None) -> None
Monkey-patch a BatchGenerator instance so that large prefills are broken into chunks of at most budget tokens each.
Between chunks the generation loop gets a chance to produce one token for every active request, preventing starvation during long prefills.
Parameters:
-
batch_gen(BatchGenerator) –The BatchGenerator to patch.
-
budget(int) –Max tokens per prefill chunk.
-
mid_prefill_save–Optional callback(uid, processed, prompt_cache) called after each chunk to save intermediate KV cache state.
Source code in vllm_mlx/scheduler.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 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 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | |
vllm_mlx.scheduler._configure_chunked_prefill
¶
_configure_chunked_prefill(scheduler: Scheduler, batch_gen: BatchGenerator, budget: int, prompt_cache_save) -> None
Enable the matching legacy or native mlx-lm chunked-prefill API.
Source code in vllm_mlx/scheduler.py
vllm_mlx.scheduler._install_mtp
¶
_install_mtp(batch_gen: BatchGenerator, model: Any, num_draft_tokens: int = 1, optimistic: bool = False, stats_state: Optional[_MTPStatsState] = None) -> None
Monkey-patch a BatchGenerator to use MTP (Multi-Token Prediction) with always-advance strategy for hybrid MambaCache + KVCache.
Flow per generation step: 1. Use skip_state logits/hidden OR run model forward -> sample primary 2. MTP head drafts one token after primary 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 KVCache by 1, skip_state from pos 0 (no cold start) 5. Draft is emitted in the NEXT generation step after primary
Source code in vllm_mlx/scheduler.py
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 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 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 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 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 | |
vllm_mlx.scheduler._mtp_status_snapshot
¶
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.scheduler._normalize_logits_processors · function
Normalize empty per-sequence processor slots to lists.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
logits_processors |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
None;[processors or [] for processors in logits_processors]
Exceptions and behavior
Function _normalize_logits_processors has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._sanitize_batch_generator_logits_processors · function
Sanitize stale BatchGenerator processor state before decode.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
batch_generator |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Function _sanitize_batch_generator_logits_processors calls getattr, hasattr, _normalize_logits_processors, isinstance.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.SchedulingPolicy · class
Scheduling policy for request ordering.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.scheduler.SchedulingPolicy
Exceptions and behavior
Class SchedulingPolicy derives from Enum and declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.scheduler.SchedulerConfig · class
vllm_mlx.scheduler.SchedulerConfig(max_num_seqs: int = 256, max_num_batched_tokens: int = 8192, policy: SchedulingPolicy = SchedulingPolicy.FCFS, prefill_batch_size: int = 8, completion_batch_size: int = 32, prefill_step_size: int = 2048, mllm_prefill_step_size: Optional[int] = None, enable_prefix_cache: bool = True, prefix_cache_size: int = 100, use_memory_aware_cache: bool = True, cache_memory_mb: Optional[int] = None, cache_memory_percent: float = 0.2, kv_cache_quantization: bool = False, kv_cache_quantization_bits: int = 8, kv_cache_quantization_group_size: int = 64, kv_cache_min_quantize_tokens: int = 256, use_paged_cache: bool = False, paged_cache_block_size: int = 64, max_cache_blocks: int = 1000, chunked_prefill_tokens: int = 0, mid_prefill_save_interval: int = 8192, ssd_cache_dir: Optional[str] = None, ssd_cache_max_gb: float = 10.0, max_kv_size: int = 0, enable_mtp: bool = False, mtp_num_draft_tokens: int = 1, mtp_optimistic: bool = False)
Configuration for the scheduler.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
max_num_seqs |
int |
no |
256 |
Optional constructor field; defaults to 256. |
max_num_batched_tokens |
int |
no |
8192 |
Optional constructor field; defaults to 8192. |
policy |
SchedulingPolicy |
no |
SchedulingPolicy.FCFS |
Optional constructor field; defaults to SchedulingPolicy.FCFS. |
prefill_batch_size |
int |
no |
8 |
Optional constructor field; defaults to 8. |
completion_batch_size |
int |
no |
32 |
Optional constructor field; defaults to 32. |
prefill_step_size |
int |
no |
2048 |
Optional constructor field; defaults to 2048. |
mllm_prefill_step_size |
Optional[int] |
no |
None |
Optional constructor field; defaults to None. |
enable_prefix_cache |
bool |
no |
True |
Optional constructor field; defaults to True. |
prefix_cache_size |
int |
no |
100 |
Optional constructor field; defaults to 100. |
use_memory_aware_cache |
bool |
no |
True |
Optional constructor field; defaults to True. |
cache_memory_mb |
Optional[int] |
no |
None |
Optional constructor field; defaults to None. |
cache_memory_percent |
float |
no |
0.2 |
Optional constructor field; defaults to 0.2. |
kv_cache_quantization |
bool |
no |
False |
Optional constructor field; defaults to False. |
kv_cache_quantization_bits |
int |
no |
8 |
Optional constructor field; defaults to 8. |
kv_cache_quantization_group_size |
int |
no |
64 |
Optional constructor field; defaults to 64. |
kv_cache_min_quantize_tokens |
int |
no |
256 |
Optional constructor field; defaults to 256. |
use_paged_cache |
bool |
no |
False |
Optional constructor field; defaults to False. |
paged_cache_block_size |
int |
no |
64 |
Optional constructor field; defaults to 64. |
max_cache_blocks |
int |
no |
1000 |
Optional constructor field; defaults to 1000. |
chunked_prefill_tokens |
int |
no |
0 |
Optional constructor field; defaults to 0. |
mid_prefill_save_interval |
int |
no |
8192 |
Optional constructor field; defaults to 8192. |
ssd_cache_dir |
Optional[str] |
no |
None |
Optional constructor field; defaults to None. |
ssd_cache_max_gb |
float |
no |
10.0 |
Optional constructor field; defaults to 10.0. |
max_kv_size |
int |
no |
0 |
Optional constructor field; defaults to 0. |
enable_mtp |
bool |
no |
False |
Optional constructor field; defaults to False. |
mtp_num_draft_tokens |
int |
no |
1 |
Optional constructor field; defaults to 1. |
mtp_optimistic |
bool |
no |
False |
Optional constructor field; defaults to False. |
Returns
- Constructs:
vllm_mlx.scheduler.SchedulerConfig
Exceptions and behavior
Class SchedulerConfig declares 1 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.scheduler.SchedulerConfig.__post_init__ · method
Method SchedulerConfig.__post_init__ calls ValueError; can raise ValueError.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method SchedulerConfig.__post_init__ calls ValueError; can raise ValueError.
Directly raised exceptions: ValueError.
vllm_mlx.scheduler.SchedulerOutput · class
vllm_mlx.scheduler.SchedulerOutput(scheduled_request_ids: List[str] = field(default_factory=list), num_scheduled_tokens: int = 0, finished_request_ids: Set[str] = field(default_factory=set), outputs: List[RequestOutput] = field(default_factory=list), has_work: bool = False)
Output from a scheduling step.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
scheduled_request_ids |
List[str] |
no |
field(default_factory=list) |
Optional constructor field; defaults to field(default_factory=list). |
num_scheduled_tokens |
int |
no |
0 |
Optional constructor field; defaults to 0. |
finished_request_ids |
Set[str] |
no |
field(default_factory=set) |
Optional constructor field; defaults to field(default_factory=set). |
outputs |
List[RequestOutput] |
no |
field(default_factory=list) |
Optional constructor field; defaults to field(default_factory=list). |
has_work |
bool |
no |
False |
Optional constructor field; defaults to False. |
Returns
- Constructs:
vllm_mlx.scheduler.SchedulerOutput
Exceptions and behavior
Class SchedulerOutput declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_prompt_cache_save · function
vllm_mlx.scheduler._install_prompt_cache_save(batch_gen: 'BatchGenerator', prompt_cache_save) -> None
Monkey-patch _process_prompts to capture prompt-only cache state.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
batch_gen |
'BatchGenerator' |
yes |
none |
Required positional or keyword input. |
prompt_cache_save |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Function _install_prompt_cache_save contains no state mutation, call, raise, return, await, or yield.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_prompt_cache_save._patched_process_prompts · nested function
vllm_mlx.scheduler._install_prompt_cache_save._patched_process_prompts(prompts, _self = batch_gen) -> not annotated
Nested Function _install_prompt_cache_save._patched_process_prompts calls _orig_process_prompts, enumerate, prompt_cache_save, batch.extract_cache; returns batch.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
prompts |
not annotated |
yes |
none |
Required positional or keyword input. |
_self |
not annotated |
no |
batch_gen |
Optional positional or keyword input; defaults to batch_gen. |
Returns
- Type:
not annotated - Direct return expressions:
batch
Exceptions and behavior
Nested Function _install_prompt_cache_save._patched_process_prompts calls _orig_process_prompts, enumerate, prompt_cache_save, batch.extract_cache; returns batch.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_chunked_prefill · function
vllm_mlx.scheduler._install_chunked_prefill(batch_gen: 'BatchGenerator', budget: int, mid_prefill_save = None, prompt_cache_save = None, pending_abort_ids: Optional[Set[str]] = None, uid_to_request_id: Optional[Dict[int, str]] = None, requests: Optional[Dict[str, Any]] = None) -> None
Monkey-patch a BatchGenerator instance so that large prefills are broken into chunks of at most budget tokens each.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
batch_gen |
'BatchGenerator' |
yes |
none |
The BatchGenerator to patch. |
budget |
int |
yes |
none |
Max tokens per prefill chunk. |
mid_prefill_save |
not annotated |
no |
None |
Optional callback(uid, processed, prompt_cache) called after each chunk to save intermediate KV cache state. |
prompt_cache_save |
not annotated |
no |
None |
Optional positional or keyword input; defaults to None. |
pending_abort_ids |
Optional[Set[str]] |
no |
None |
Optional positional or keyword input; defaults to None. |
uid_to_request_id |
Optional[Dict[int, str]] |
no |
None |
Optional positional or keyword input; defaults to None. |
requests |
Optional[Dict[str, Any]] |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
None
Exceptions and behavior
Function _install_chunked_prefill calls logger.info.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_chunked_prefill._lazy_extract_cache · nested function
Nested Function _install_chunked_prefill._lazy_extract_cache calls c.extract; returns (c.extract(idx) for c in cache).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache |
not annotated |
yes |
none |
Required positional or keyword input. |
idx |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
(c.extract(idx) for c in cache)
Exceptions and behavior
Nested Function _install_chunked_prefill._lazy_extract_cache calls c.extract; returns (c.extract(idx) for c in cache).
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_chunked_prefill._batch_cls · nested class
vllm_mlx.scheduler._install_chunked_prefill._batch_cls(uids: List[int], y: Any, logprobs: List[Any], max_tokens: List[int], num_tokens: List[int], cache: List[Any], samplers: List[Any], logits_processors: List[Any], tokens: List[Any])
Nested Class _install_chunked_prefill._batch_cls declares 4 direct member(s).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
uids |
List[int] |
yes |
none |
Required constructor field. |
y |
Any |
yes |
none |
Required constructor field. |
logprobs |
List[Any] |
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. |
samplers |
List[Any] |
yes |
none |
Required constructor field. |
logits_processors |
List[Any] |
yes |
none |
Required constructor field. |
tokens |
List[Any] |
yes |
none |
Required constructor field. |
Returns
- Constructs:
vllm_mlx.scheduler._install_chunked_prefill._batch_cls
Exceptions and behavior
Nested Class _install_chunked_prefill._batch_cls declares 4 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_chunked_prefill._batch_cls.__len__ · nested function
Nested Function _install_chunked_prefill._batch_cls.__len__ calls len; returns len(self.uids).
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
len(self.uids)
Exceptions and behavior
Nested Function _install_chunked_prefill._batch_cls.__len__ calls len; returns len(self.uids).
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_chunked_prefill._batch_cls.filter · nested function
Nested Function _install_chunked_prefill._batch_cls.filter updates self.uids, self.logprobs, self.max_tokens, self.num_tokens; calls mx.array, c.filter.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
keep_idx |
List[int] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated
Exceptions and behavior
Nested Function _install_chunked_prefill._batch_cls.filter updates self.uids, self.logprobs, self.max_tokens, self.num_tokens; calls mx.array, c.filter.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_chunked_prefill._batch_cls.extend · nested function
Nested Function _install_chunked_prefill._batch_cls.extend updates self.y; calls self.uids.extend, mx.concatenate, self.logprobs.extend, self.num_tokens.extend.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
other |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated
Exceptions and behavior
Nested Function _install_chunked_prefill._batch_cls.extend updates self.y; calls self.uids.extend, mx.concatenate, self.logprobs.extend, self.num_tokens.extend.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_chunked_prefill._batch_cls.extract_cache · nested function
Nested Function _install_chunked_prefill._batch_cls.extract_cache calls c.extract; returns [c.extract(idx) for c in self.cache].
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
idx |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
[c.extract(idx) for c in self.cache]
Exceptions and behavior
Nested Function _install_chunked_prefill._batch_cls.extract_cache calls c.extract; returns [c.extract(idx) for c in self.cache].
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_chunked_prefill._patched_process_prompts · nested function
vllm_mlx.scheduler._install_chunked_prefill._patched_process_prompts(prompts, _self = batch_gen) -> not annotated
Nested Function _install_chunked_prefill._patched_process_prompts calls _orig_process_prompts, enumerate, prompt_cache_save, batch.extract_cache; returns batch.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
prompts |
not annotated |
yes |
none |
Required positional or keyword input. |
_self |
not annotated |
no |
batch_gen |
Optional positional or keyword input; defaults to batch_gen. |
Returns
- Type:
not annotated - Direct return expressions:
batch
Exceptions and behavior
Nested Function _install_chunked_prefill._patched_process_prompts calls _orig_process_prompts, enumerate, prompt_cache_save, batch.extract_cache; returns batch.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_chunked_prefill._generation_step · nested function
Run one generation step on the active batch.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
[];responses
Exceptions and behavior
Nested Function _install_chunked_prefill._generation_step updates self._stats.generation_time, self.active_batch, self._stats.generation_tokens; calls len, _time.perf_counter, enumerate, mx.concatenate; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_chunked_prefill._chunked_next · nested function
Replacement for _next() that chunks large prefills.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
self._generation_step()
Exceptions and behavior
Nested Function _install_chunked_prefill._chunked_next updates self._partial, self.active_batch, self._stats.prompt_time, self._stats.generation_time; calls uid_to_request_id.get, logger.info, mx.clear_cache, self._generation_step; returns self._generation_step().
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_chunked_prefill._patched_remove · nested function
vllm_mlx.scheduler._install_chunked_prefill._patched_remove(uids_to_remove, _self = batch_gen) -> not annotated
Clear partial state if aborted request is being prefilled.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
uids_to_remove |
not annotated |
yes |
none |
Required positional or keyword input. |
_self |
not annotated |
no |
batch_gen |
Optional positional or keyword input; defaults to batch_gen. |
Returns
- Type:
not annotated
Exceptions and behavior
Nested Function _install_chunked_prefill._patched_remove calls set, logger.info, mx.clear_cache, _orig_remove.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._MTPStatsState · class
vllm_mlx.scheduler._MTPStatsState(counters: Dict[str, int] = field(default_factory=lambda: {'attempted': 0, 'accepted': 0, 'rejected': 0, 'errors': 0}), bypass_counts: Dict[str, int] = field(default_factory=lambda: {'prefill': 0, 'no_active_batch': 0, 'cache_mismatch': 0}), lock: Any = field(default_factory=Lock))
Cumulative native-MTP counters shared across generator instances.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
counters |
Dict[str, int] |
no |
field(default_factory=lambda: {'attempted': 0, 'accepted': 0, 'rejected': 0, 'errors': 0}) |
Optional constructor field; defaults to field(default_factory=lambda: {'attempted': 0, 'accepted': 0, 'rejected': 0, 'errors': 0}). |
bypass_counts |
Dict[str, int] |
no |
field(default_factory=lambda: {'prefill': 0, 'no_active_batch': 0, 'cache_mismatch': 0}) |
Optional constructor field; defaults to field(default_factory=lambda: {'prefill': 0, 'no_active_batch': 0, 'cache_mismatch': 0}). |
lock |
Any |
no |
field(default_factory=Lock) |
Optional constructor field; defaults to field(default_factory=Lock). |
Returns
- Constructs:
vllm_mlx.scheduler._MTPStatsState
Exceptions and behavior
Class _MTPStatsState declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.scheduler._configure_chunked_prefill · function
vllm_mlx.scheduler._configure_chunked_prefill(scheduler: 'Scheduler', batch_gen: 'BatchGenerator', budget: int, prompt_cache_save) -> None
Enable the matching legacy or native mlx-lm chunked-prefill API.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
scheduler |
'Scheduler' |
yes |
none |
Required positional or keyword input. |
batch_gen |
'BatchGenerator' |
yes |
none |
Required positional or keyword input. |
budget |
int |
yes |
none |
Required positional or keyword input. |
prompt_cache_save |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Function _configure_chunked_prefill calls hasattr, scheduler._make_mid_prefill_save_callback, logger.info, _install_chunked_prefill; returns None.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_mtp · function
vllm_mlx.scheduler._install_mtp(batch_gen: 'BatchGenerator', model: Any, num_draft_tokens: int = 1, optimistic: bool = False, stats_state: Optional['_MTPStatsState'] = None) -> None
Monkey-patch a BatchGenerator to use MTP (Multi-Token Prediction) with always-advance strategy for hybrid MambaCache + KVCache.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
batch_gen |
'BatchGenerator' |
yes |
none |
Required positional or keyword input. |
model |
Any |
yes |
none |
Required positional or keyword input. |
num_draft_tokens |
int |
no |
1 |
Optional positional or keyword input; defaults to 1. |
optimistic |
bool |
no |
False |
Optional positional or keyword input; defaults to False. |
stats_state |
Optional['_MTPStatsState'] |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
None
Exceptions and behavior
Function _install_mtp calls make_sampler, _MTPStatsState, logger.warning, logger.info.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_mtp._get_mtp_stats · nested function
Nested Function _install_mtp._get_mtp_stats calls dict; returns {'enabled': True, 'requested_draft_tokens': num_draft_tokens, 'effective_draft_tokens': 1, 'mode': 'always_advance_opti….
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': 'always_advance_opti…
Exceptions and behavior
Nested Function _install_mtp._get_mtp_stats calls dict; returns {'enabled': True, 'requested_draft_tokens': num_draft_tokens, 'effective_draft_tokens': 1, 'mode': 'always_advance_opti….
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_mtp._mtp_bypass_reasons · nested function
Nested Function _install_mtp._mtp_bypass_reasons calls reasons.append; returns reasons.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
input_tokens |
not annotated |
yes |
none |
Required positional or keyword input. |
prompt_cache |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
reasons
Exceptions and behavior
Nested Function _install_mtp._mtp_bypass_reasons calls reasons.append; returns reasons.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_mtp._record_mtp_bypass · nested function
Nested Function _install_mtp._record_mtp_bypass contains no state mutation, call, raise, return, await, or yield.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
reasons |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Nested Function _install_mtp._record_mtp_bypass contains no state mutation, call, raise, return, await, or yield.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_mtp._mtp_step · nested function
vllm_mlx.scheduler._install_mtp._mtp_step(input_tokens, prompt_cache, samplers, logits_processors, tokens) -> not annotated
Extended _step with MTP always-advance strategy.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
input_tokens |
not annotated |
yes |
none |
Required positional or keyword input. |
prompt_cache |
not annotated |
yes |
none |
Required positional or keyword input. |
samplers |
not annotated |
yes |
none |
Required positional or keyword input. |
logits_processors |
not annotated |
yes |
none |
Required positional or keyword input. |
tokens |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
_orig_step(input_tokens, prompt_cache, samplers, logits_processors, tokens);(primary_tokens, list(logprobs))
Exceptions and behavior
Nested Function _install_mtp._mtp_step calls _mtp_bypass_reasons, _record_mtp_bypass, _orig_step, model; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._install_mtp._mtp_next · nested function
Wrapper around _next that emits deferred MTP draft tokens.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
responses;augmented
Exceptions and behavior
Nested Function _install_mtp._mtp_next updates self.active_batch; calls _deferred_drafts.clear, _deferred_drafts.pop, self._inner_next, set; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler._mtp_status_snapshot · function
Function _mtp_status_snapshot calls getattr, callable, get_mtp_stats; has 2 explicit return paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
batch_generator |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Dict[str, Any] - Direct return expressions:
{'mtp': get_mtp_stats()};{}
Exceptions and behavior
Function _mtp_status_snapshot calls getattr, callable, get_mtp_stats; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler · class
Scheduler for continuous batching using mlx-lm BatchGenerator.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model |
Any |
yes |
none |
The MLX model |
tokenizer |
Any |
yes |
none |
The tokenizer |
config |
Optional[SchedulerConfig] |
no |
None |
Scheduler configuration |
Returns
- Constructs:
vllm_mlx.scheduler.Scheduler
Exceptions and behavior
Class Scheduler declares 52 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.__init__ · method
vllm_mlx.scheduler.Scheduler.__init__(model: Any, tokenizer: Any, config: Optional[SchedulerConfig] = None) -> not annotated
Initialize the scheduler.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model |
Any |
yes |
none |
The MLX model |
tokenizer |
Any |
yes |
none |
The tokenizer |
config |
Optional[SchedulerConfig] |
no |
None |
Scheduler configuration |
Returns
- Type:
not annotated
Exceptions and behavior
Method Scheduler.__init__ updates self.model, self.tokenizer, self.config, self._actual_tokenizer; calls SchedulerConfig, self._get_actual_tokenizer, deque, set.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._get_actual_tokenizer · method
Get the actual tokenizer from a processor or tokenizer.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokenizer |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Any - Direct return expressions:
tokenizer;tokenizer.tokenizer
Exceptions and behavior
Method Scheduler._get_actual_tokenizer calls hasattr, callable; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._decode_tokens · method
Decode token IDs to text, handling both tokenizers and processors.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
token_ids |
List[int] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
self._actual_tokenizer.decode(token_ids)
Exceptions and behavior
Method Scheduler._decode_tokens calls self._actual_tokenizer.decode; returns self._actual_tokenizer.decode(token_ids).
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._get_detokenizer · method
Get or create a streaming detokenizer for a request.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Any - Direct return expressions:
self._detokenizer_pool[request_id]
Exceptions and behavior
Method Scheduler._get_detokenizer calls NaiveStreamingDetokenizer; returns self._detokenizer_pool[request_id].
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._cleanup_detokenizer · method
Remove the streaming detokenizer for a finished request.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method Scheduler._cleanup_detokenizer calls self._detokenizer_pool.pop.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._get_stop_tokens · method
Get stop token IDs from tokenizer or processor.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Set[int] - Direct return expressions:
stop_tokens
Exceptions and behavior
Method Scheduler._get_stop_tokens calls set, hasattr, isinstance, stop_tokens.update; returns stop_tokens.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._create_batch_generator · method
vllm_mlx.scheduler.Scheduler._create_batch_generator(sampling_params: SamplingParams) -> BatchGenerator
Create a BatchGenerator with the given sampling parameters.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
sampling_params |
SamplingParams |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
BatchGenerator - Direct return expressions:
bg
Exceptions and behavior
Method Scheduler._create_batch_generator calls make_sampler, self._get_stop_tokens, stop_tokens.update, BatchGenerator; returns bg.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._create_batch_generator._prefill_progress · nested function
vllm_mlx.scheduler.Scheduler._create_batch_generator._prefill_progress(progress_list) -> not annotated
Log prefill progress for each uid chunk.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
progress_list |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated
Exceptions and behavior
Nested Function Scheduler._create_batch_generator._prefill_progress calls self.uid_to_request_id.get, logger.info, isinstance.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._make_prompt_cache_save_callback · method
Create a callback that stores prompt-only KV/Mamba cache.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
_prompt_cache_save
Exceptions and behavior
Method Scheduler._make_prompt_cache_save_callback returns _prompt_cache_save.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._make_prompt_cache_save_callback._prompt_cache_save · nested function
vllm_mlx.scheduler.Scheduler._make_prompt_cache_save_callback._prompt_cache_save(uid, extracted_cache) -> not annotated
Nested Function Scheduler._make_prompt_cache_save_callback._prompt_cache_save calls self.uid_to_request_id.get, self.requests.get, list, _trim_cache_offset; returns None.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
uid |
not annotated |
yes |
none |
Required positional or keyword input. |
extracted_cache |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
None
Exceptions and behavior
Nested Function Scheduler._make_prompt_cache_save_callback._prompt_cache_save calls self.uid_to_request_id.get, self.requests.get, list, _trim_cache_offset; returns None.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._make_mid_prefill_save_callback · method
Create a callback for saving intermediate KV cache during chunked prefill.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
save_interval |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
_mid_prefill_save
Exceptions and behavior
Method Scheduler._make_mid_prefill_save_callback returns _mid_prefill_save.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._make_mid_prefill_save_callback._mid_prefill_save · nested function
vllm_mlx.scheduler.Scheduler._make_mid_prefill_save_callback._mid_prefill_save(uid, processed_tokens, prompt_cache) -> not annotated
Nested Function Scheduler._make_mid_prefill_save_callback._mid_prefill_save calls self.uid_to_request_id.get, self.requests.get, getattr, self._extract_cache_states; returns None.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
uid |
not annotated |
yes |
none |
Required positional or keyword input. |
processed_tokens |
not annotated |
yes |
none |
Required positional or keyword input. |
prompt_cache |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
None
Exceptions and behavior
Nested Function Scheduler._make_mid_prefill_save_callback._mid_prefill_save calls self.uid_to_request_id.get, self.requests.get, getattr, self._extract_cache_states; returns None.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._close_batch_generator · method
Properly close BatchGenerator to restore wired_limit.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method Scheduler._close_batch_generator updates self.batch_generator; calls hasattr, self.batch_generator.close, logger.debug.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._ensure_batch_generator · method
Ensure BatchGenerator exists with compatible settings.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
sampling_params |
SamplingParams |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method Scheduler._ensure_batch_generator updates self.batch_generator, self._current_sampler_params; calls logger.warning, len, hasattr, logger.info; returns None.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._validate_cache · method
Validate that a cache object is usable.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache |
Any |
yes |
none |
The cache object to validate |
Returns
- Type:
bool - Direct return expressions:
False;True
Exceptions and behavior
Method Scheduler._validate_cache calls isinstance, len, hasattr, logger.debug; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._extract_cache_states · method
Extract actual tensor state from each layer cache.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
raw_cache |
List[Any] |
yes |
none |
List of KVCache objects from mlx-lm |
Returns
- Type:
List[Dict[str, Any]] - Direct return expressions:
[];extracted if len(extracted) == len(raw_cache) else []
Exceptions and behavior
Method Scheduler._extract_cache_states calls hasattr, extracted.append, type, logger.debug; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._reconstruct_cache_from_states · method
vllm_mlx.scheduler.Scheduler._reconstruct_cache_from_states(extracted_states: List[Dict[str, Any]]) -> Optional[List[Any]]
Reconstruct cache objects from extracted cache states.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
extracted_states |
List[Dict[str, Any]] |
yes |
none |
List of dicts from _extract_cache_states() |
Returns
- Type:
Optional[List[Any]] - Direct return expressions:
None;caches
Exceptions and behavior
Method Scheduler._reconstruct_cache_from_states calls layer_state.get, hasattr, _KVCache, cache_cls.from_state; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.add_request · method
Add a new request to the scheduler.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request |
Request |
yes |
none |
The request to add |
Returns
- Type:
None
Exceptions and behavior
Method Scheduler.add_request calls ValueError, isinstance, hasattr, self.tokenizer.encode; can raise ValueError, AttributeError.
Directly raised exceptions: ValueError, AttributeError.
vllm_mlx.scheduler.Scheduler.abort_request · method
Queue request for abort.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
The request ID to abort |
Returns
- Type:
bool - Direct return expressions:
True
Exceptions and behavior
Method Scheduler.abort_request calls self._pending_abort_ids.add, logger.info; returns True.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._process_pending_aborts · method
Drain and process pending abort requests.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method Scheduler._process_pending_aborts calls self._pending_abort_ids.pop, self._do_abort_request.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._do_abort_request · method
Actually abort a request.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
The request ID to abort |
Returns
- Type:
bool - Direct return expressions:
True
Exceptions and behavior
Method Scheduler._do_abort_request updates self.total_completion_tokens, self.total_prompt_tokens; calls self.requests.get, self.waiting.remove, self.batch_generator.remove, request.set_finished; returns True.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.has_requests · method
Check if there are any pending or running requests.
Parameters
This callable has no explicit inputs.
Returns
- Type:
bool - Direct return expressions:
bool(self.waiting or self.running)
Exceptions and behavior
Method Scheduler.has_requests calls bool; returns bool(self.waiting or self.running).
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.get_num_waiting · method
Get number of waiting requests.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
len(self.waiting)
Exceptions and behavior
Method Scheduler.get_num_waiting calls len; returns len(self.waiting).
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.get_num_running · method
Get number of running requests.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
len(self.running)
Exceptions and behavior
Method Scheduler.get_num_running calls len; returns len(self.running).
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._schedule_waiting · method
Move requests from waiting queue to running.
Parameters
This callable has no explicit inputs.
Returns
- Type:
List[Request] - Direct return expressions:
scheduled
Exceptions and behavior
Method Scheduler._schedule_waiting updates self.total_prompt_tokens; calls self._try_promote_ssd_pending, len, self.waiting.popleft, self._ensure_batch_generator; returns scheduled.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._copy_cache_state · method
Deep-copy a cache state payload.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
value |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Any - Direct return expressions:
value + 0;type(value)(copied) if isinstance(value, tuple) else copied;value
Exceptions and behavior
Method Scheduler._copy_cache_state calls isinstance, Scheduler._copy_cache_state, type(value), type; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._prompt_output_entry_is_useless · method
Would a prompt+output entry built from this cache ever be reusable?
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
not can_trim_prompt_cache(cache);False
Exceptions and behavior
Method Scheduler._prompt_output_entry_is_useless calls can_trim_prompt_cache; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._extract_cache_for_uid · method
Pull one sequence's cache out of the live BatchGenerator batch.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
uid |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Any - Direct return expressions:
None;extract(uids.index(uid))
Exceptions and behavior
Method Scheduler._extract_cache_for_uid calls getattr, extract, uids.index, logger.debug; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._make_snapshot_destination · method
Build a destination cache with the same topology as the live one.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
live_cache |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Any - Direct return expressions:
[_mirror(layer) for layer in live_cache];None
Exceptions and behavior
Method Scheduler._make_snapshot_destination calls _mirror, logger.warning; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._make_snapshot_destination._mirror · nested function
Nested Function Scheduler._make_snapshot_destination._mirror calls getattr, _mirror, copy.copy, type(children); has 2 explicit return paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
layer |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Any - Direct return expressions:
container;copy.copy(layer)
Exceptions and behavior
Nested Function Scheduler._make_snapshot_destination._mirror calls getattr, _mirror, copy.copy, type(children); has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._cache_coverage · method
How many tokens the live cache actually holds.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
int | None - Direct return expressions:
found;None
Exceptions and behavior
Method Scheduler._cache_coverage calls _offset_of; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._cache_coverage._offset_of · nested function
Nested Function Scheduler._cache_coverage._offset_of calls getattr, isinstance, _offset_of; has 3 explicit return paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
layer |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
int | None - Direct return expressions:
offset;found;None
Exceptions and behavior
Nested Function Scheduler._cache_coverage._offset_of calls getattr, isinstance, _offset_of; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._cache_key_for_snapshot · method
vllm_mlx.scheduler.Scheduler._cache_key_for_snapshot(request: Any, response: Any, raw_cache: Any) -> list[int] | None
Key the entry by the tokens the cache covers, not by the prompt.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request |
Any |
yes |
none |
Required positional or keyword input. |
response |
Any |
yes |
none |
Required positional or keyword input. |
raw_cache |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
list[int] | None - Direct return expressions:
None;prompt_ids;prompt_ids + generated[:overshoot]
Exceptions and behavior
Method Scheduler._cache_key_for_snapshot calls self._cache_coverage, list, logger.debug, ', '.join; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._store_prompt_only_cache · method
Store the post-prefill cache under the prompt tokens alone.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request |
Any |
yes |
none |
Required positional or keyword input. |
response |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method Scheduler._store_prompt_only_cache calls getattr, len, callable, raw_cache; returns None.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._process_batch_responses · method
vllm_mlx.scheduler.Scheduler._process_batch_responses(responses: List[Any]) -> Tuple[List[RequestOutput], Set[str]]
Process responses from BatchGenerator.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
responses |
List[Any] |
yes |
none |
List of BatchGenerator.Response objects |
Returns
- Type:
Tuple[List[RequestOutput], Set[str]] - Direct return expressions:
(outputs, finished_ids)
Exceptions and behavior
Method Scheduler._process_batch_responses updates self.total_completion_tokens, self.num_requests_processed; calls set, self.uid_to_request_id.get, self.running.get, self._store_prompt_only_cache; returns (outputs, finished_ids).
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._cleanup_finished · method
Clean up finished requests and store caches for reuse.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
finished_ids |
Set[str] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method Scheduler._cleanup_finished calls self.running.get, hasattr, list, self.block_aware_cache.store_cache.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._is_cache_corruption_error · method
Check if an error indicates cache corruption.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
error |
Exception |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
any((pattern in error_str for pattern in CACHE_CORRUPTION_PATTERNS))
Exceptions and behavior
Method Scheduler._is_cache_corruption_error calls str, any; returns any((pattern in error_str for pattern in CACHE_CORRUPTION_PATTERNS)).
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._is_stream_thread_error · method
Check if an error indicates MLX stream/thread ownership mismatch.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
error |
Exception |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
'no Stream(' in error_str or 'no Stream(gpu' in error_str
Exceptions and behavior
Method Scheduler._is_stream_thread_error calls str; returns 'no Stream(' in error_str or 'no Stream(gpu' in error_str.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._recover_from_cache_error · method
Recover from cache corruption error.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method Scheduler._recover_from_cache_error updates self._current_sampler_params; calls self._close_batch_generator, self.block_aware_cache.clear, self.memory_aware_cache.clear, self.prefix_cache.clear.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._recover_from_generation_error · method
Recover from fatal generation error (OOM, Metal crash).
Parameters
This callable has no explicit inputs.
Returns
- Type:
Set[str] - Direct return expressions:
aborted_ids
Exceptions and behavior
Method Scheduler._recover_from_generation_error updates self._current_sampler_params; calls self._close_batch_generator, set, list, self.running.get; returns aborted_ids.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._reschedule_running_requests · method
Move running requests back to waiting queue for retry.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method Scheduler._reschedule_running_requests calls len, list, self.running.items, self.waiting.appendleft.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.step · method
Execute one scheduling step with automatic error recovery.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
max_retries |
int |
no |
1 |
Number of times to retry on cache errors (default 1) |
Returns
- Type:
SchedulerOutput - Direct return expressions:
output
Exceptions and behavior
Method Scheduler.step updates self.finished_req_ids, self._step_count; calls SchedulerOutput, self._process_pending_aborts, range, self._schedule_waiting; returns output.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.get_request · method
Get a request by ID.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Optional[Request] - Direct return expressions:
self.requests.get(request_id)
Exceptions and behavior
Method Scheduler.get_request calls self.requests.get; returns self.requests.get(request_id).
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.remove_finished_request · method
Remove a finished request from tracking.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Optional[Request] - Direct return expressions:
self.requests.pop(request_id, None)
Exceptions and behavior
Method Scheduler.remove_finished_request calls self.requests.pop; returns self.requests.pop(request_id, None).
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.get_running_requests_info · method
Per-request details for status endpoint.
Parameters
This callable has no explicit inputs.
Returns
- Type:
List[Dict[str, Any]] - Direct return expressions:
result
Exceptions and behavior
Method Scheduler.get_running_requests_info calls _time.time, result.append, round, self.running.values; returns result.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.get_stats · method
Get scheduler statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Dict[str, Any] - Direct return expressions:
stats
Exceptions and behavior
Method Scheduler.get_stats calls len, stats.update, _mtp_status_snapshot, mx.metal.is_available; returns stats.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.get_cache_stats · method
Get cache statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Optional[Dict[str, Any]] - Direct return expressions:
self.block_aware_cache.get_stats();self.memory_aware_cache.get_stats();self.prefix_cache.get_stats();None
Exceptions and behavior
Method Scheduler.get_cache_stats calls self.block_aware_cache.get_stats, self.memory_aware_cache.get_stats, self.prefix_cache.get_stats; has 4 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.clear_runtime_caches · method
Clear prefix-cache state without resetting scheduler/request state.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Dict[str, bool] - Direct return expressions:
cleared
Exceptions and behavior
Method Scheduler.clear_runtime_caches calls self.block_aware_cache.clear, self.memory_aware_cache.clear, self.prefix_cache.clear; returns cleared.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.reset · method
Reset the scheduler state.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method Scheduler.reset updates self._current_sampler_params; calls self._pending_abort_ids.clear, list, self.requests.keys, self._do_abort_request.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.deep_reset · method
Deep reset that clears ALL cache state including model-level caches.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method Scheduler.deep_reset updates self.model.cache; calls self.reset, hasattr, gc.collect, logger.info.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.save_cache_to_disk · method
Save prefix cache to disk for persistence across restarts.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache_dir |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
self.memory_aware_cache.save_to_disk(cache_dir);False
Exceptions and behavior
Method Scheduler.save_cache_to_disk calls self.memory_aware_cache.save_to_disk, logger.info; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.load_cache_from_disk · method
Load prefix cache from disk.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache_dir |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
int - Direct return expressions:
self.memory_aware_cache.load_from_disk(cache_dir);0
Exceptions and behavior
Method Scheduler.load_cache_from_disk calls self.memory_aware_cache.load_from_disk, logger.info; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.clear_prefix_cache · method
Clear the in-memory prefix cache (keeps disk cache untouched).
Parameters
This callable has no explicit inputs.
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method Scheduler.clear_prefix_cache calls hasattr, self.memory_aware_cache.clear, logger.info, self.prefix_cache.clear; returns None.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.close_ssd_tier · method
Shut down the SSD cache tier if present.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method Scheduler.close_ssd_tier updates self._ssd_tier; calls self._ssd_tier.close, logger.info.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._try_promote_ssd_pending · method
Attempt synchronous SSD promotion for waiting requests tagged ssd_pending.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method Scheduler._try_promote_ssd_pending updates self._ssd_tier._stats.promotion_failures, self._ssd_tier._stats.ssd_hits; calls getattr, self.memory_aware_cache.try_reserve_memory, logger.info, tuple.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.promote_from_ssd · method
Promote a cold-tier cache entry for a request (async version).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
False;True
Exceptions and behavior
Method Scheduler.promote_from_ssd calls getattr, candidate.get, len, tuple; awaits asynchronous work; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.promote_from_ssd.reserve_budget · nested function
Tentatively reserve RAM budget for promotion.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
nbytes |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
False;self.memory_aware_cache.try_reserve_memory(nbytes)
Exceptions and behavior
Nested Function Scheduler.promote_from_ssd.reserve_budget calls self.memory_aware_cache.try_reserve_memory; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler.promote_from_ssd.release_budget · nested function
Release tentatively reserved budget on failure.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
nbytes |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Nested Function Scheduler.promote_from_ssd.release_budget calls self.memory_aware_cache.release_reserved_memory.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._reconstruct_ssd_layers · method
Reconstruct cache objects from deserialized layer dicts.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
layer_dicts |
list[dict] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
list | None - Direct return expressions:
None;result
Exceptions and behavior
Method Scheduler._reconstruct_ssd_layers calls KVCache, mx.array, ld.get, _mx_dtype_from_name; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.scheduler.Scheduler._reconstruct_ssd_layers._mx_dtype_from_name · nested function
vllm_mlx.scheduler.Scheduler._reconstruct_ssd_layers._mx_dtype_from_name(name: str) -> not annotated
Nested Function Scheduler._reconstruct_ssd_layers._mx_dtype_from_name calls getattr; returns getattr(mx, name, None).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
name |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
getattr(mx, name, None)
Exceptions and behavior
Nested Function Scheduler._reconstruct_ssd_layers._mx_dtype_from_name calls getattr; returns getattr(mx, name, None).
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 |
|---|---|---|---|---|
_normalize_logits_processors |
function | _normalize_logits_processors(logits_processors) -> not annotated |
Normalize empty per-sequence processor slots to lists. | #L46-L50 |
_sanitize_batch_generator_logits_processors |
function | _sanitize_batch_generator_logits_processors(batch_generator) -> None |
Sanitize stale BatchGenerator processor state before decode. | #L53-L65 |
SchedulingPolicy |
class | SchedulingPolicy() |
Scheduling policy for request ordering. | #L68-L72 |
SchedulerConfig |
class | SchedulerConfig(max_num_seqs: int = 256, max_num_batched_tokens: int = 8192, policy: SchedulingPolicy = SchedulingPolicy.FCFS, prefill_batch_size: int = 8, completion_batch_size: int = 32, prefill_step_size: int = 2048, mllm_prefill_step_size: Optional[int] = None, enable_prefix_cache: bool = True, prefix_cache_size: int = 100, use_memory_aware_cache: bool = True, cache_memory_mb: Optional[int] = None, cache_memory_percent: float = 0.2, kv_cache_quantization: bool = False, kv_cache_quantization_bits: int = 8, kv_cache_quantization_group_size: int = 64, kv_cache_min_quantize_tokens: int = 256, use_paged_cache: bool = False, paged_cache_block_size: int = 64, max_cache_blocks: int = 1000, chunked_prefill_tokens: int = 0, mid_prefill_save_interval: int = 8192, ssd_cache_dir: Optional[str] = None, ssd_cache_max_gb: float = 10.0, max_kv_size: int = 0, enable_mtp: bool = False, mtp_num_draft_tokens: int = 1, mtp_optimistic: bool = False) |
Configuration for the scheduler. | #L76-L140 |
SchedulerConfig.__post_init__ |
method | SchedulerConfig.__post_init__() -> None |
Method SchedulerConfig.__post_init__ calls ValueError; can raise ValueError. |
#L138-L140 |
SchedulerOutput |
class | SchedulerOutput(scheduled_request_ids: List[str] = field(default_factory=list), num_scheduled_tokens: int = 0, finished_request_ids: Set[str] = field(default_factory=set), outputs: List[RequestOutput] = field(default_factory=list), has_work: bool = False) |
Output from a scheduling step. | #L144-L160 |
_install_prompt_cache_save |
function | _install_prompt_cache_save(batch_gen: 'BatchGenerator', prompt_cache_save) -> None |
Monkey-patch _process_prompts to capture prompt-only cache state. |
#L163-L187 |
_install_prompt_cache_save._patched_process_prompts |
nested function | _install_prompt_cache_save._patched_process_prompts(prompts, _self = batch_gen) -> not annotated |
Nested Function _install_prompt_cache_save._patched_process_prompts calls _orig_process_prompts, enumerate, prompt_cache_save, batch.extract_cache; returns batch. |
#L177-L185 |
_install_chunked_prefill |
function | _install_chunked_prefill(batch_gen: 'BatchGenerator', budget: int, mid_prefill_save = None, prompt_cache_save = None, pending_abort_ids: Optional[Set[str]] = None, uid_to_request_id: Optional[Dict[int, str]] = None, requests: Optional[Dict[str, Any]] = None) -> None |
Monkey-patch a BatchGenerator instance so that large prefills are broken into chunks of at most budget tokens each. | #L190-L697 |
_install_chunked_prefill._lazy_extract_cache |
nested function | _install_chunked_prefill._lazy_extract_cache(cache, idx) -> not annotated |
Nested Function _install_chunked_prefill._lazy_extract_cache calls c.extract; returns (c.extract(idx) for c in cache). |
#L225-L226 |
_install_chunked_prefill._batch_cls |
nested class | _install_chunked_prefill._batch_cls(uids: List[int], y: Any, logprobs: List[Any], max_tokens: List[int], num_tokens: List[int], cache: List[Any], samplers: List[Any], logits_processors: List[Any], tokens: List[Any]) |
Nested Class _install_chunked_prefill._batch_cls declares 4 direct member(s). |
#L233-L273 |
_install_chunked_prefill._batch_cls.__len__ |
nested function | _install_chunked_prefill._batch_cls.__len__() -> not annotated |
Nested Function _install_chunked_prefill._batch_cls.__len__ calls len; returns len(self.uids). |
#L244-L245 |
_install_chunked_prefill._batch_cls.filter |
nested function | _install_chunked_prefill._batch_cls.filter(keep_idx: List[int]) -> not annotated |
Nested Function _install_chunked_prefill._batch_cls.filter updates self.uids, self.logprobs, self.max_tokens, self.num_tokens; calls mx.array, c.filter. |
#L247-L258 |
_install_chunked_prefill._batch_cls.extend |
nested function | _install_chunked_prefill._batch_cls.extend(other) -> not annotated |
Nested Function _install_chunked_prefill._batch_cls.extend updates self.y; calls self.uids.extend, mx.concatenate, self.logprobs.extend, self.num_tokens.extend. |
#L260-L270 |
_install_chunked_prefill._batch_cls.extract_cache |
nested function | _install_chunked_prefill._batch_cls.extract_cache(idx) -> not annotated |
Nested Function _install_chunked_prefill._batch_cls.extract_cache calls c.extract; returns [c.extract(idx) for c in self.cache]. |
#L272-L273 |
_install_chunked_prefill._patched_process_prompts |
nested function | _install_chunked_prefill._patched_process_prompts(prompts, _self = batch_gen) -> not annotated |
Nested Function _install_chunked_prefill._patched_process_prompts calls _orig_process_prompts, enumerate, prompt_cache_save, batch.extract_cache; returns batch. |
#L291-L299 |
_install_chunked_prefill._generation_step |
nested function | _install_chunked_prefill._generation_step() -> not annotated |
Run one generation step on the active batch. | #L303-L360 |
_install_chunked_prefill._chunked_next |
nested function | _install_chunked_prefill._chunked_next() -> not annotated |
Replacement for _next() that chunks large prefills. | #L362-L678 |
_install_chunked_prefill._patched_remove |
nested function | _install_chunked_prefill._patched_remove(uids_to_remove, _self = batch_gen) -> not annotated |
Clear partial state if aborted request is being prefilled. | #L680-L691 |
_MTPStatsState |
class | _MTPStatsState(counters: Dict[str, int] = field(default_factory=lambda: {'attempted': 0, 'accepted': 0, 'rejected': 0, 'errors': 0}), bypass_counts: Dict[str, int] = field(default_factory=lambda: {'prefill': 0, 'no_active_batch': 0, 'cache_mismatch': 0}), lock: Any = field(default_factory=Lock)) |
Cumulative native-MTP counters shared across generator instances. | #L701-L719 |
_configure_chunked_prefill |
function | _configure_chunked_prefill(scheduler: 'Scheduler', batch_gen: 'BatchGenerator', budget: int, prompt_cache_save) -> None |
Enable the matching legacy or native mlx-lm chunked-prefill API. | #L722-L777 |
_install_mtp |
function | _install_mtp(batch_gen: 'BatchGenerator', model: Any, num_draft_tokens: int = 1, optimistic: bool = False, stats_state: Optional['_MTPStatsState'] = None) -> None |
Monkey-patch a BatchGenerator to use MTP (Multi-Token Prediction) with always-advance strategy for hybrid MambaCache + KVCache. | #L780-L1262 |
_install_mtp._get_mtp_stats |
nested function | _install_mtp._get_mtp_stats() -> Dict[str, Any] |
Nested Function _install_mtp._get_mtp_stats calls dict; returns {'enabled': True, 'requested_draft_tokens': num_draft_tokens, 'effective_draft_tokens': 1, 'mode': 'always_advance_opti…. |
#L823-L845 |
_install_mtp._mtp_bypass_reasons |
nested function | _install_mtp._mtp_bypass_reasons(input_tokens, prompt_cache) -> not annotated |
Nested Function _install_mtp._mtp_bypass_reasons calls reasons.append; returns reasons. |
#L849-L857 |
_install_mtp._record_mtp_bypass |
nested function | _install_mtp._record_mtp_bypass(reasons) -> None |
Nested Function _install_mtp._record_mtp_bypass contains no state mutation, call, raise, return, await, or yield. |
#L859-L862 |
_install_mtp._mtp_step |
nested function | _install_mtp._mtp_step(input_tokens, prompt_cache, samplers, logits_processors, tokens) -> not annotated |
Extended _step with MTP always-advance strategy. | #L864-L1138 |
_install_mtp._mtp_next |
nested function | _install_mtp._mtp_next() -> not annotated |
Wrapper around _next that emits deferred MTP draft tokens. | #L1147-L1247 |
_mtp_status_snapshot |
function | _mtp_status_snapshot(batch_generator) -> Dict[str, Any] |
Function _mtp_status_snapshot calls getattr, callable, get_mtp_stats; has 2 explicit return paths. |
#L1265-L1269 |
Scheduler |
class | Scheduler(model: Any, tokenizer: Any, config: Optional[SchedulerConfig] = None) |
Scheduler for continuous batching using mlx-lm BatchGenerator. | #L1272-L3518 |
Scheduler.__init__ |
method | Scheduler.__init__(model: Any, tokenizer: Any, config: Optional[SchedulerConfig] = None) -> not annotated |
Initialize the scheduler. | #L1286-L1402 |
Scheduler._get_actual_tokenizer |
method | Scheduler._get_actual_tokenizer(tokenizer: Any) -> Any |
Get the actual tokenizer from a processor or tokenizer. | #L1404-L1418 |
Scheduler._decode_tokens |
method | Scheduler._decode_tokens(token_ids: List[int]) -> str |
Decode token IDs to text, handling both tokenizers and processors. | #L1420-L1424 |
Scheduler._get_detokenizer |
method | Scheduler._get_detokenizer(request_id: str) -> Any |
Get or create a streaming detokenizer for a request. | #L1426-L1431 |
Scheduler._cleanup_detokenizer |
method | Scheduler._cleanup_detokenizer(request_id: str) -> None |
Remove the streaming detokenizer for a finished request. | #L1433-L1435 |
Scheduler._get_stop_tokens |
method | Scheduler._get_stop_tokens() -> Set[int] |
Get stop token IDs from tokenizer or processor. | #L1437-L1455 |
Scheduler._create_batch_generator |
method | Scheduler._create_batch_generator(sampling_params: SamplingParams) -> BatchGenerator |
Create a BatchGenerator with the given sampling parameters. | #L1457-L1539 |
Scheduler._create_batch_generator._prefill_progress |
nested function | Scheduler._create_batch_generator._prefill_progress(progress_list) -> not annotated |
Log prefill progress for each uid chunk. | #L1472-L1479 |
Scheduler._make_prompt_cache_save_callback |
method | Scheduler._make_prompt_cache_save_callback() -> not annotated |
Create a callback that stores prompt-only KV/Mamba cache. | #L1541-L1585 |
Scheduler._make_prompt_cache_save_callback._prompt_cache_save |
nested function | Scheduler._make_prompt_cache_save_callback._prompt_cache_save(uid, extracted_cache) -> not annotated |
Nested Function Scheduler._make_prompt_cache_save_callback._prompt_cache_save calls self.uid_to_request_id.get, self.requests.get, list, _trim_cache_offset; returns None. |
#L1554-L1583 |
Scheduler._make_mid_prefill_save_callback |
method | Scheduler._make_mid_prefill_save_callback(save_interval: int) -> not annotated |
Create a callback for saving intermediate KV cache during chunked prefill. | #L1587-L1655 |
Scheduler._make_mid_prefill_save_callback._mid_prefill_save |
nested function | Scheduler._make_mid_prefill_save_callback._mid_prefill_save(uid, processed_tokens, prompt_cache) -> not annotated |
Nested Function Scheduler._make_mid_prefill_save_callback._mid_prefill_save calls self.uid_to_request_id.get, self.requests.get, getattr, self._extract_cache_states; returns None. |
#L1598-L1653 |
Scheduler._close_batch_generator |
method | Scheduler._close_batch_generator() -> None |
Properly close BatchGenerator to restore wired_limit. | #L1657-L1665 |
Scheduler._ensure_batch_generator |
method | Scheduler._ensure_batch_generator(sampling_params: SamplingParams) -> None |
Ensure BatchGenerator exists with compatible settings. | #L1667-L1709 |
Scheduler._validate_cache |
method | Scheduler._validate_cache(cache: Any) -> bool |
Validate that a cache object is usable. | #L1711-L1769 |
Scheduler._extract_cache_states |
method | Scheduler._extract_cache_states(raw_cache: List[Any]) -> List[Dict[str, Any]] |
Extract actual tensor state from each layer cache. | #L1771-L1806 |
Scheduler._reconstruct_cache_from_states |
method | Scheduler._reconstruct_cache_from_states(extracted_states: List[Dict[str, Any]]) -> Optional[List[Any]] |
Reconstruct cache objects from extracted cache states. | #L1808-L1872 |
Scheduler.add_request |
method | Scheduler.add_request(request: Request) -> None |
Add a new request to the scheduler. | #L1874-L1997 |
Scheduler.abort_request |
method | Scheduler.abort_request(request_id: str) -> bool |
Queue request for abort. | #L1999-L2014 |
Scheduler._process_pending_aborts |
method | Scheduler._process_pending_aborts() -> None |
Drain and process pending abort requests. | #L2016-L2020 |
Scheduler._do_abort_request |
method | Scheduler._do_abort_request(request_id: str) -> bool |
Actually abort a request. | #L2022-L2087 |
Scheduler.has_requests |
method | Scheduler.has_requests() -> bool |
Check if there are any pending or running requests. | #L2089-L2091 |
Scheduler.get_num_waiting |
method | Scheduler.get_num_waiting() -> int |
Get number of waiting requests. | #L2093-L2095 |
Scheduler.get_num_running |
method | Scheduler.get_num_running() -> int |
Get number of running requests. | #L2097-L2099 |
Scheduler._schedule_waiting |
method | Scheduler._schedule_waiting() -> List[Request] |
Move requests from waiting queue to running. | #L2101-L2276 |
Scheduler._copy_cache_state |
method | Scheduler._copy_cache_state(value: Any) -> Any |
Deep-copy a cache state payload. |
#L2279-L2295 |
Scheduler._prompt_output_entry_is_useless |
method | Scheduler._prompt_output_entry_is_useless(cache: Any) -> bool |
Would a prompt+output entry built from this cache ever be reusable? | #L2303-L2317 |
Scheduler._extract_cache_for_uid |
method | Scheduler._extract_cache_for_uid(uid: int) -> Any |
Pull one sequence's cache out of the live BatchGenerator batch. | #L2319-L2336 |
Scheduler._make_snapshot_destination |
method | Scheduler._make_snapshot_destination(live_cache: Any) -> Any |
Build a destination cache with the same topology as the live one. | #L2338-L2380 |
Scheduler._make_snapshot_destination._mirror |
nested function | Scheduler._make_snapshot_destination._mirror(layer: Any) -> Any |
Nested Function Scheduler._make_snapshot_destination._mirror calls getattr, _mirror, copy.copy, type(children); has 2 explicit return paths. |
#L2360-L2370 |
Scheduler._cache_coverage |
method | Scheduler._cache_coverage(cache: Any) -> int \| None |
How many tokens the live cache actually holds. | #L2383-L2409 |
Scheduler._cache_coverage._offset_of |
nested function | Scheduler._cache_coverage._offset_of(layer: Any) -> int \| None |
Nested Function Scheduler._cache_coverage._offset_of calls getattr, isinstance, _offset_of; has 3 explicit return paths. |
#L2393-L2403 |
Scheduler._cache_key_for_snapshot |
method | Scheduler._cache_key_for_snapshot(request: Any, response: Any, raw_cache: Any) -> list[int] \| None |
Key the entry by the tokens the cache covers, not by the prompt. | #L2411-L2468 |
Scheduler._store_prompt_only_cache |
method | Scheduler._store_prompt_only_cache(request: Any, response: Any) -> None |
Store the post-prefill cache under the prompt tokens alone. | #L2470-L2581 |
Scheduler._process_batch_responses |
method | Scheduler._process_batch_responses(responses: List[Any]) -> Tuple[List[RequestOutput], Set[str]] |
Process responses from BatchGenerator. | #L2583-L2710 |
Scheduler._cleanup_finished |
method | Scheduler._cleanup_finished(finished_ids: Set[str]) -> None |
Clean up finished requests and store caches for reuse. | #L2712-L2865 |
Scheduler._is_cache_corruption_error |
method | Scheduler._is_cache_corruption_error(error: Exception) -> bool |
Check if an error indicates cache corruption. | #L2867-L2870 |
Scheduler._is_stream_thread_error |
method | Scheduler._is_stream_thread_error(error: Exception) -> bool |
Check if an error indicates MLX stream/thread ownership mismatch. | #L2872-L2875 |
Scheduler._recover_from_cache_error |
method | Scheduler._recover_from_cache_error() -> None |
Recover from cache corruption error. | #L2877-L2895 |
Scheduler._recover_from_generation_error |
method | Scheduler._recover_from_generation_error() -> Set[str] |
Recover from fatal generation error (OOM, Metal crash). | #L2897-L2933 |
Scheduler._reschedule_running_requests |
method | Scheduler._reschedule_running_requests() -> None |
Move running requests back to waiting queue for retry. | #L2935-L2951 |
Scheduler.step |
method | Scheduler.step(max_retries: int = 1) -> SchedulerOutput |
Execute one scheduling step with automatic error recovery. | #L2953-L3089 |
Scheduler.get_request |
method | Scheduler.get_request(request_id: str) -> Optional[Request] |
Get a request by ID. | #L3091-L3093 |
Scheduler.remove_finished_request |
method | Scheduler.remove_finished_request(request_id: str) -> Optional[Request] |
Remove a finished request from tracking. | #L3095-L3097 |
Scheduler.get_running_requests_info |
method | Scheduler.get_running_requests_info() -> List[Dict[str, Any]] |
Per-request details for status endpoint. | #L3099-L3165 |
Scheduler.get_stats |
method | Scheduler.get_stats() -> Dict[str, Any] |
Get scheduler statistics. | #L3167-L3193 |
Scheduler.get_cache_stats |
method | Scheduler.get_cache_stats() -> Optional[Dict[str, Any]] |
Get cache statistics. | #L3195-L3203 |
Scheduler.clear_runtime_caches |
method | Scheduler.clear_runtime_caches() -> Dict[str, bool] |
Clear prefix-cache state without resetting scheduler/request state. | #L3205-L3221 |
Scheduler.reset |
method | Scheduler.reset() -> None |
Reset the scheduler state. | #L3223-L3246 |
Scheduler.deep_reset |
method | Scheduler.deep_reset() -> None |
Deep reset that clears ALL cache state including model-level caches. | #L3248-L3276 |
Scheduler.save_cache_to_disk |
method | Scheduler.save_cache_to_disk(cache_dir: str) -> bool |
Save prefix cache to disk for persistence across restarts. | #L3282-L3287 |
Scheduler.load_cache_from_disk |
method | Scheduler.load_cache_from_disk(cache_dir: str) -> int |
Load prefix cache from disk. | #L3289-L3294 |
Scheduler.clear_prefix_cache |
method | Scheduler.clear_prefix_cache() -> None |
Clear the in-memory prefix cache (keeps disk cache untouched). | #L3296-L3306 |
Scheduler.close_ssd_tier |
method | Scheduler.close_ssd_tier() -> None |
Shut down the SSD cache tier if present. | #L3308-L3313 |
Scheduler._try_promote_ssd_pending |
method | Scheduler._try_promote_ssd_pending() -> None |
Attempt synchronous SSD promotion for waiting requests tagged ssd_pending. | #L3315-L3395 |
Scheduler.promote_from_ssd |
method | async Scheduler.promote_from_ssd(request) -> bool |
Promote a cold-tier cache entry for a request (async version). | #L3397-L3460 |
Scheduler.promote_from_ssd.reserve_budget |
nested function | Scheduler.promote_from_ssd.reserve_budget(nbytes: int) -> bool |
Tentatively reserve RAM budget for promotion. | #L3412-L3416 |
Scheduler.promote_from_ssd.release_budget |
nested function | Scheduler.promote_from_ssd.release_budget(nbytes: int) -> None |
Release tentatively reserved budget on failure. | #L3418-L3421 |
Scheduler._reconstruct_ssd_layers |
method | Scheduler._reconstruct_ssd_layers(layer_dicts: list[dict]) -> list \| None |
Reconstruct cache objects from deserialized layer dicts. | #L3462-L3518 |
Scheduler._reconstruct_ssd_layers._mx_dtype_from_name |
nested function | Scheduler._reconstruct_ssd_layers._mx_dtype_from_name(name: str) -> not annotated |
Nested Function Scheduler._reconstruct_ssd_layers._mx_dtype_from_name calls getattr; returns getattr(mx, name, None). |
#L3473-L3474 |