# `vllm_mlx.patches.glm4v_moe_mllm`

Runtime patch for mlx-vlm's GLM-4.6V model to support BatchKVCache.

[View the complete module source at #L1-L89](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/patches/glm4v_moe_mllm.py#L1-L89).

## 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.patches.glm4v_moe_mllm
    options:
      members:
        - logger
        - patch_glm4v_moe_for_batching
      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.patches.glm4v_moe_mllm.patch_glm4v_moe_for_batching" markdown="1">
<summary><code>vllm_mlx.patches.glm4v_moe_mllm.patch_glm4v_moe_for_batching</code> · function</summary>

```python
vllm_mlx.patches.glm4v_moe_mllm.patch_glm4v_moe_for_batching() -> bool
```

Monkey-patch GLM4VModel.__call__ to handle BatchKVCache offset.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `bool`
- Direct return expressions: `False`; `True`

**Exceptions and behavior**

Function `patch_glm4v_moe_for_batching` calls `logger.debug`, `getattr`, `logger.info`; has 2 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L31-L89](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/patches/glm4v_moe_mllm.py#L31-L89).

</details>

<details class="api-contract" id="contract-vllm_mlx.patches.glm4v_moe_mllm.patch_glm4v_moe_for_batching._patched_call" markdown="1">
<summary><code>vllm_mlx.patches.glm4v_moe_mllm.patch_glm4v_moe_for_batching._patched_call</code> · nested function</summary>

```python
vllm_mlx.patches.glm4v_moe_mllm.patch_glm4v_moe_for_batching._patched_call(inputs: mx.array, inputs_embeds: Optional[mx.array] = None, cache: Optional[Any] = None, mask: Optional[mx.array] = None, position_ids: Optional[mx.array] = None) -> mx.array
```

Nested Function `patch_glm4v_moe_for_batching._patched_call` calls `self.embed_tokens`, `inputs_embeds.astype`, `isinstance`, `int`; returns `self.norm(h)`.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `inputs` | `mx.array` | `yes` | `none` | Required positional or keyword input. |
| `inputs_embeds` | `Optional[mx.array]` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |
| `cache` | `Optional[Any]` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |
| `mask` | `Optional[mx.array]` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |
| `position_ids` | `Optional[mx.array]` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |

**Returns**

- Type: `mx.array`
- Direct return expressions: `self.norm(h)`

**Exceptions and behavior**

Nested Function `patch_glm4v_moe_for_batching._patched_call` calls `self.embed_tokens`, `inputs_embeds.astype`, `isinstance`, `int`; returns `self.norm(h)`.
No direct `raise` statement appears in this definition.

[View source #L50-L84](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/patches/glm4v_moe_mllm.py#L50-L84).

</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 |
| --- | --- | --- | --- | --- |
| [`patch_glm4v_moe_for_batching`](#contract-vllm_mlx.patches.glm4v_moe_mllm.patch_glm4v_moe_for_batching) | function | `patch_glm4v_moe_for_batching() -> bool` | Monkey-patch GLM4VModel.__call__ to handle BatchKVCache offset. | [#L31-L89](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/patches/glm4v_moe_mllm.py#L31-L89) |
| [`patch_glm4v_moe_for_batching._patched_call`](#contract-vllm_mlx.patches.glm4v_moe_mllm.patch_glm4v_moe_for_batching._patched_call) | nested function | `patch_glm4v_moe_for_batching._patched_call(inputs: mx.array, inputs_embeds: Optional[mx.array] = None, cache: Optional[Any] = None, mask: Optional[mx.array] = None, position_ids: Optional[mx.array] = None) -> mx.array` | Nested Function `patch_glm4v_moe_for_batching._patched_call` calls `self.embed_tokens`, `inputs_embeds.astype`, `isinstance`, `int`; returns `self.norm(h)`. | [#L50-L84](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/patches/glm4v_moe_mllm.py#L50-L84) |
