# `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](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/text_model_from_vlm.py#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
    options:
      members:
        - logger
        - _TEXT_MODEL_FAMILIES
        - _DEFAULT_TEXT_MODEL
        - _import_text_model_classes
        - build_text_model
        - _load_mtp_weights
      filters: []
      show_if_no_docstring: true

## 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.

<details class="api-contract" id="contract-vllm_mlx.text_model_from_vlm._import_text_model_classes" markdown="1">
<summary><code>vllm_mlx.text_model_from_vlm._import_text_model_classes</code> · function</summary>

```python
vllm_mlx.text_model_from_vlm._import_text_model_classes(model_type: str) -> not annotated
```

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.

[View source #L41-L66](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/text_model_from_vlm.py#L41-L66).

</details>

<details class="api-contract" id="contract-vllm_mlx.text_model_from_vlm.build_text_model" markdown="1">
<summary><code>vllm_mlx.text_model_from_vlm.build_text_model</code> · function</summary>

```python
vllm_mlx.text_model_from_vlm.build_text_model(vlm_model: Any, model_path: str | Path) -> Any | None
```

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.

[View source #L69-L225](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/text_model_from_vlm.py#L69-L225).

</details>

<details class="api-contract" id="contract-vllm_mlx.text_model_from_vlm.build_text_model._class_predicate" markdown="1">
<summary><code>vllm_mlx.text_model_from_vlm.build_text_model._class_predicate</code> · nested function</summary>

```python
vllm_mlx.text_model_from_vlm.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.

**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.

[View source #L127-L137](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/text_model_from_vlm.py#L127-L137).

</details>

<details class="api-contract" id="contract-vllm_mlx.text_model_from_vlm._load_mtp_weights" markdown="1">
<summary><code>vllm_mlx.text_model_from_vlm._load_mtp_weights</code> · function</summary>

```python
vllm_mlx.text_model_from_vlm._load_mtp_weights(model_path: Path) -> list[tuple[str, mx.array]]
```

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.

[View source #L228-L272](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/text_model_from_vlm.py#L228-L272).

</details>

## 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`](#contract-vllm_mlx.text_model_from_vlm._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](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/text_model_from_vlm.py#L41-L66) |
| [`build_text_model`](#contract-vllm_mlx.text_model_from_vlm.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](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/text_model_from_vlm.py#L69-L225) |
| [`build_text_model._class_predicate`](#contract-vllm_mlx.text_model_from_vlm.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](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/text_model_from_vlm.py#L127-L137) |
| [`_load_mtp_weights`](#contract-vllm_mlx.text_model_from_vlm._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](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/text_model_from_vlm.py#L228-L272) |
