vllm_mlx.models.mllm¶
MLX Multimodal Language Model (MLLM) wrapper.
View the complete module source at #L1-L2944.
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.models.mllm
¶
MLX Multimodal Language Model (MLLM) wrapper.
This module provides a wrapper around mlx-vlm for multimodal inference, supporting vision, audio, and video understanding on Apple Silicon.
Features: - OpenAI-compatible API format for images and video - Smart video frame extraction with configurable FPS - Base64 and URL image support - Streaming generation - MLLM KV cache for repeated image/video+prompt combinations
vllm_mlx.models.mllm.MAX_BASE64_IMAGE_LENGTH
module-attribute
¶
vllm_mlx.models.mllm.MAX_BASE64_VIDEO_LENGTH
module-attribute
¶
vllm_mlx.models.mllm.MAX_BASE64_AUDIO_LENGTH
module-attribute
¶
vllm_mlx.models.mllm._DRAFT_KWARG_NAMES
module-attribute
¶
vllm_mlx.models.mllm._VIDEO_EXT_MAP
module-attribute
¶
_VIDEO_EXT_MAP: dict[str, str] = {'mp4': '.mp4', 'webm': '.webm', 'avi': '.avi', 'mov': '.mov', 'quicktime': '.mov', 'mkv': '.mkv'}
vllm_mlx.models.mllm._AUDIO_EXT_MAP
module-attribute
¶
_AUDIO_EXT_MAP: dict[str, str] = {'wav': '.wav', 'mpeg': '.mp3', 'mp3': '.mp3', 'flac': '.flac', 'ogg': '.ogg', 'webm': '.webm', 'mp4': '.m4a', 'm4a': '.m4a', 'aac': '.m4a'}
vllm_mlx.models.mllm._base64_image_cache
module-attribute
¶
vllm_mlx.models.mllm.MLXVisionLanguageModel
module-attribute
¶
MLXVisionLanguageModel = MLXMultimodalLM
vllm_mlx.models.mllm.TempFileManager
¶
Thread-safe manager for tracking and cleaning up temporary files.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.TempFileManager.register
¶
vllm_mlx.models.mllm.TempFileManager.cleanup
¶
Clean up a specific temp file. Returns True if successful.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.TempFileManager.cleanup_all
¶
Clean up all tracked temp files. Returns count of cleaned files.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.FileSizeExceededError
¶
Bases: Exception
Raised when a downloaded file exceeds the size limit.
vllm_mlx.models.mllm.UnsafeRemoteURLError
¶
Bases: ValueError
Raised when a remote media URL targets an unsafe destination.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.UnsafeRemoteURLError.public_message
instance-attribute
¶
vllm_mlx.models.mllm.MultimodalInput
dataclass
¶
MultimodalInput(prompt: str, images: list[str] = list(), videos: list[str] = list(), audio: list[str] = list())
vllm_mlx.models.mllm.MLLMOutput
dataclass
¶
MLLMOutput(text: str, finish_reason: str | None = None, prompt_tokens: int = 0, completion_tokens: int = 0, mtp_drafts: int = 0, mtp_accepted: int = 0)
Output from multimodal language model.
vllm_mlx.models.mllm.MLLMOutput.finish_reason
class-attribute
instance-attribute
¶
vllm_mlx.models.mllm.MLLMOutput.prompt_tokens
class-attribute
instance-attribute
¶
vllm_mlx.models.mllm.MLLMOutput.completion_tokens
class-attribute
instance-attribute
¶
vllm_mlx.models.mllm.MLLMOutput.mtp_accepted
class-attribute
instance-attribute
¶
vllm_mlx.models.mllm.MLXMultimodalLM
¶
MLXMultimodalLM(model_name: str, trust_remote_code: bool = False, enable_cache: bool = True, cache_size: int = 50, max_kv_size: int = 0, draft_model: str | None = None, draft_kind: str | None = None, draft_block_size: int | None = None)
Wrapper around mlx-vlm for multimodal inference.
This class provides a unified interface for multimodal language models using Apple's MLX framework. Supports: - Image understanding (single and multi-image) - Video understanding (smart frame extraction) - Audio understanding (for supported models) - OpenAI-compatible API format
Supported models include: - Qwen2-VL / Qwen2.5-VL / Qwen3-VL - LLaVA - Idefics3 - PaliGemma - And more via mlx-vlm
Example
model = MLXMultimodalLM("mlx-community/Qwen2-VL-2B-Instruct-4bit") model.load() output = model.generate( ... prompt="What's in this image?", ... images=["photo.jpg"] ... ) print(output.text)
Initialize the MLX multimodal language model.
Parameters:
-
model_name(str) –HuggingFace model name or local path
-
trust_remote_code(bool, default:False) –Whether to trust remote code
-
enable_cache(bool, default:True) –Enable KV cache for repeated image/video+prompt (default: True)
-
cache_size(int, default:50) –Maximum cache entries (default: 50)
-
max_kv_size(int, default:0) –Maximum KV cache size per sequence (0 = unbounded)
-
draft_model(str | None, default:None) –Optional MLLM speculative draft/assistant model path.
-
draft_kind(str | None, default:None) –Optional mlx-vlm draft kind, for example "mtp".
-
draft_block_size(int | None, default:None) –Optional speculative block size passed to mlx-vlm.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM.trust_remote_code
instance-attribute
¶
vllm_mlx.models.mllm.MLXMultimodalLM.draft_model_path
instance-attribute
¶
vllm_mlx.models.mllm.MLXMultimodalLM.draft_block_size
instance-attribute
¶
vllm_mlx.models.mllm.MLXMultimodalLM._video_native_with_audio
instance-attribute
¶
vllm_mlx.models.mllm.MLXMultimodalLM._cache_manager
instance-attribute
¶
_cache_manager: MLLMPrefixCacheManager | None = None
vllm_mlx.models.mllm.MLXMultimodalLM.load
¶
Load the model and processor.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM._load_draft_model
¶
vllm_mlx.models.mllm.MLXMultimodalLM._draft_generation_kwargs
¶
Return mlx-vlm drafter kwargs when the request explicitly opts in.
call_kwargs is the outbound mlx-vlm kwargs dict. This method removes
vllm-mlx drafter control keys before the dict is forwarded so caller
passthrough values cannot conflict with the configured server drafter.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM._reset_draft_metrics
¶
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM._draft_metrics_since
¶
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM.get_language_model
¶
vllm_mlx.models.mllm.MLXMultimodalLM.get_tokenizer
¶
vllm_mlx.models.mllm.MLXMultimodalLM._prepare_images
¶
Process remote/base64 image inputs into local temp file paths.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM._prepare_audio
¶
Process audio inputs and return local file paths.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM._prepare_video
¶
_prepare_video(video_input: str | dict, fps: float = DEFAULT_FPS, max_frames: int = MAX_FRAMES, resolved_path: str | None = None) -> list[str]
Process video input and extract frames.
Supports: - URLs (http/https) - will be downloaded - Base64 encoded videos (data:video/mp4;base64,...) - OpenAI format dicts: {"url": "..."} or {"video_url": {"url": "..."}}
Parameters:
-
video_input(str | dict) –Video in any supported format
-
fps(float, default:DEFAULT_FPS) –Frames per second to extract
-
max_frames(int, default:MAX_FRAMES) –Maximum frames to extract
-
resolved_path(str | None, default:None) –Optional pre-resolved local path. Callers that already ran process_video_input (e.g. for parallel audio extraction) pass it here to avoid re-downloading / re-decoding.
Returns:
-
list[str]–List of paths to extracted frame images
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM._collect_video_inputs
¶
Collect video inputs from messages, keyed by message index.
Handles both 'video' and 'video_url' content types, including Pydantic model conversion.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM._collect_audio_inputs
¶
Collect audio inputs from messages, keyed by message index.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM._prepare_native_video_inputs
¶
_prepare_native_video_inputs(messages: list[dict], video_fps: float = DEFAULT_FPS, video_max_frames: int = MAX_FRAMES, tools: list | None = None) -> tuple[str, dict]
Preprocess messages into prompt + generation kwargs for native video.
Mirrors the preprocessing in mlx_vlm.video_generate.main() so that upstream improvements are easy to adopt. Returns the formatted prompt text and a dict of kwargs ready to pass to video_generate.generate().
Currently Qwen-family-specific (video_token_id / video_token_index).
Source code in vllm_mlx/models/mllm.py
1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 | |
vllm_mlx.models.mllm.MLXMultimodalLM._generate_native_video
¶
_generate_native_video(messages: list[dict], max_tokens: int = 256, temperature: float = 0.7, video_fps: float = DEFAULT_FPS, video_max_frames: int = MAX_FRAMES, tools: list | None = None, **kwargs) -> MLLMOutput
Generate using native video pipeline (Qwen-family models).
Delegates preprocessing to _prepare_native_video_inputs and generation to mlx_vlm.video_generate.generate(), keeping our code aligned with upstream's video pipeline so improvements are easy to adopt.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM._translate_messages_for_native_video
¶
_translate_messages_for_native_video(messages: list[dict], video_fps: float, video_max_frames: int) -> list[dict]
Translate OpenAI API format messages to process_vision_info format.
Converts video_url/video types and resolves remote/base64 inputs to local paths. Images are preserved as-is (process_vision_info handles them).
Source code in vllm_mlx/models/mllm.py
1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 | |
vllm_mlx.models.mllm.MLXMultimodalLM.generate
¶
generate(prompt: str, images: list | None = None, videos: list | None = None, audio: list[str] | None = None, max_tokens: int = 256, temperature: float = 0.7, top_p: float = 0.9, video_fps: float = DEFAULT_FPS, video_max_frames: int = MAX_FRAMES, use_cache: bool = True, **kwargs) -> MLLMOutput
Generate text from multimodal input.
Parameters:
-
prompt(str) –Text prompt/question
-
images(list | None, default:None) –List of image URLs or base64 strings
-
videos(list | None, default:None) –List of video inputs (URLs, base64, or OpenAI format dicts)
-
audio(list[str] | None, default:None) –List of audio file paths
-
max_tokens(int, default:256) –Maximum tokens to generate
-
temperature(float, default:0.7) –Sampling temperature
-
top_p(float, default:0.9) –Top-p sampling parameter
-
video_fps(float, default:DEFAULT_FPS) –FPS for video frame extraction (default: 2.0)
-
video_max_frames(int, default:MAX_FRAMES) –Max frames to extract from video
-
use_cache(bool, default:True) –Whether to use KV cache (default: True)
-
**kwargs–Additional generation parameters
Returns:
-
MLLMOutput–MLLMOutput with generated text
Example
With local video¶
output = model.generate("Describe this video", videos=["video.mp4"])
With video URL¶
output = model.generate("What happens?", videos=["https://example.com/video.mp4"])
With base64 video¶
output = model.generate("Describe", videos=["data:video/mp4;base64,AAAA..."])
Source code in vllm_mlx/models/mllm.py
1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 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 1998 1999 2000 2001 2002 | |
vllm_mlx.models.mllm.MLXMultimodalLM.stream_generate
¶
stream_generate(prompt: str, images: list | None = None, videos: list[str] | None = None, audio: list[str] | None = None, max_tokens: int = 256, temperature: float = 0.7, video_fps: float = DEFAULT_FPS, **kwargs) -> Iterator[str]
Stream text generation for multimodal input.
Parameters:
-
prompt(str) –Text prompt
-
images(list | None, default:None) –List of image inputs
-
videos(list[str] | None, default:None) –List of video paths
-
audio(list[str] | None, default:None) –List of audio inputs
-
max_tokens(int, default:256) –Maximum tokens to generate
-
temperature(float, default:0.7) –Sampling temperature
-
video_fps(float, default:DEFAULT_FPS) –FPS for video frame extraction
-
**kwargs–Additional parameters
Yields:
-
str–Generated text chunks
Source code in vllm_mlx/models/mllm.py
2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 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 2088 2089 2090 2091 2092 2093 | |
vllm_mlx.models.mllm.MLXMultimodalLM.chat
¶
chat(messages: list[dict], max_tokens: int = 256, temperature: float = 0.7, **kwargs) -> MLLMOutput
Chat with OpenAI-compatible message format.
Supports multimodal content in messages: - {"type": "text", "text": "..."} - {"type": "image_url", "image_url": {"url": "..."}} - {"type": "image_url", "image_url": {"url": "data:image/...;base64,..."}}
Parameters:
-
messages(list[dict]) –List of chat messages (OpenAI format)
-
max_tokens(int, default:256) –Maximum tokens to generate
-
temperature(float, default:0.7) –Sampling temperature
-
**kwargs–Additional parameters
Returns:
-
MLLMOutput–MLLMOutput with assistant's response
Source code in vllm_mlx/models/mllm.py
2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 | |
vllm_mlx.models.mllm.MLXMultimodalLM.stream_chat
¶
stream_chat(messages: list[dict], max_tokens: int = 256, temperature: float = 0.7, **kwargs) -> Iterator[MLLMOutput]
Stream chat with OpenAI-compatible message format.
Supports multimodal content in messages: - {"type": "text", "text": "..."} - {"type": "image_url", "image_url": {"url": "..."}} - {"type": "image_url", "image_url": {"url": "data:image/...;base64,..."}}
Parameters:
-
messages(list[dict]) –List of chat messages (OpenAI format)
-
max_tokens(int, default:256) –Maximum tokens to generate
-
temperature(float, default:0.7) –Sampling temperature
-
**kwargs–Additional parameters
Yields:
-
MLLMOutput–MLLMOutput with incremental text chunks
Source code in vllm_mlx/models/mllm.py
2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 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 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 | |
vllm_mlx.models.mllm.MLXMultimodalLM.describe_image
¶
describe_image(image: str, prompt: str = 'Describe this image in detail.', max_tokens: int = 512, **kwargs) -> str
Convenience method to describe an image.
Parameters:
-
image(str) –Image path, URL, or base64 string
-
prompt(str, default:'Describe this image in detail.') –Description prompt
-
max_tokens(int, default:512) –Maximum tokens
-
**kwargs–Additional parameters
Returns:
-
str–Image description text
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM.answer_about_image
¶
Answer a question about an image.
Parameters:
-
image(str) –Image path, URL, or base64 string
-
question(str) –Question about the image
-
max_tokens(int, default:256) –Maximum tokens
-
**kwargs–Additional parameters
Returns:
-
str–Answer text
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM.describe_video
¶
describe_video(video: str | dict, prompt: str = 'Describe what happens in this video.', fps: float = 2.0, max_frames: int = 32, max_tokens: int = 512, **kwargs) -> str
Describe a video using frame extraction.
Parameters:
-
video(str | dict) –Video file path, URL, base64, or OpenAI format dict
-
prompt(str, default:'Describe what happens in this video.') –Description prompt
-
fps(float, default:2.0) –Frames per second to extract
-
max_frames(int, default:32) –Maximum frames to extract
-
max_tokens(int, default:512) –Maximum tokens to generate
Returns:
-
str–Video description text
Example
URL¶
model.describe_video("https://example.com/video.mp4")
OpenAI format¶
model.describe_video({"url": "https://example.com/video.mp4"})
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM.get_cache_stats
¶
Get MLLM cache statistics.
Returns:
-
dict–Dictionary with cache stats (hits, misses, hit_rate, tokens_saved, etc.)
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM.clear_cache
¶
vllm_mlx.models.mllm.MLXMultimodalLM.get_model_info
¶
Get information about the loaded model.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM.list_supported_model_families
staticmethod
¶
List supported model families and their patterns.
Any model on HuggingFace containing these patterns in the name is likely compatible with mlx-vlm.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.MLXMultimodalLM.is_mllm_model
staticmethod
¶
Check if a model name indicates an MLLM model.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.cleanup_temp_file
¶
vllm_mlx.models.mllm.cleanup_all_temp_files
¶
vllm_mlx.models.mllm._normalize_content_part
¶
Convert Pydantic content parts into plain Python objects.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm._extract_media_url
¶
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm._text_content_part
¶
vllm_mlx.models.mllm._append_text_content_part
¶
vllm_mlx.models.mllm._build_string_mllm_message_content
¶
vllm_mlx.models.mllm._append_ordered_mllm_content_part
¶
_append_ordered_mllm_content_part(raw_item: object, *, built_parts: list[dict[str, str]], text_parts: list[str], all_image_urls: list[str], video_frame_count: int) -> int
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm._build_ordered_mllm_message_content
¶
_build_ordered_mllm_message_content(content: object, *, role: str, all_image_urls: list[str], video_frame_count: int = 0) -> tuple[object, bool]
Build template content while preserving OpenAI media/text part order.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm._normalize_mllm_tool_calls
¶
Normalize replayed assistant tool calls for chat templates.
Mirrors _normalize_tool_call_arguments_for_template in
vllm_mlx/engine/batched.py: JSON argument strings become mappings so
templates that iterate argument keys render correctly.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm._build_mllm_chat_messages
¶
_build_mllm_chat_messages(messages: list[dict], *, all_image_urls: list[str], video_frame_counts: dict[int, int]) -> list[dict]
Build chat-template messages without reordering multimodal content parts.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.load_gemma4_assistant_drafter
¶
Load a Gemma 4 assistant drafter for mlx-vlm speculative decoding.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm._count_draft_tokens
¶
Best-effort drafted-token count for an mlx-vlm drafter output.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm._install_draft_metrics_hooks
¶
Record actual drafted token counts from mlx-vlm assistant drafters.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.is_base64_image
¶
vllm_mlx.models.mllm.is_url
¶
vllm_mlx.models.mllm.is_base64_video
¶
vllm_mlx.models.mllm.is_base64_audio
¶
vllm_mlx.models.mllm.decode_base64_image
¶
decode_base64_image(base64_string: str, max_length: int = MAX_BASE64_IMAGE_LENGTH) -> bytes
Decode base64 image to bytes.
Parameters:
-
base64_string(str) –Base64 encoded image (optionally with data URL prefix)
-
max_length(int, default:MAX_BASE64_IMAGE_LENGTH) –Maximum allowed length of base64 string
Returns:
-
bytes–Decoded image bytes
Raises:
-
FileSizeExceededError–If base64 string exceeds max_length
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm._validate_url_safety
¶
Reject remote URLs that target local or private network resources.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm._request_with_safe_redirects
¶
_request_with_safe_redirects(method: str, url: str, *, timeout: int, headers: dict[str, str], stream: bool = False, max_redirects: int = 5)
Issue a requests call while validating every redirect target.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.download_image
¶
download_image(url: str, timeout: int = 30, max_size: int = MAX_IMAGE_SIZE) -> str
Download image from URL and return local path.
Parameters:
-
url(str) –Image URL
-
timeout(int, default:30) –Download timeout in seconds
-
max_size(int, default:MAX_IMAGE_SIZE) –Maximum allowed file size in bytes
Returns:
-
str–Local file path to downloaded image
Raises:
-
FileSizeExceededError–If image exceeds max_size
Source code in vllm_mlx/models/mllm.py
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 | |
vllm_mlx.models.mllm._download_media
¶
_download_media(url: str, media_type: str, ext_map: dict[str, str], default_ext: str, timeout: int, max_size: int) -> str
Download media from URL, enforce size limits, and return a local temp path.
Source code in vllm_mlx/models/mllm.py
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 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 | |
vllm_mlx.models.mllm.download_video
¶
download_video(url: str, timeout: int = 120, max_size: int = MAX_VIDEO_SIZE) -> str
Download video from URL and return local path.
vllm_mlx.models.mllm.download_audio
¶
download_audio(url: str, timeout: int = 120, max_size: int = MAX_AUDIO_SIZE) -> str
Download audio from URL and return local path.
vllm_mlx.models.mllm.decode_base64_video
¶
decode_base64_video(base64_string: str, max_length: int = MAX_BASE64_VIDEO_LENGTH) -> str
Decode base64 video to temp file and return path.
Supports format: data:video/mp4;base64,AAAA...
Parameters:
-
base64_string(str) –Base64-encoded video with data URL prefix
-
max_length(int, default:MAX_BASE64_VIDEO_LENGTH) –Maximum allowed length of base64 string
Returns:
-
str–Local file path to decoded video
Raises:
-
FileSizeExceededError–If base64 string exceeds max_length
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.decode_base64_audio
¶
decode_base64_audio(base64_string: str, max_length: int = MAX_BASE64_AUDIO_LENGTH) -> str
Decode base64 audio to temp file and return path.
Supports format: data:audio/wav;base64,AAAA...
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.process_video_input
¶
Process video input in various formats and return local path.
Supports: - URL (http/https) - Base64 encoded string (data:video/mp4;base64,...) - OpenAI format dict: {"url": "..."} or {"url": "data:video/...;base64,..."}
Parameters:
-
video(str | dict) –Video input in any supported format
Returns:
-
str–Local file path to video
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.process_audio_input
¶
Process audio input in various formats and return local path.
Supports: - Local file path - URL (http/https) - Base64 encoded string (data:audio/wav;base64,...) - OpenAI format dict: {"url": "..."} or {"audio_url": {"url": "..."}}
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm._video_has_audio_track
¶
Return True if ffprobe finds an audio stream in the video.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm._model_has_sound_encoder
¶
Whether a loaded model exposes a usable sound encoder.
Uses getattr(..., None) is not None rather than hasattr so model
wrappers that declare sound_encoder in __init__ but leave it as
None until the first encoder pass are correctly treated as not yet
enabled. A bare hasattr check would spuriously enable A/V fusion
against a missing encoder and crash the processor downstream.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.extract_audio_from_video
¶
Extract the audio track from a video file as 16 kHz mono WAV.
Returns the path to the WAV (registered with the temp manager so it's cleaned up automatically), or None if the video has no audio or ffmpeg is unavailable.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.save_base64_image
¶
Save base64 image to temp file and return path. Caches identical images.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.process_image_input
¶
Process image input in various formats and return local path.
Supports: - URL (http/https) - Base64 encoded string - OpenAI format dict: {"url": "..."} or {"url": "data:image/...;base64,..."}
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.round_by_factor
¶
vllm_mlx.models.mllm.ceil_by_factor
¶
vllm_mlx.models.mllm.floor_by_factor
¶
vllm_mlx.models.mllm.smart_nframes
¶
smart_nframes(total_frames: int, video_fps: float, target_fps: float = DEFAULT_FPS, min_frames: int = MIN_FRAMES, max_frames: int = MAX_FRAMES) -> int
Calculate optimal number of frames to extract from video.
Uses smart sampling based on video length and target FPS.
Source code in vllm_mlx/models/mllm.py
vllm_mlx.models.mllm.extract_video_frames_smart
¶
extract_video_frames_smart(video_path: str, fps: float = DEFAULT_FPS, max_frames: int = MAX_FRAMES, resize: tuple[int, int] | None = None) -> list[ndarray]
Extract frames from video with smart sampling.
Parameters:
-
video_path(str) –Path to video file
-
fps(float, default:DEFAULT_FPS) –Target frames per second (default: 2.0)
-
max_frames(int, default:MAX_FRAMES) –Maximum frames to extract
-
resize(tuple[int, int] | None, default:None) –Optional (width, height) to resize frames
Returns:
-
list[ndarray]–List of frame arrays (RGB format)
Source code in vllm_mlx/models/mllm.py
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 | |
vllm_mlx.models.mllm.save_frames_to_temp
¶
Save frame arrays to temporary files and return paths.
Source code in vllm_mlx/models/mllm.py
Complete contract reference¶
Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.
vllm_mlx.models.mllm.TempFileManager · class
Thread-safe manager for tracking and cleaning up temporary files.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.models.mllm.TempFileManager
Exceptions and behavior
Class TempFileManager declares 4 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.TempFileManager.__init__ · method
Method TempFileManager.__init__ updates self._files, self._lock; calls set, threading.Lock, atexit.register.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated
Exceptions and behavior
Method TempFileManager.__init__ updates self._files, self._lock; calls set, threading.Lock, atexit.register.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.TempFileManager.register · method
Register a temp file for tracking.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
path
Exceptions and behavior
Method TempFileManager.register calls self._files.add; returns path.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.TempFileManager.cleanup · method
Clean up a specific temp file.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
True;False
Exceptions and behavior
Method TempFileManager.cleanup calls self._files.discard, os.path.exists, os.unlink, logger.debug; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.TempFileManager.cleanup_all · method
Clean up all tracked temp files.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
cleaned
Exceptions and behavior
Method TempFileManager.cleanup_all calls list, self._files.clear, os.path.exists, os.unlink; returns cleaned.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.cleanup_temp_file · function
Clean up a specific temporary file.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
_temp_manager.cleanup(path)
Exceptions and behavior
Function cleanup_temp_file calls _temp_manager.cleanup; returns _temp_manager.cleanup(path).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.cleanup_all_temp_files · function
Clean up all tracked temporary files.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
_temp_manager.cleanup_all()
Exceptions and behavior
Function cleanup_all_temp_files calls _temp_manager.cleanup_all; returns _temp_manager.cleanup_all().
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.FileSizeExceededError · class
Raised when a downloaded file exceeds the size limit.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.models.mllm.FileSizeExceededError
Exceptions and behavior
Class FileSizeExceededError derives from Exception and declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.UnsafeRemoteURLError · class
vllm_mlx.models.mllm.UnsafeRemoteURLError(message: str, *, public_message: str = 'Remote media URL is not allowed')
Raised when a remote media URL targets an unsafe destination.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
message |
str |
yes |
none |
Required positional or keyword input. |
public_message |
str |
no |
'Remote media URL is not allowed' |
Optional keyword-only input; defaults to 'Remote media URL is not allowed'. |
Returns
- Constructs:
vllm_mlx.models.mllm.UnsafeRemoteURLError
Exceptions and behavior
Class UnsafeRemoteURLError derives from ValueError and declares 1 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.UnsafeRemoteURLError.__init__ · method
vllm_mlx.models.mllm.UnsafeRemoteURLError.__init__(message: str, *, public_message: str = 'Remote media URL is not allowed') -> None
Method UnsafeRemoteURLError.__init__ updates self.public_message; calls super().__init__, super.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
message |
str |
yes |
none |
Required positional or keyword input. |
public_message |
str |
no |
'Remote media URL is not allowed' |
Optional keyword-only input; defaults to 'Remote media URL is not allowed'. |
Returns
- Type:
None
Exceptions and behavior
Method UnsafeRemoteURLError.__init__ updates self.public_message; calls super().__init__, super.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm._normalize_content_part · function
Convert Pydantic content parts into plain Python objects.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
item |
object |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
object - Direct return expressions:
item.model_dump(exclude_none=True);{k: v for k, v in item.dict().items() if v is not None};item
Exceptions and behavior
Function _normalize_content_part calls hasattr, item.model_dump, item.dict().items, item.dict; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm._extract_media_url · function
Function _extract_media_url calls item.get, isinstance, media_value.get; has 2 explicit return paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
item |
dict |
yes |
none |
Required positional or keyword input. |
item_type |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
'';media_value if isinstance(media_value, str) else ''
Exceptions and behavior
Function _extract_media_url calls item.get, isinstance, media_value.get; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm._text_content_part · function
Function _text_content_part returns {'type': 'text', 'text': text, 'content': text}.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict[str, str] - Direct return expressions:
{'type': 'text', 'text': text, 'content': text}
Exceptions and behavior
Function _text_content_part returns {'type': 'text', 'text': text, 'content': text}.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm._append_text_content_part · function
vllm_mlx.models.mllm._append_text_content_part(built_parts: list[dict[str, str]], text_parts: list[str], text: str) -> None
Function _append_text_content_part calls built_parts.append, _text_content_part, text_parts.append; returns None.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
built_parts |
list[dict[str, str]] |
yes |
none |
Required positional or keyword input. |
text_parts |
list[str] |
yes |
none |
Required positional or keyword input. |
text |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Function _append_text_content_part calls built_parts.append, _text_content_part, text_parts.append; returns None.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm._build_string_mllm_message_content · function
vllm_mlx.models.mllm._build_string_mllm_message_content(content: str, role: str) -> tuple[object, bool]
Function _build_string_mllm_message_content calls _text_content_part; has 3 explicit return paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
content |
str |
yes |
none |
Required positional or keyword input. |
role |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
tuple[object, bool] - Direct return expressions:
('', False);(content, True);([_text_content_part(content)], True)
Exceptions and behavior
Function _build_string_mllm_message_content calls _text_content_part; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm._append_ordered_mllm_content_part · function
vllm_mlx.models.mllm._append_ordered_mllm_content_part(raw_item: object, *, built_parts: list[dict[str, str]], text_parts: list[str], all_image_urls: list[str], video_frame_count: int) -> int
Function _append_ordered_mllm_content_part calls _normalize_content_part, isinstance, _append_text_content_part, item.get; has 2 explicit return paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
raw_item |
object |
yes |
none |
Required positional or keyword input. |
built_parts |
list[dict[str, str]] |
yes |
none |
Required keyword-only input. |
text_parts |
list[str] |
yes |
none |
Required keyword-only input. |
all_image_urls |
list[str] |
yes |
none |
Required keyword-only input. |
video_frame_count |
int |
yes |
none |
Required keyword-only input. |
Returns
- Type:
int - Direct return expressions:
video_frame_count;0
Exceptions and behavior
Function _append_ordered_mllm_content_part calls _normalize_content_part, isinstance, _append_text_content_part, item.get; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm._build_ordered_mllm_message_content · function
vllm_mlx.models.mllm._build_ordered_mllm_message_content(content: object, *, role: str, all_image_urls: list[str], video_frame_count: int = 0) -> tuple[object, bool]
Build template content while preserving OpenAI media/text part order.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
content |
object |
yes |
none |
Required positional or keyword input. |
role |
str |
yes |
none |
Required keyword-only input. |
all_image_urls |
list[str] |
yes |
none |
Required keyword-only input. |
video_frame_count |
int |
no |
0 |
Optional keyword-only input; defaults to 0. |
Returns
- Type:
tuple[object, bool] - Direct return expressions:
_build_string_mllm_message_content(content, role);('', False);(text, bool(text));(built_parts, bool(built_parts))
Exceptions and behavior
Function _build_ordered_mllm_message_content calls isinstance, _build_string_mllm_message_content, _append_ordered_mllm_content_part, ''.join; has 4 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm._normalize_mllm_tool_calls · function
Normalize replayed assistant tool calls for chat templates.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tool_calls |
list |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
list - Direct return expressions:
normalized[0].get('tool_calls', plain_calls)
Exceptions and behavior
Function _normalize_mllm_tool_calls calls _normalize_content_part, normalize_messages_for_chat_template, normalized[0].get; returns normalized[0].get('tool_calls', plain_calls).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm._build_mllm_chat_messages · function
vllm_mlx.models.mllm._build_mllm_chat_messages(messages: list[dict], *, all_image_urls: list[str], video_frame_counts: dict[int, int]) -> list[dict]
Build chat-template messages without reordering multimodal content parts.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
messages |
list[dict] |
yes |
none |
Required positional or keyword input. |
all_image_urls |
list[str] |
yes |
none |
Required keyword-only input. |
video_frame_counts |
dict[int, int] |
yes |
none |
Required keyword-only input. |
Returns
- Type:
list[dict] - Direct return expressions:
chat_messages
Exceptions and behavior
Function _build_mllm_chat_messages calls enumerate, msg.get, isinstance, str; returns chat_messages.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MultimodalInput · class
vllm_mlx.models.mllm.MultimodalInput(prompt: str, images: list[str] = field(default_factory=list), videos: list[str] = field(default_factory=list), audio: list[str] = field(default_factory=list))
Input for multimodal generation.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
prompt |
str |
yes |
none |
Required constructor field. |
images |
list[str] |
no |
field(default_factory=list) |
Optional constructor field; defaults to field(default_factory=list). |
videos |
list[str] |
no |
field(default_factory=list) |
Optional constructor field; defaults to field(default_factory=list). |
audio |
list[str] |
no |
field(default_factory=list) |
Optional constructor field; defaults to field(default_factory=list). |
Returns
- Constructs:
vllm_mlx.models.mllm.MultimodalInput
Exceptions and behavior
Class MultimodalInput declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLLMOutput · class
vllm_mlx.models.mllm.MLLMOutput(text: str, finish_reason: str | None = None, prompt_tokens: int = 0, completion_tokens: int = 0, mtp_drafts: int = 0, mtp_accepted: int = 0)
Output from multimodal language model.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text |
str |
yes |
none |
Required constructor field. |
finish_reason |
str \| None |
no |
None |
Optional constructor field; defaults to None. |
prompt_tokens |
int |
no |
0 |
Optional constructor field; defaults to 0. |
completion_tokens |
int |
no |
0 |
Optional constructor field; defaults to 0. |
mtp_drafts |
int |
no |
0 |
Optional constructor field; defaults to 0. |
mtp_accepted |
int |
no |
0 |
Optional constructor field; defaults to 0. |
Returns
- Constructs:
vllm_mlx.models.mllm.MLLMOutput
Exceptions and behavior
Class MLLMOutput declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.load_gemma4_assistant_drafter · function
Load a Gemma 4 assistant drafter for mlx-vlm speculative decoding.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
model
Exceptions and behavior
Function load_gemma4_assistant_drafter calls ImportError, version, logger.info, Path; can raise ImportError, FileNotFoundError; returns model.
Directly raised exceptions: ImportError, FileNotFoundError.
vllm_mlx.models.mllm._count_draft_tokens · function
Best-effort drafted-token count for an mlx-vlm drafter output.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
draft_tokens |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
int - Direct return expressions:
max(int(shape[-1]), 0);max(len(draft_tokens), 0);0
Exceptions and behavior
Function _count_draft_tokens calls getattr, max, int, len; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm._install_draft_metrics_hooks · function
Record actual drafted token counts from mlx-vlm assistant drafters.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
draft_model |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Function _install_draft_metrics_hooks calls getattr, hasattr, callable; returns None.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm._install_draft_metrics_hooks.draft_block_with_metrics · nested function
vllm_mlx.models.mllm._install_draft_metrics_hooks.draft_block_with_metrics(*args, **kwargs) -> not annotated
Nested Function _install_draft_metrics_hooks.draft_block_with_metrics calls draft_block, draft_model._vllm_mlx_draft_counts.append, _count_draft_tokens; returns draft_tokens.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
*args |
not annotated |
no |
none |
Additional variadic positional inputs accepted by this callable. |
**kwargs |
not annotated |
no |
none |
Additional variadic keyword inputs accepted by this callable. |
Returns
- Type:
not annotated - Direct return expressions:
draft_tokens
Exceptions and behavior
Nested Function _install_draft_metrics_hooks.draft_block_with_metrics calls draft_block, draft_model._vllm_mlx_draft_counts.append, _count_draft_tokens; returns draft_tokens.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm._install_draft_metrics_hooks.reset_with_metrics · nested function
vllm_mlx.models.mllm._install_draft_metrics_hooks.reset_with_metrics(*args, **kwargs) -> not annotated
Nested Function _install_draft_metrics_hooks.reset_with_metrics calls reset; returns reset(*args, **kwargs).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
*args |
not annotated |
no |
none |
Additional variadic positional inputs accepted by this callable. |
**kwargs |
not annotated |
no |
none |
Additional variadic keyword inputs accepted by this callable. |
Returns
- Type:
not annotated - Direct return expressions:
reset(*args, **kwargs)
Exceptions and behavior
Nested Function _install_draft_metrics_hooks.reset_with_metrics calls reset; returns reset(*args, **kwargs).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.is_base64_image · function
Check if string is base64-encoded image data.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
s |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
s.startswith('data:image/') or (len(s) > 100 and (not s.startswith(('http://', 'https://', '/'))))
Exceptions and behavior
Function is_base64_image calls s.startswith, len; returns s.startswith('data:image/') or (len(s) > 100 and (not s.startswith(('http://', 'https://', '/')))).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.is_url · function
Check if string is a URL.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
s |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
s.startswith(('http://', 'https://'))
Exceptions and behavior
Function is_url calls s.startswith; returns s.startswith(('http://', 'https://')).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.is_base64_video · function
Check if string is base64-encoded video data.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
s |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
s.startswith('data:video/')
Exceptions and behavior
Function is_base64_video calls s.startswith; returns s.startswith('data:video/').
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.is_base64_audio · function
Check if string is base64-encoded audio data.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
s |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
s.startswith('data:audio/')
Exceptions and behavior
Function is_base64_audio calls s.startswith; returns s.startswith('data:audio/').
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.decode_base64_image · function
vllm_mlx.models.mllm.decode_base64_image(base64_string: str, max_length: int = MAX_BASE64_IMAGE_LENGTH) -> bytes
Decode base64 image to bytes.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
base64_string |
str |
yes |
none |
Base64 encoded image (optionally with data URL prefix) |
max_length |
int |
no |
MAX_BASE64_IMAGE_LENGTH |
Maximum allowed length of base64 string |
Returns
- Type:
bytes - Direct return expressions:
base64.b64decode(data);base64.b64decode(base64_string)
Exceptions and behavior
Function decode_base64_image calls len, FileSizeExceededError, base64_string.startswith, base64_string.split; can raise FileSizeExceededError; has 2 explicit return paths.
Directly raised exceptions: FileSizeExceededError.
vllm_mlx.models.mllm._validate_url_safety · function
Reject remote URLs that target local or private network resources.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
url |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Function _validate_url_safety calls urlparse, UnsafeRemoteURLError, hostname.endswith, ipaddress.ip_address; can raise UnsafeRemoteURLError.
Directly raised exceptions: UnsafeRemoteURLError.
vllm_mlx.models.mllm._request_with_safe_redirects · function
vllm_mlx.models.mllm._request_with_safe_redirects(method: str, url: str, *, timeout: int, headers: dict[str, str], stream: bool = False, max_redirects: int = 5) -> not annotated
Issue a requests call while validating every redirect target.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
method |
str |
yes |
none |
Required positional or keyword input. |
url |
str |
yes |
none |
Required positional or keyword input. |
timeout |
int |
yes |
none |
Required keyword-only input. |
headers |
dict[str, str] |
yes |
none |
Required keyword-only input. |
stream |
bool |
no |
False |
Optional keyword-only input; defaults to False. |
max_redirects |
int |
no |
5 |
Optional keyword-only input; defaults to 5. |
Returns
- Type:
not annotated - Direct return expressions:
response
Exceptions and behavior
Function _request_with_safe_redirects calls range, _validate_url_safety, requests.request, response.headers.get; can raise UnsafeRemoteURLError; returns response.
Directly raised exceptions: UnsafeRemoteURLError.
vllm_mlx.models.mllm.download_image · function
vllm_mlx.models.mllm.download_image(url: str, timeout: int = 30, max_size: int = MAX_IMAGE_SIZE) -> str
Download image from URL and return local path.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
url |
str |
yes |
none |
Image URL |
timeout |
int |
no |
30 |
Download timeout in seconds |
max_size |
int |
no |
MAX_IMAGE_SIZE |
Maximum allowed file size in bytes |
Returns
- Type:
str - Direct return expressions:
_temp_manager.register(temp_file.name)
Exceptions and behavior
Function download_image calls _request_with_safe_redirects, head_response.headers.get, int, FileSizeExceededError; can raise FileSizeExceededError; returns _temp_manager.register(temp_file.name).
Directly raised exceptions: FileSizeExceededError.
vllm_mlx.models.mllm._download_media · function
vllm_mlx.models.mllm._download_media(url: str, media_type: str, ext_map: dict[str, str], default_ext: str, timeout: int, max_size: int) -> str
Download media from URL, enforce size limits, and return a local temp path.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
url |
str |
yes |
none |
Required positional or keyword input. |
media_type |
str |
yes |
none |
Required positional or keyword input. |
ext_map |
dict[str, str] |
yes |
none |
Required positional or keyword input. |
default_ext |
str |
yes |
none |
Required positional or keyword input. |
timeout |
int |
yes |
none |
Required positional or keyword input. |
max_size |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
_temp_manager.register(temp_file.name)
Exceptions and behavior
Function _download_media calls logger.info, _request_with_safe_redirects, head_response.headers.get, int; can raise FileSizeExceededError; returns _temp_manager.register(temp_file.name).
Directly raised exceptions: FileSizeExceededError.
vllm_mlx.models.mllm.download_video · function
vllm_mlx.models.mllm.download_video(url: str, timeout: int = 120, max_size: int = MAX_VIDEO_SIZE) -> str
Download video from URL and return local path.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
url |
str |
yes |
none |
Required positional or keyword input. |
timeout |
int |
no |
120 |
Optional positional or keyword input; defaults to 120. |
max_size |
int |
no |
MAX_VIDEO_SIZE |
Optional positional or keyword input; defaults to MAX_VIDEO_SIZE. |
Returns
- Type:
str - Direct return expressions:
_download_media(url, 'video', _VIDEO_EXT_MAP, '.mp4', timeout, max_size)
Exceptions and behavior
Function download_video calls _download_media; returns _download_media(url, 'video', _VIDEO_EXT_MAP, '.mp4', timeout, max_size).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.download_audio · function
vllm_mlx.models.mllm.download_audio(url: str, timeout: int = 120, max_size: int = MAX_AUDIO_SIZE) -> str
Download audio from URL and return local path.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
url |
str |
yes |
none |
Required positional or keyword input. |
timeout |
int |
no |
120 |
Optional positional or keyword input; defaults to 120. |
max_size |
int |
no |
MAX_AUDIO_SIZE |
Optional positional or keyword input; defaults to MAX_AUDIO_SIZE. |
Returns
- Type:
str - Direct return expressions:
_download_media(url, 'audio', _AUDIO_EXT_MAP, '.wav', timeout, max_size)
Exceptions and behavior
Function download_audio calls _download_media; returns _download_media(url, 'audio', _AUDIO_EXT_MAP, '.wav', timeout, max_size).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.decode_base64_video · function
vllm_mlx.models.mllm.decode_base64_video(base64_string: str, max_length: int = MAX_BASE64_VIDEO_LENGTH) -> str
Decode base64 video to temp file and return path.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
base64_string |
str |
yes |
none |
Base64-encoded video with data URL prefix |
max_length |
int |
no |
MAX_BASE64_VIDEO_LENGTH |
Maximum allowed length of base64 string |
Returns
- Type:
str - Direct return expressions:
_temp_manager.register(temp_file.name)
Exceptions and behavior
Function decode_base64_video calls len, FileSizeExceededError, base64_string.startswith, base64_string.split; can raise FileSizeExceededError; returns _temp_manager.register(temp_file.name).
Directly raised exceptions: FileSizeExceededError.
vllm_mlx.models.mllm.decode_base64_audio · function
vllm_mlx.models.mllm.decode_base64_audio(base64_string: str, max_length: int = MAX_BASE64_AUDIO_LENGTH) -> str
Decode base64 audio to temp file and return path.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
base64_string |
str |
yes |
none |
Required positional or keyword input. |
max_length |
int |
no |
MAX_BASE64_AUDIO_LENGTH |
Optional positional or keyword input; defaults to MAX_BASE64_AUDIO_LENGTH. |
Returns
- Type:
str - Direct return expressions:
_temp_manager.register(temp_file.name)
Exceptions and behavior
Function decode_base64_audio calls len, FileSizeExceededError, base64_string.startswith, base64_string.split; can raise FileSizeExceededError; returns _temp_manager.register(temp_file.name).
Directly raised exceptions: FileSizeExceededError.
vllm_mlx.models.mllm.process_video_input · function
Process video input in various formats and return local path.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
video |
str \| dict |
yes |
none |
Video input in any supported format |
Returns
- Type:
str - Direct return expressions:
download_video(video);decode_base64_video(video)
Exceptions and behavior
Function process_video_input calls isinstance, video.get, url.get, ValueError; can raise ValueError; has 2 explicit return paths.
Directly raised exceptions: ValueError.
vllm_mlx.models.mllm.process_audio_input · function
Process audio input in various formats and return local path.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
audio |
str \| dict |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
decode_base64_audio(audio);download_audio(audio);audio
Exceptions and behavior
Function process_audio_input calls isinstance, audio.get, url.get, ValueError; can raise ValueError; has 3 explicit return paths.
Directly raised exceptions: ValueError.
vllm_mlx.models.mllm._video_has_audio_track · function
Return True if ffprobe finds an audio stream in the video.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
video_path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
True;bool(r.stdout.strip())
Exceptions and behavior
Function _video_has_audio_track calls shutil.which, subprocess.run, bool, r.stdout.strip; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm._model_has_sound_encoder · function
Whether a loaded model exposes a usable sound encoder.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
getattr(model, 'sound_encoder', None) is not None
Exceptions and behavior
Function _model_has_sound_encoder calls getattr; returns getattr(model, 'sound_encoder', None) is not None.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.extract_audio_from_video · function
Extract the audio track from a video file as 16 kHz mono WAV.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
video_path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str | None - Direct return expressions:
None;_temp_manager.register(out_path)
Exceptions and behavior
Function extract_audio_from_video calls shutil.which, logger.warning, _video_has_audio_track, tempfile.mkstemp; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.save_base64_image · function
Save base64 image to temp file and return path.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
base64_string |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
cached_path;path
Exceptions and behavior
Function save_base64_image calls hashlib.sha256(base64_string.encode()).hexdigest, hashlib.sha256, base64_string.encode, Path(cached_path).exists; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.process_image_input · function
Process image input in various formats and return local path.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
image |
str \| dict |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
save_base64_image(image);download_image(image)
Exceptions and behavior
Function process_image_input calls isinstance, image.get, url.get, ValueError; can raise ValueError; has 2 explicit return paths.
Directly raised exceptions: ValueError.
vllm_mlx.models.mllm.round_by_factor · function
Round to nearest multiple of factor.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
x |
int |
yes |
none |
Required positional or keyword input. |
factor |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
int - Direct return expressions:
round(x / factor) * factor
Exceptions and behavior
Function round_by_factor calls round; returns round(x / factor) * factor.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.ceil_by_factor · function
Ceiling to next multiple of factor.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
x |
float |
yes |
none |
Required positional or keyword input. |
factor |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
int - Direct return expressions:
math.ceil(x / factor) * factor
Exceptions and behavior
Function ceil_by_factor calls math.ceil; returns math.ceil(x / factor) * factor.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.floor_by_factor · function
Floor to previous multiple of factor.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
x |
float |
yes |
none |
Required positional or keyword input. |
factor |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
int - Direct return expressions:
math.floor(x / factor) * factor
Exceptions and behavior
Function floor_by_factor calls math.floor; returns math.floor(x / factor) * factor.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.smart_nframes · function
vllm_mlx.models.mllm.smart_nframes(total_frames: int, video_fps: float, target_fps: float = DEFAULT_FPS, min_frames: int = MIN_FRAMES, max_frames: int = MAX_FRAMES) -> int
Calculate optimal number of frames to extract from video.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
total_frames |
int |
yes |
none |
Required positional or keyword input. |
video_fps |
float |
yes |
none |
Required positional or keyword input. |
target_fps |
float |
no |
DEFAULT_FPS |
Optional positional or keyword input; defaults to DEFAULT_FPS. |
min_frames |
int |
no |
MIN_FRAMES |
Optional positional or keyword input; defaults to MIN_FRAMES. |
max_frames |
int |
no |
MAX_FRAMES |
Optional positional or keyword input; defaults to MAX_FRAMES. |
Returns
- Type:
int - Direct return expressions:
int(nframes)
Exceptions and behavior
Function smart_nframes calls max, min, floor_by_factor, int; returns int(nframes).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.extract_video_frames_smart · function
vllm_mlx.models.mllm.extract_video_frames_smart(video_path: str, fps: float = DEFAULT_FPS, max_frames: int = MAX_FRAMES, resize: tuple[int, int] | None = None) -> list[np.ndarray]
Extract frames from video with smart sampling.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
video_path |
str |
yes |
none |
Path to video file |
fps |
float |
no |
DEFAULT_FPS |
Target frames per second (default: 2.0) |
max_frames |
int |
no |
MAX_FRAMES |
Maximum frames to extract |
resize |
tuple[int, int] \| None |
no |
None |
Optional (width, height) to resize frames |
Returns
- Type:
list[np.ndarray] - Direct return expressions:
frames
Exceptions and behavior
Function extract_video_frames_smart calls ImportError, cv2.VideoCapture, cap.isOpened, ValueError; can raise ImportError, ValueError; returns frames.
Directly raised exceptions: ImportError, ValueError.
vllm_mlx.models.mllm.save_frames_to_temp · function
Save frame arrays to temporary files and return paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
frames |
list[np.ndarray] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
list[str] - Direct return expressions:
paths
Exceptions and behavior
Function save_frames_to_temp calls ImportError, enumerate, Image.fromarray, tempfile.NamedTemporaryFile; can raise ImportError; returns paths.
Directly raised exceptions: ImportError.
vllm_mlx.models.mllm.MLXMultimodalLM · class
vllm_mlx.models.mllm.MLXMultimodalLM(model_name: str, trust_remote_code: bool = False, enable_cache: bool = True, cache_size: int = 50, max_kv_size: int = 0, draft_model: str | None = None, draft_kind: str | None = None, draft_block_size: int | None = None)
Wrapper around mlx-vlm for multimodal inference.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_name |
str |
yes |
none |
HuggingFace model name or local path |
trust_remote_code |
bool |
no |
False |
Whether to trust remote code |
enable_cache |
bool |
no |
True |
Enable KV cache for repeated image/video+prompt (default: True) |
cache_size |
int |
no |
50 |
Maximum cache entries (default: 50) |
max_kv_size |
int |
no |
0 |
Maximum KV cache size per sequence (0 = unbounded) |
draft_model |
str \| None |
no |
None |
Optional MLLM speculative draft/assistant model path. |
draft_kind |
str \| None |
no |
None |
Optional mlx-vlm draft kind, for example "mtp". |
draft_block_size |
int \| None |
no |
None |
Optional speculative block size passed to mlx-vlm. |
Returns
- Constructs:
vllm_mlx.models.mllm.MLXMultimodalLM
Exceptions and behavior
Class MLXMultimodalLM declares 29 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.__init__ · method
vllm_mlx.models.mllm.MLXMultimodalLM.__init__(model_name: str, trust_remote_code: bool = False, enable_cache: bool = True, cache_size: int = 50, max_kv_size: int = 0, draft_model: str | None = None, draft_kind: str | None = None, draft_block_size: int | None = None) -> not annotated
Initialize the MLX multimodal language model.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_name |
str |
yes |
none |
HuggingFace model name or local path |
trust_remote_code |
bool |
no |
False |
Whether to trust remote code |
enable_cache |
bool |
no |
True |
Enable KV cache for repeated image/video+prompt (default: True) |
cache_size |
int |
no |
50 |
Maximum cache entries (default: 50) |
max_kv_size |
int |
no |
0 |
Maximum KV cache size per sequence (0 = unbounded) |
draft_model |
str \| None |
no |
None |
Optional MLLM speculative draft/assistant model path. |
draft_kind |
str \| None |
no |
None |
Optional mlx-vlm draft kind, for example "mtp". |
draft_block_size |
int \| None |
no |
None |
Optional speculative block size passed to mlx-vlm. |
Returns
- Type:
not annotated
Exceptions and behavior
Method MLXMultimodalLM.__init__ updates self.model_name, self.trust_remote_code, self.enable_cache, self.max_kv_size; calls MLLMPrefixCacheManager.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.load · method
Load the model and processor.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method MLXMultimodalLM.load updates self.model, self.processor, self.config, self._draft_model; calls logger.info, load, load_config, self._load_draft_model; can raise ImportError; returns None.
Directly raised exceptions: ImportError.
vllm_mlx.models.mllm.MLXMultimodalLM._load_draft_model · method
Method MLXMultimodalLM._load_draft_model calls load_gemma4_assistant_drafter, load; has 2 explicit return paths.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
load_gemma4_assistant_drafter(self.draft_model_path);draft_model
Exceptions and behavior
Method MLXMultimodalLM._load_draft_model calls load_gemma4_assistant_drafter, load; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM._draft_generation_kwargs · method
vllm_mlx.models.mllm.MLXMultimodalLM._draft_generation_kwargs(call_kwargs: dict | None = None) -> dict
Return mlx-vlm drafter kwargs when the request explicitly opts in.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
call_kwargs |
dict \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
dict - Direct return expressions:
{};kwargs
Exceptions and behavior
Method MLXMultimodalLM._draft_generation_kwargs calls bool, call_kwargs.pop, _install_draft_metrics_hooks; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM._reset_draft_metrics · method
Method MLXMultimodalLM._reset_draft_metrics updates self._draft_model.accept_lens, self._draft_model._vllm_mlx_draft_counts; calls hasattr; returns 0.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
0
Exceptions and behavior
Method MLXMultimodalLM._reset_draft_metrics updates self._draft_model.accept_lens, self._draft_model._vllm_mlx_draft_counts; calls hasattr; returns 0.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM._draft_metrics_since · method
Method MLXMultimodalLM._draft_metrics_since calls list, getattr, len, int; has 2 explicit return paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
start_accept_lens |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict[str, int] - Direct return expressions:
{'mtp_drafts': 0, 'mtp_accepted': 0};{'mtp_drafts': mtp_drafts, 'mtp_accepted': sum((int(value) for value in new_accept_lens))}
Exceptions and behavior
Method MLXMultimodalLM._draft_metrics_since calls list, getattr, len, int; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.get_language_model · method
Extract the underlying language model for mlx_lm TextModel construction.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
self.model.language_model
Exceptions and behavior
Method MLXMultimodalLM.get_language_model returns self.model.language_model.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.get_tokenizer · method
Get the text tokenizer (not the multimodal processor).
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
self.processor.tokenizer
Exceptions and behavior
Method MLXMultimodalLM.get_tokenizer returns self.processor.tokenizer.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM._prepare_images · method
Process remote/base64 image inputs into local temp file paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
images |
list |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
list[str] - Direct return expressions:
processed
Exceptions and behavior
Method MLXMultimodalLM._prepare_images calls process_image_input, processed.append, logger.warning; returns processed.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM._prepare_audio · method
Process audio inputs and return local file paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
audio_inputs |
list |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
list[str] - Direct return expressions:
processed
Exceptions and behavior
Method MLXMultimodalLM._prepare_audio calls process_audio_input, processed.append, logger.warning; returns processed.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM._prepare_video · method
vllm_mlx.models.mllm.MLXMultimodalLM._prepare_video(video_input: str | dict, fps: float = DEFAULT_FPS, max_frames: int = MAX_FRAMES, resolved_path: str | None = None) -> list[str]
Process video input and extract frames.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
video_input |
str \| dict |
yes |
none |
Video in any supported format |
fps |
float |
no |
DEFAULT_FPS |
Frames per second to extract |
max_frames |
int |
no |
MAX_FRAMES |
Maximum frames to extract |
resolved_path |
str \| None |
no |
None |
Optional pre-resolved local path. Callers that already ran process_video_input (e.g. for parallel audio extraction) pass it here to avoid re-downloading / re-decoding. |
Returns
- Type:
list[str] - Direct return expressions:
save_frames_to_temp(frames)
Exceptions and behavior
Method MLXMultimodalLM._prepare_video calls process_video_input, extract_video_frames_smart, save_frames_to_temp; returns save_frames_to_temp(frames).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM._collect_video_inputs · method
Collect video inputs from messages, keyed by message index.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
messages |
list[dict] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict[int, list] - Direct return expressions:
video_inputs
Exceptions and behavior
Method MLXMultimodalLM._collect_video_inputs calls enumerate, msg.get, isinstance, hasattr; returns video_inputs.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM._collect_audio_inputs · method
Collect audio inputs from messages, keyed by message index.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
messages |
list[dict] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict[int, list] - Direct return expressions:
audio_inputs
Exceptions and behavior
Method MLXMultimodalLM._collect_audio_inputs calls enumerate, msg.get, isinstance, hasattr; returns audio_inputs.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM._prepare_native_video_inputs · method
vllm_mlx.models.mllm.MLXMultimodalLM._prepare_native_video_inputs(messages: list[dict], video_fps: float = DEFAULT_FPS, video_max_frames: int = MAX_FRAMES, tools: list | None = None) -> tuple[str, dict]
Preprocess messages into prompt + generation kwargs for native video.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
messages |
list[dict] |
yes |
none |
Required positional or keyword input. |
video_fps |
float |
no |
DEFAULT_FPS |
Optional positional or keyword input; defaults to DEFAULT_FPS. |
video_max_frames |
int |
no |
MAX_FRAMES |
Optional positional or keyword input; defaults to MAX_FRAMES. |
tools |
list \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
tuple[str, dict] - Direct return expressions:
(text, gen_kwargs)
Exceptions and behavior
Method MLXMultimodalLM._prepare_native_video_inputs calls ImportError, self._translate_messages_for_native_video, self.processor.apply_chat_template, process_vision_info; can raise ImportError; returns (text, gen_kwargs).
Directly raised exceptions: ImportError.
vllm_mlx.models.mllm.MLXMultimodalLM._generate_native_video · method
vllm_mlx.models.mllm.MLXMultimodalLM._generate_native_video(messages: list[dict], max_tokens: int = 256, temperature: float = 0.7, video_fps: float = DEFAULT_FPS, video_max_frames: int = MAX_FRAMES, tools: list | None = None, **kwargs) -> MLLMOutput
Generate using native video pipeline (Qwen-family models).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
messages |
list[dict] |
yes |
none |
Required positional or keyword input. |
max_tokens |
int |
no |
256 |
Optional positional or keyword input; defaults to 256. |
temperature |
float |
no |
0.7 |
Optional positional or keyword input; defaults to 0.7. |
video_fps |
float |
no |
DEFAULT_FPS |
Optional positional or keyword input; defaults to DEFAULT_FPS. |
video_max_frames |
int |
no |
MAX_FRAMES |
Optional positional or keyword input; defaults to MAX_FRAMES. |
tools |
list \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
**kwargs |
not annotated |
no |
none |
Additional variadic keyword inputs accepted by this callable. |
Returns
- Type:
MLLMOutput - Direct return expressions:
MLLMOutput(text=result.text, finish_reason='stop', prompt_tokens=getattr(result, 'prompt_tokens', 0), completion_tokens…;MLLMOutput(text=str(result), finish_reason='stop')
Exceptions and behavior
Method MLXMultimodalLM._generate_native_video calls ImportError, self._prepare_native_video_inputs, generate, hasattr; can raise ImportError; has 2 explicit return paths.
Directly raised exceptions: ImportError.
vllm_mlx.models.mllm.MLXMultimodalLM._translate_messages_for_native_video · method
vllm_mlx.models.mllm.MLXMultimodalLM._translate_messages_for_native_video(messages: list[dict], video_fps: float, video_max_frames: int) -> list[dict]
Translate OpenAI API format messages to process_vision_info format.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
messages |
list[dict] |
yes |
none |
Required positional or keyword input. |
video_fps |
float |
yes |
none |
Required positional or keyword input. |
video_max_frames |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
list[dict] - Direct return expressions:
translated
Exceptions and behavior
Method MLXMultimodalLM._translate_messages_for_native_video calls msg.get, isinstance, translated.append, str; returns translated.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.generate · method
vllm_mlx.models.mllm.MLXMultimodalLM.generate(prompt: str, images: list | None = None, videos: list | None = None, audio: list[str] | None = None, max_tokens: int = 256, temperature: float = 0.7, top_p: float = 0.9, video_fps: float = DEFAULT_FPS, video_max_frames: int = MAX_FRAMES, use_cache: bool = True, **kwargs) -> MLLMOutput
Generate text from multimodal input.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
prompt |
str |
yes |
none |
Text prompt/question |
images |
list \| None |
no |
None |
List of image URLs or base64 strings |
videos |
list \| None |
no |
None |
List of video inputs (URLs, base64, or OpenAI format dicts) |
audio |
list[str] \| None |
no |
None |
List of audio file paths |
max_tokens |
int |
no |
256 |
Maximum tokens to generate |
temperature |
float |
no |
0.7 |
Sampling temperature |
top_p |
float |
no |
0.9 |
Top-p sampling parameter |
video_fps |
float |
no |
DEFAULT_FPS |
FPS for video frame extraction (default: 2.0) |
video_max_frames |
int |
no |
MAX_FRAMES |
Max frames to extract from video |
use_cache |
bool |
no |
True |
Whether to use KV cache (default: True) |
**kwargs |
not annotated |
no |
none |
Additional generation parameters |
Returns
- Type:
MLLMOutput - Direct return expressions:
MLLMOutput(text=output_text, finish_reason='stop', prompt_tokens=prompt_tokens, completion_tokens=generation_tokens, **…
Exceptions and behavior
Method MLXMultimodalLM.generate calls self.load, all_images.extend, self._prepare_images, all_sources.extend; returns MLLMOutput(text=output_text, finish_reason='stop', prompt_tokens=prompt_tokens, completion_tokens=generation_tokens, **….
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.stream_generate · method
vllm_mlx.models.mllm.MLXMultimodalLM.stream_generate(prompt: str, images: list | None = None, videos: list[str] | None = None, audio: list[str] | None = None, max_tokens: int = 256, temperature: float = 0.7, video_fps: float = DEFAULT_FPS, **kwargs) -> Iterator[str]
Stream text generation for multimodal input.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
prompt |
str |
yes |
none |
Text prompt |
images |
list \| None |
no |
None |
List of image inputs |
videos |
list[str] \| None |
no |
None |
List of video paths |
audio |
list[str] \| None |
no |
None |
List of audio inputs |
max_tokens |
int |
no |
256 |
Maximum tokens to generate |
temperature |
float |
no |
0.7 |
Sampling temperature |
video_fps |
float |
no |
DEFAULT_FPS |
FPS for video frame extraction |
**kwargs |
not annotated |
no |
none |
Additional parameters |
Returns
- Type:
Iterator[str] - Direct return expressions:
None - Yields values incrementally.
Exceptions and behavior
Method MLXMultimodalLM.stream_generate calls self.load, self.generate, all_images.extend, self._prepare_images; yields values incrementally; returns None.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.chat · method
vllm_mlx.models.mllm.MLXMultimodalLM.chat(messages: list[dict], max_tokens: int = 256, temperature: float = 0.7, **kwargs) -> MLLMOutput
Chat with OpenAI-compatible message format.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
messages |
list[dict] |
yes |
none |
List of chat messages (OpenAI format) |
max_tokens |
int |
no |
256 |
Maximum tokens to generate |
temperature |
float |
no |
0.7 |
Sampling temperature |
**kwargs |
not annotated |
no |
none |
Additional parameters |
Returns
- Type:
MLLMOutput - Direct return expressions:
self._generate_native_video(messages=messages, max_tokens=max_tokens, temperature=temperature, video_fps=video_fps, vid…;MLLMOutput(text=output_text, finish_reason='stop', prompt_tokens=prompt_tokens, completion_tokens=generation_tokens, **…
Exceptions and behavior
Method MLXMultimodalLM.chat calls self.load, logger.info, len, kwargs.pop; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.stream_chat · method
vllm_mlx.models.mllm.MLXMultimodalLM.stream_chat(messages: list[dict], max_tokens: int = 256, temperature: float = 0.7, **kwargs) -> Iterator[MLLMOutput]
Stream chat with OpenAI-compatible message format.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
messages |
list[dict] |
yes |
none |
List of chat messages (OpenAI format) |
max_tokens |
int |
no |
256 |
Maximum tokens to generate |
temperature |
float |
no |
0.7 |
Sampling temperature |
**kwargs |
not annotated |
no |
none |
Additional parameters |
Returns
- Type:
Iterator[MLLMOutput] - Direct return expressions:
None - Yields values incrementally.
Exceptions and behavior
Method MLXMultimodalLM.stream_chat calls self.load, self.chat, kwargs.pop, chat_template_kwargs.pop; yields values incrementally; returns None.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.describe_image · method
vllm_mlx.models.mllm.MLXMultimodalLM.describe_image(image: str, prompt: str = 'Describe this image in detail.', max_tokens: int = 512, **kwargs) -> str
Convenience method to describe an image.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
image |
str |
yes |
none |
Image path, URL, or base64 string |
prompt |
str |
no |
'Describe this image in detail.' |
Description prompt |
max_tokens |
int |
no |
512 |
Maximum tokens |
**kwargs |
not annotated |
no |
none |
Additional parameters |
Returns
- Type:
str - Direct return expressions:
output.text
Exceptions and behavior
Method MLXMultimodalLM.describe_image calls self.generate; returns output.text.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.answer_about_image · method
vllm_mlx.models.mllm.MLXMultimodalLM.answer_about_image(image: str, question: str, max_tokens: int = 256, **kwargs) -> str
Answer a question about an image.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
image |
str |
yes |
none |
Image path, URL, or base64 string |
question |
str |
yes |
none |
Question about the image |
max_tokens |
int |
no |
256 |
Maximum tokens |
**kwargs |
not annotated |
no |
none |
Additional parameters |
Returns
- Type:
str - Direct return expressions:
output.text
Exceptions and behavior
Method MLXMultimodalLM.answer_about_image calls self.generate; returns output.text.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.describe_video · method
vllm_mlx.models.mllm.MLXMultimodalLM.describe_video(video: str | dict, prompt: str = 'Describe what happens in this video.', fps: float = 2.0, max_frames: int = 32, max_tokens: int = 512, **kwargs) -> str
Describe a video using frame extraction.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
video |
str \| dict |
yes |
none |
Video file path, URL, base64, or OpenAI format dict |
prompt |
str |
no |
'Describe what happens in this video.' |
Description prompt |
fps |
float |
no |
2.0 |
Frames per second to extract |
max_frames |
int |
no |
32 |
Maximum frames to extract |
max_tokens |
int |
no |
512 |
Maximum tokens to generate |
**kwargs |
not annotated |
no |
none |
Additional variadic keyword inputs accepted by this callable. |
Returns
- Type:
str - Direct return expressions:
output.text
Exceptions and behavior
Method MLXMultimodalLM.describe_video calls self.generate; returns output.text.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.get_cache_stats · method
Get MLLM cache statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
dict - Direct return expressions:
{'enabled': False};stats
Exceptions and behavior
Method MLXMultimodalLM.get_cache_stats calls self._cache_manager.get_stats, len; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.clear_cache · method
Clear the MLLM KV cache.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method MLXMultimodalLM.clear_cache calls self._cache_manager.clear, logger.info.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.get_model_info · method
Get information about the loaded model.
Parameters
This callable has no explicit inputs.
Returns
- Type:
dict - Direct return expressions:
{'loaded': False, 'model_name': self.model_name};info
Exceptions and behavior
Method MLXMultimodalLM.get_model_info calls getattr, self._cache_manager.get_stats; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.list_supported_model_families · method
List supported model families and their patterns.
Parameters
This callable has no explicit inputs.
Returns
- Type:
dict[str, str] - Direct return expressions:
{'Qwen-VL': 'Qwen VL models (Qwen2-VL, Qwen2.5-VL, Qwen3-VL, etc.)', 'LLaVA': 'LLaVA vision-language models', 'Idefics'…
Exceptions and behavior
Method MLXMultimodalLM.list_supported_model_families returns {'Qwen-VL': 'Qwen VL models (Qwen2-VL, Qwen2.5-VL, Qwen3-VL, etc.)', 'LLaVA': 'LLaVA vision-language models', 'Idefics'….
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.is_mllm_model · method
Check if a model name indicates an MLLM model.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_name |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
any((pattern.lower() in model_lower for pattern in mllm_patterns))
Exceptions and behavior
Method MLXMultimodalLM.is_mllm_model calls model_name.lower, any, pattern.lower; returns any((pattern.lower() in model_lower for pattern in mllm_patterns)).
No direct raise statement appears in this definition.
vllm_mlx.models.mllm.MLXMultimodalLM.__repr__ · method
Method MLXMultimodalLM.__repr__ returns f'<MLXMultimodalLM model={self.model_name} status={status}>'.
Parameters
This callable has no explicit inputs.
Returns
- Type:
str - Direct return expressions:
f'<MLXMultimodalLM model={self.model_name} status={status}>'
Exceptions and behavior
Method MLXMultimodalLM.__repr__ returns f'<MLXMultimodalLM model={self.model_name} status={status}>'.
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 |
|---|---|---|---|---|
TempFileManager |
class | TempFileManager() |
Thread-safe manager for tracking and cleaning up temporary files. | #L41-L86 |
TempFileManager.__init__ |
method | TempFileManager.__init__() -> not annotated |
Method TempFileManager.__init__ updates self._files, self._lock; calls set, threading.Lock, atexit.register. |
#L44-L47 |
TempFileManager.register |
method | TempFileManager.register(path: str) -> str |
Register a temp file for tracking. | #L49-L53 |
TempFileManager.cleanup |
method | TempFileManager.cleanup(path: str) -> bool |
Clean up a specific temp file. | #L55-L67 |
TempFileManager.cleanup_all |
method | TempFileManager.cleanup_all() -> int |
Clean up all tracked temp files. | #L69-L86 |
cleanup_temp_file |
function | cleanup_temp_file(path: str) -> bool |
Clean up a specific temporary file. | #L93-L95 |
cleanup_all_temp_files |
function | cleanup_all_temp_files() -> int |
Clean up all tracked temporary files. | #L98-L100 |
FileSizeExceededError |
class | FileSizeExceededError() |
Raised when a downloaded file exceeds the size limit. | #L119-L122 |
UnsafeRemoteURLError |
class | UnsafeRemoteURLError(message: str, *, public_message: str = 'Remote media URL is not allowed') |
Raised when a remote media URL targets an unsafe destination. | #L125-L135 |
UnsafeRemoteURLError.__init__ |
method | UnsafeRemoteURLError.__init__(message: str, *, public_message: str = 'Remote media URL is not allowed') -> None |
Method UnsafeRemoteURLError.__init__ updates self.public_message; calls super().__init__, super. |
#L128-L135 |
_normalize_content_part |
function | _normalize_content_part(item: object) -> object |
Convert Pydantic content parts into plain Python objects. | #L138-L144 |
_extract_media_url |
function | _extract_media_url(item: dict, item_type: str) -> str |
Function _extract_media_url calls item.get, isinstance, media_value.get; has 2 explicit return paths. |
#L147-L161 |
_text_content_part |
function | _text_content_part(text: str) -> dict[str, str] |
Function _text_content_part returns {'type': 'text', 'text': text, 'content': text}. |
#L164-L165 |
_append_text_content_part |
function | _append_text_content_part(built_parts: list[dict[str, str]], text_parts: list[str], text: str) -> None |
Function _append_text_content_part calls built_parts.append, _text_content_part, text_parts.append; returns None. |
#L168-L174 |
_build_string_mllm_message_content |
function | _build_string_mllm_message_content(content: str, role: str) -> tuple[object, bool] |
Function _build_string_mllm_message_content calls _text_content_part; has 3 explicit return paths. |
#L177-L182 |
_append_ordered_mllm_content_part |
function | _append_ordered_mllm_content_part(raw_item: object, *, built_parts: list[dict[str, str]], text_parts: list[str], all_image_urls: list[str], video_frame_count: int) -> int |
Function _append_ordered_mllm_content_part calls _normalize_content_part, isinstance, _append_text_content_part, item.get; has 2 explicit return paths. |
#L185-L220 |
_build_ordered_mllm_message_content |
function | _build_ordered_mllm_message_content(content: object, *, role: str, all_image_urls: list[str], video_frame_count: int = 0) -> tuple[object, bool] |
Build template content while preserving OpenAI media/text part order. | #L223-L254 |
_normalize_mllm_tool_calls |
function | _normalize_mllm_tool_calls(tool_calls: list) -> list |
Normalize replayed assistant tool calls for chat templates. | #L257-L268 |
_build_mllm_chat_messages |
function | _build_mllm_chat_messages(messages: list[dict], *, all_image_urls: list[str], video_frame_counts: dict[int, int]) -> list[dict] |
Build chat-template messages without reordering multimodal content parts. | #L271-L315 |
MultimodalInput |
class | MultimodalInput(prompt: str, images: list[str] = field(default_factory=list), videos: list[str] = field(default_factory=list), audio: list[str] = field(default_factory=list)) |
Input for multimodal generation. | #L319-L325 |
MLLMOutput |
class | MLLMOutput(text: str, finish_reason: str \| None = None, prompt_tokens: int = 0, completion_tokens: int = 0, mtp_drafts: int = 0, mtp_accepted: int = 0) |
Output from multimodal language model. | #L329-L337 |
load_gemma4_assistant_drafter |
function | load_gemma4_assistant_drafter(model_path: str) -> not annotated |
Load a Gemma 4 assistant drafter for mlx-vlm speculative decoding. | #L340-L381 |
_count_draft_tokens |
function | _count_draft_tokens(draft_tokens) -> int |
Best-effort drafted-token count for an mlx-vlm drafter output. | #L387-L398 |
_install_draft_metrics_hooks |
function | _install_draft_metrics_hooks(draft_model) -> None |
Record actual drafted token counts from mlx-vlm assistant drafters. | #L401-L428 |
_install_draft_metrics_hooks.draft_block_with_metrics |
nested function | _install_draft_metrics_hooks.draft_block_with_metrics(*args, **kwargs) -> not annotated |
Nested Function _install_draft_metrics_hooks.draft_block_with_metrics calls draft_block, draft_model._vllm_mlx_draft_counts.append, _count_draft_tokens; returns draft_tokens. |
#L412-L415 |
_install_draft_metrics_hooks.reset_with_metrics |
nested function | _install_draft_metrics_hooks.reset_with_metrics(*args, **kwargs) -> not annotated |
Nested Function _install_draft_metrics_hooks.reset_with_metrics calls reset; returns reset(*args, **kwargs). |
#L422-L424 |
is_base64_image |
function | is_base64_image(s: str) -> bool |
Check if string is base64-encoded image data. | #L431-L435 |
is_url |
function | is_url(s: str) -> bool |
Check if string is a URL. | #L438-L440 |
is_base64_video |
function | is_base64_video(s: str) -> bool |
Check if string is base64-encoded video data. | #L443-L445 |
is_base64_audio |
function | is_base64_audio(s: str) -> bool |
Check if string is base64-encoded audio data. | #L448-L450 |
decode_base64_image |
function | decode_base64_image(base64_string: str, max_length: int = MAX_BASE64_IMAGE_LENGTH) -> bytes |
Decode base64 image to bytes. | #L453-L480 |
_validate_url_safety |
function | _validate_url_safety(url: str) -> None |
Reject remote URLs that target local or private network resources. | #L483-L519 |
_request_with_safe_redirects |
function | _request_with_safe_redirects(method: str, url: str, *, timeout: int, headers: dict[str, str], stream: bool = False, max_redirects: int = 5) -> not annotated |
Issue a requests call while validating every redirect target. | #L522-L557 |
download_image |
function | download_image(url: str, timeout: int = 30, max_size: int = MAX_IMAGE_SIZE) -> str |
Download image from URL and return local path. | #L560-L645 |
_download_media |
function | _download_media(url: str, media_type: str, ext_map: dict[str, str], default_ext: str, timeout: int, max_size: int) -> str |
Download media from URL, enforce size limits, and return a local temp path. | #L670-L748 |
download_video |
function | download_video(url: str, timeout: int = 120, max_size: int = MAX_VIDEO_SIZE) -> str |
Download video from URL and return local path. | #L751-L753 |
download_audio |
function | download_audio(url: str, timeout: int = 120, max_size: int = MAX_AUDIO_SIZE) -> str |
Download audio from URL and return local path. | #L756-L758 |
decode_base64_video |
function | decode_base64_video(base64_string: str, max_length: int = MAX_BASE64_VIDEO_LENGTH) -> str |
Decode base64 video to temp file and return path. | #L761-L807 |
decode_base64_audio |
function | decode_base64_audio(base64_string: str, max_length: int = MAX_BASE64_AUDIO_LENGTH) -> str |
Decode base64 audio to temp file and return path. | #L810-L836 |
process_video_input |
function | process_video_input(video: str \| dict) -> str |
Process video input in various formats and return local path. | #L839-L874 |
process_audio_input |
function | process_audio_input(audio: str \| dict) -> str |
Process audio input in various formats and return local path. | #L877-L905 |
_video_has_audio_track |
function | _video_has_audio_track(video_path: str) -> bool |
Return True if ffprobe finds an audio stream in the video. | #L908-L935 |
_model_has_sound_encoder |
function | _model_has_sound_encoder(model) -> bool |
Whether a loaded model exposes a usable sound encoder. | #L938-L947 |
extract_audio_from_video |
function | extract_audio_from_video(video_path: str) -> str \| None |
Extract the audio track from a video file as 16 kHz mono WAV. | #L950-L1005 |
save_base64_image |
function | save_base64_image(base64_string: str) -> str |
Save base64 image to temp file and return path. | #L1012-L1048 |
process_image_input |
function | process_image_input(image: str \| dict) -> str |
Process image input in various formats and return local path. | #L1051-L1080 |
round_by_factor |
function | round_by_factor(x: int, factor: int) -> int |
Round to nearest multiple of factor. | #L1083-L1085 |
ceil_by_factor |
function | ceil_by_factor(x: float, factor: int) -> int |
Ceiling to next multiple of factor. | #L1088-L1090 |
floor_by_factor |
function | floor_by_factor(x: float, factor: int) -> int |
Floor to previous multiple of factor. | #L1093-L1095 |
smart_nframes |
function | smart_nframes(total_frames: int, video_fps: float, target_fps: float = DEFAULT_FPS, min_frames: int = MIN_FRAMES, max_frames: int = MAX_FRAMES) -> int |
Calculate optimal number of frames to extract from video. | #L1098-L1120 |
extract_video_frames_smart |
function | extract_video_frames_smart(video_path: str, fps: float = DEFAULT_FPS, max_frames: int = MAX_FRAMES, resize: tuple[int, int] \| None = None) -> list[np.ndarray] |
Extract frames from video with smart sampling. | #L1123-L1187 |
save_frames_to_temp |
function | save_frames_to_temp(frames: list[np.ndarray]) -> list[str] |
Save frame arrays to temporary files and return paths. | #L1190-L1204 |
MLXMultimodalLM |
class | MLXMultimodalLM(model_name: str, trust_remote_code: bool = False, enable_cache: bool = True, cache_size: int = 50, max_kv_size: int = 0, draft_model: str \| None = None, draft_kind: str \| None = None, draft_block_size: int \| None = None) |
Wrapper around mlx-vlm for multimodal inference. | #L1207-L2938 |
MLXMultimodalLM.__init__ |
method | MLXMultimodalLM.__init__(model_name: str, trust_remote_code: bool = False, enable_cache: bool = True, cache_size: int = 50, max_kv_size: int = 0, draft_model: str \| None = None, draft_kind: str \| None = None, draft_block_size: int \| None = None) -> not annotated |
Initialize the MLX multimodal language model. | #L1235-L1278 |
MLXMultimodalLM.load |
method | MLXMultimodalLM.load() -> None |
Load the model and processor. | #L1280-L1323 |
MLXMultimodalLM._load_draft_model |
method | MLXMultimodalLM._load_draft_model() -> not annotated |
Method MLXMultimodalLM._load_draft_model calls load_gemma4_assistant_drafter, load; has 2 explicit return paths. |
#L1325-L1332 |
MLXMultimodalLM._draft_generation_kwargs |
method | MLXMultimodalLM._draft_generation_kwargs(call_kwargs: dict \| None = None) -> dict |
Return mlx-vlm drafter kwargs when the request explicitly opts in. | #L1334-L1355 |
MLXMultimodalLM._reset_draft_metrics |
method | MLXMultimodalLM._reset_draft_metrics() -> int |
Method MLXMultimodalLM._reset_draft_metrics updates self._draft_model.accept_lens, self._draft_model._vllm_mlx_draft_counts; calls hasattr; returns 0. |
#L1357-L1364 |
MLXMultimodalLM._draft_metrics_since |
method | MLXMultimodalLM._draft_metrics_since(start_accept_lens: int) -> dict[str, int] |
Method MLXMultimodalLM._draft_metrics_since calls list, getattr, len, int; has 2 explicit return paths. |
#L1366-L1395 |
MLXMultimodalLM.get_language_model |
method | MLXMultimodalLM.get_language_model() -> not annotated |
Extract the underlying language model for mlx_lm TextModel construction. | #L1397-L1399 |
MLXMultimodalLM.get_tokenizer |
method | MLXMultimodalLM.get_tokenizer() -> not annotated |
Get the text tokenizer (not the multimodal processor). | #L1401-L1403 |
MLXMultimodalLM._prepare_images |
method | MLXMultimodalLM._prepare_images(images: list) -> list[str] |
Process remote/base64 image inputs into local temp file paths. | #L1405-L1414 |
MLXMultimodalLM._prepare_audio |
method | MLXMultimodalLM._prepare_audio(audio_inputs: list) -> list[str] |
Process audio inputs and return local file paths. | #L1416-L1425 |
MLXMultimodalLM._prepare_video |
method | MLXMultimodalLM._prepare_video(video_input: str \| dict, fps: float = DEFAULT_FPS, max_frames: int = MAX_FRAMES, resolved_path: str \| None = None) -> list[str] |
Process video input and extract frames. | #L1427-L1463 |
MLXMultimodalLM._collect_video_inputs |
method | MLXMultimodalLM._collect_video_inputs(messages: list[dict]) -> dict[int, list] |
Collect video inputs from messages, keyed by message index. | #L1465-L1497 |
MLXMultimodalLM._collect_audio_inputs |
method | MLXMultimodalLM._collect_audio_inputs(messages: list[dict]) -> dict[int, list] |
Collect audio inputs from messages, keyed by message index. | #L1499-L1528 |
MLXMultimodalLM._prepare_native_video_inputs |
method | MLXMultimodalLM._prepare_native_video_inputs(messages: list[dict], video_fps: float = DEFAULT_FPS, video_max_frames: int = MAX_FRAMES, tools: list \| None = None) -> tuple[str, dict] |
Preprocess messages into prompt + generation kwargs for native video. | #L1530-L1648 |
MLXMultimodalLM._generate_native_video |
method | MLXMultimodalLM._generate_native_video(messages: list[dict], max_tokens: int = 256, temperature: float = 0.7, video_fps: float = DEFAULT_FPS, video_max_frames: int = MAX_FRAMES, tools: list \| None = None, **kwargs) -> MLLMOutput |
Generate using native video pipeline (Qwen-family models). | #L1650-L1695 |
MLXMultimodalLM._translate_messages_for_native_video |
method | MLXMultimodalLM._translate_messages_for_native_video(messages: list[dict], video_fps: float, video_max_frames: int) -> list[dict] |
Translate OpenAI API format messages to process_vision_info format. | #L1697-L1832 |
MLXMultimodalLM.generate |
method | MLXMultimodalLM.generate(prompt: str, images: list \| None = None, videos: list \| None = None, audio: list[str] \| None = None, max_tokens: int = 256, temperature: float = 0.7, top_p: float = 0.9, video_fps: float = DEFAULT_FPS, video_max_frames: int = MAX_FRAMES, use_cache: bool = True, **kwargs) -> MLLMOutput |
Generate text from multimodal input. | #L1834-L2002 |
MLXMultimodalLM.stream_generate |
method | MLXMultimodalLM.stream_generate(prompt: str, images: list \| None = None, videos: list[str] \| None = None, audio: list[str] \| None = None, max_tokens: int = 256, temperature: float = 0.7, video_fps: float = DEFAULT_FPS, **kwargs) -> Iterator[str] |
Stream text generation for multimodal input. | #L2004-L2093 |
MLXMultimodalLM.chat |
method | MLXMultimodalLM.chat(messages: list[dict], max_tokens: int = 256, temperature: float = 0.7, **kwargs) -> MLLMOutput |
Chat with OpenAI-compatible message format. | #L2095-L2487 |
MLXMultimodalLM.stream_chat |
method | MLXMultimodalLM.stream_chat(messages: list[dict], max_tokens: int = 256, temperature: float = 0.7, **kwargs) -> Iterator[MLLMOutput] |
Stream chat with OpenAI-compatible message format. | #L2489-L2737 |
MLXMultimodalLM.describe_image |
method | MLXMultimodalLM.describe_image(image: str, prompt: str = 'Describe this image in detail.', max_tokens: int = 512, **kwargs) -> str |
Convenience method to describe an image. | #L2739-L2764 |
MLXMultimodalLM.answer_about_image |
method | MLXMultimodalLM.answer_about_image(image: str, question: str, max_tokens: int = 256, **kwargs) -> str |
Answer a question about an image. | #L2766-L2791 |
MLXMultimodalLM.describe_video |
method | MLXMultimodalLM.describe_video(video: str \| dict, prompt: str = 'Describe what happens in this video.', fps: float = 2.0, max_frames: int = 32, max_tokens: int = 512, **kwargs) -> str |
Describe a video using frame extraction. | #L2793-L2830 |
MLXMultimodalLM.get_cache_stats |
method | MLXMultimodalLM.get_cache_stats() -> dict |
Get MLLM cache statistics. | #L2832-L2846 |
MLXMultimodalLM.clear_cache |
method | MLXMultimodalLM.clear_cache() -> None |
Clear the MLLM KV cache. | #L2848-L2852 |
MLXMultimodalLM.get_model_info |
method | MLXMultimodalLM.get_model_info() -> dict |
Get information about the loaded model. | #L2854-L2874 |
MLXMultimodalLM.list_supported_model_families |
method | MLXMultimodalLM.list_supported_model_families() -> dict[str, str] |
List supported model families and their patterns. | #L2877-L2897 |
MLXMultimodalLM.is_mllm_model |
method | MLXMultimodalLM.is_mllm_model(model_name: str) -> bool |
Check if a model name indicates an MLLM model. | #L2900-L2934 |
MLXMultimodalLM.__repr__ |
method | MLXMultimodalLM.__repr__() -> str |
Method MLXMultimodalLM.__repr__ returns f'<MLXMultimodalLM model={self.model_name} status={status}>'. |
#L2936-L2938 |