vllm_mlx.text_model_from_vlm¶
Construct an mlx_lm TextModel from mlx_vlm-loaded model weights.
View the complete module source at #L1-L272.
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.text_model_from_vlm
¶
Construct an mlx_lm TextModel from mlx_vlm-loaded model weights.
When mlx_vlm loads a model, it strips MTP weights in sanitize(). This module builds a parallel mlx_lm TextModel that: 1. Shares backbone + lm_head weights with the vlm model (zero-copy) 2. Loads MTP weights from safetensors on disk 3. Provides full mlx_lm API: return_hidden, n_confirmed, mtp_forward, make_mtp_cache
vllm_mlx.text_model_from_vlm._TEXT_MODEL_FAMILIES
module-attribute
¶
_TEXT_MODEL_FAMILIES: tuple[tuple[str, str, tuple[str, str]], ...] = (('gemma4', 'mlx_lm.models.gemma4_text', ('Model', 'ModelArgs')),)
vllm_mlx.text_model_from_vlm._DEFAULT_TEXT_MODEL
module-attribute
¶
vllm_mlx.text_model_from_vlm._import_text_model_classes
¶
Return (Model, ModelArgs) for a text config's model_type.
Source code in vllm_mlx/text_model_from_vlm.py
vllm_mlx.text_model_from_vlm.build_text_model
¶
Build an mlx_lm TextModel from a vlm-loaded model's weights.
Parameters:
-
vlm_model(Any) –The mlx_vlm-loaded model (has .language_model attribute)
-
model_path(str | Path) –Path to the model directory (contains config.json + safetensors)
Returns:
-
Any | None–mlx_lm TextModel with MTP support, or None on failure.
Source code in vllm_mlx/text_model_from_vlm.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
vllm_mlx.text_model_from_vlm._load_mtp_weights
¶
Load MTP weights from safetensors, stripping the language_model. prefix.
mlx_vlm's sanitize() strips mtp.* keys during model loading, but the weights are still on disk in the safetensors files.
Source code in vllm_mlx/text_model_from_vlm.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.text_model_from_vlm._import_text_model_classes · function
Return (Model, ModelArgs) for a text config's model_type.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_type |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
(getattr(module, model_attr), getattr(module, args_attr))
Exceptions and behavior
Function _import_text_model_classes calls sorted, model_type.startswith, logger.debug, importlib.import_module; returns (getattr(module, model_attr), getattr(module, args_attr)).
No direct raise statement appears in this definition.
vllm_mlx.text_model_from_vlm.build_text_model · function
Build an mlx_lm TextModel from a vlm-loaded model's weights.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
vlm_model |
Any |
yes |
none |
The mlx_vlm-loaded model (has .language_model attribute) |
model_path |
str \| Path |
yes |
none |
Path to the model directory (contains config.json + safetensors) |
Returns
- Type:
Any | None - Direct return expressions:
None;text_model
Exceptions and behavior
Function build_text_model calls Path, (model_path / 'config.json').exists, json.loads, (model_path / 'config.json').read_text; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.text_model_from_vlm.build_text_model._class_predicate · nested function
Nested Function build_text_model._class_predicate calls hasattr, per_layer_overrides.items, key.endswith; has 4 explicit return paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
path |
not annotated |
yes |
none |
Required positional or keyword input. |
module |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
False;quantization[path];override;True
Exceptions and behavior
Nested Function build_text_model._class_predicate calls hasattr, per_layer_overrides.items, key.endswith; has 4 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.text_model_from_vlm._load_mtp_weights · function
Load MTP weights from safetensors, stripping the language_model.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_path |
Path |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
list[tuple[str, mx.array]] - Direct return expressions:
[];weights
Exceptions and behavior
Function _load_mtp_weights calls index_file.exists, json.loads, index_file.read_text, index.get; has 2 explicit return paths.
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 |
|---|---|---|---|---|
_import_text_model_classes |
function | _import_text_model_classes(model_type: str) -> not annotated |
Return (Model, ModelArgs) for a text config's model_type. |
#L41-L66 |
build_text_model |
function | build_text_model(vlm_model: Any, model_path: str \| Path) -> Any \| None |
Build an mlx_lm TextModel from a vlm-loaded model's weights. | #L69-L225 |
build_text_model._class_predicate |
nested function | build_text_model._class_predicate(path, module) -> not annotated |
Nested Function build_text_model._class_predicate calls hasattr, per_layer_overrides.items, key.endswith; has 4 explicit return paths. |
#L127-L137 |
_load_mtp_weights |
function | _load_mtp_weights(model_path: Path) -> list[tuple[str, mx.array]] |
Load MTP weights from safetensors, stripping the language_model. | #L228-L272 |