# `vllm_mlx.attention`

MLX Attention Backend for vLLM.

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

## 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.attention
    options:
      members:
        - logger
        - MLXAttentionMetadata
        - MLXAttentionBackend
        - MLXAttentionImpl
        - create_mlx_attention_backend
      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.attention.MLXAttentionMetadata" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionMetadata</code> · class</summary>

```python
vllm_mlx.attention.MLXAttentionMetadata(seq_lens: list[int], max_seq_len: int, num_prefill_tokens: int = 0, num_decode_tokens: int = 0, block_tables: Any | None = None, slot_mapping: Any | None = None)
```

Metadata for MLX attention computation.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `seq_lens` | `list[int]` | `yes` | `none` | Required constructor field. |
| `max_seq_len` | `int` | `yes` | `none` | Required constructor field. |
| `num_prefill_tokens` | `int` | `no` | `0` | Optional constructor field; defaults to `0`. |
| `num_decode_tokens` | `int` | `no` | `0` | Optional constructor field; defaults to `0`. |
| `block_tables` | `Any \| None` | `no` | `None` | Optional constructor field; defaults to `None`. |
| `slot_mapping` | `Any \| None` | `no` | `None` | Optional constructor field; defaults to `None`. |

**Returns**

- Constructs: `vllm_mlx.attention.MLXAttentionMetadata`

**Exceptions and behavior**

Class `MLXAttentionMetadata` declares 0 direct member(s).
No direct `raise` statement appears in this definition.

[View source #L20-L39](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L20-L39).

</details>

<details class="api-contract" id="contract-vllm_mlx.attention.MLXAttentionBackend" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionBackend</code> · class</summary>

```python
vllm_mlx.attention.MLXAttentionBackend()
```

Attention backend using MLX's native attention.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Constructs: `vllm_mlx.attention.MLXAttentionBackend`

**Exceptions and behavior**

Class `MLXAttentionBackend` declares 9 direct member(s).
No direct `raise` statement appears in this definition.

[View source #L42-L135](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L42-L135).

</details>

<details class="api-contract" id="contract-vllm_mlx.attention.MLXAttentionBackend.get_name" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionBackend.get_name</code> · method</summary>

```python
vllm_mlx.attention.MLXAttentionBackend.get_name() -> str
```

Return backend name.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `str`
- Direct return expressions: `'MLX'`

**Exceptions and behavior**

Method `MLXAttentionBackend.get_name` returns `'MLX'`.
No direct `raise` statement appears in this definition.

[View source #L55-L57](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L55-L57).

</details>

<details class="api-contract" id="contract-vllm_mlx.attention.MLXAttentionBackend.get_impl_cls" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionBackend.get_impl_cls</code> · method</summary>

```python
vllm_mlx.attention.MLXAttentionBackend.get_impl_cls() -> type
```

Return the implementation class.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `type`
- Direct return expressions: `MLXAttentionImpl`

**Exceptions and behavior**

Method `MLXAttentionBackend.get_impl_cls` returns `MLXAttentionImpl`.
No direct `raise` statement appears in this definition.

[View source #L60-L62](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L60-L62).

</details>

<details class="api-contract" id="contract-vllm_mlx.attention.MLXAttentionBackend.get_metadata_cls" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionBackend.get_metadata_cls</code> · method</summary>

```python
vllm_mlx.attention.MLXAttentionBackend.get_metadata_cls() -> type
```

Return the metadata class.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `type`
- Direct return expressions: `MLXAttentionMetadata`

**Exceptions and behavior**

Method `MLXAttentionBackend.get_metadata_cls` returns `MLXAttentionMetadata`.
No direct `raise` statement appears in this definition.

[View source #L65-L67](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L65-L67).

</details>

<details class="api-contract" id="contract-vllm_mlx.attention.MLXAttentionBackend.get_kv_cache_shape" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionBackend.get_kv_cache_shape</code> · method</summary>

```python
vllm_mlx.attention.MLXAttentionBackend.get_kv_cache_shape(num_blocks: int, block_size: int, num_kv_heads: int, head_size: int) -> tuple[int, ...]
```

Get the shape of KV cache.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `num_blocks` | `int` | `yes` | `none` | Number of cache blocks |
| `block_size` | `int` | `yes` | `none` | Tokens per block |
| `num_kv_heads` | `int` | `yes` | `none` | Number of KV attention heads |
| `head_size` | `int` | `yes` | `none` | Size of each attention head |

**Returns**

- Type: `tuple[int, ...]`
- Direct return expressions: `(num_blocks, block_size, num_kv_heads, head_size)`

**Exceptions and behavior**

Method `MLXAttentionBackend.get_kv_cache_shape` returns `(num_blocks, block_size, num_kv_heads, head_size)`.
No direct `raise` statement appears in this definition.

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

</details>

<details class="api-contract" id="contract-vllm_mlx.attention.MLXAttentionBackend.get_supported_head_sizes" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionBackend.get_supported_head_sizes</code> · method</summary>

```python
vllm_mlx.attention.MLXAttentionBackend.get_supported_head_sizes() -> list[int]
```

Return supported attention head sizes.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `list[int]`
- Direct return expressions: `[64, 80, 96, 112, 128, 256]`

**Exceptions and behavior**

Method `MLXAttentionBackend.get_supported_head_sizes` returns `[64, 80, 96, 112, 128, 256]`.
No direct `raise` statement appears in this definition.

[View source #L92-L94](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L92-L94).

</details>

<details class="api-contract" id="contract-vllm_mlx.attention.MLXAttentionBackend.validate_configuration" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionBackend.validate_configuration</code> · method</summary>

```python
vllm_mlx.attention.MLXAttentionBackend.validate_configuration(num_heads: int, head_size: int, num_kv_heads: int, dtype: 'torch.dtype', block_size: int, **kwargs) -> list[str]
```

Validate attention configuration.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `num_heads` | `int` | `yes` | `none` | Required positional or keyword input. |
| `head_size` | `int` | `yes` | `none` | Required positional or keyword input. |
| `num_kv_heads` | `int` | `yes` | `none` | Required positional or keyword input. |
| `dtype` | `'torch.dtype'` | `yes` | `none` | Required positional or keyword input. |
| `block_size` | `int` | `yes` | `none` | Required positional or keyword input. |
| `**kwargs` | `not annotated` | `no` | `none` | Additional variadic keyword inputs accepted by this callable. |

**Returns**

- Type: `list[str]`
- Direct return expressions: `errors`

**Exceptions and behavior**

Method `MLXAttentionBackend.validate_configuration` calls `MLXAttentionBackend.get_supported_head_sizes`, `errors.append`; returns `errors`.
No direct `raise` statement appears in this definition.

[View source #L97-L118](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L97-L118).

</details>

<details class="api-contract" id="contract-vllm_mlx.attention.MLXAttentionBackend.supports_dtype" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionBackend.supports_dtype</code> · method</summary>

```python
vllm_mlx.attention.MLXAttentionBackend.supports_dtype(dtype: 'torch.dtype') -> bool
```

Check if dtype is supported.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `dtype` | `'torch.dtype'` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `bool`
- Direct return expressions: `dtype in [torch.float16, torch.bfloat16, torch.float32]`

**Exceptions and behavior**

Method `MLXAttentionBackend.supports_dtype` returns `dtype in [torch.float16, torch.bfloat16, torch.float32]`.
No direct `raise` statement appears in this definition.

[View source #L121-L125](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L121-L125).

</details>

<details class="api-contract" id="contract-vllm_mlx.attention.MLXAttentionBackend.supports_block_size" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionBackend.supports_block_size</code> · method</summary>

```python
vllm_mlx.attention.MLXAttentionBackend.supports_block_size(block_size: int) -> bool
```

Check if block size is supported.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `block_size` | `int` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `bool`
- Direct return expressions: `block_size in [8, 16, 32]`

**Exceptions and behavior**

Method `MLXAttentionBackend.supports_block_size` returns `block_size in [8, 16, 32]`.
No direct `raise` statement appears in this definition.

[View source #L128-L130](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L128-L130).

</details>

<details class="api-contract" id="contract-vllm_mlx.attention.MLXAttentionBackend.supports_attn_type" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionBackend.supports_attn_type</code> · method</summary>

```python
vllm_mlx.attention.MLXAttentionBackend.supports_attn_type(attn_type: str) -> bool
```

Check if attention type is supported.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `attn_type` | `str` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `bool`
- Direct return expressions: `attn_type in ['decoder', 'encoder', 'encoder_decoder']`

**Exceptions and behavior**

Method `MLXAttentionBackend.supports_attn_type` returns `attn_type in ['decoder', 'encoder', 'encoder_decoder']`.
No direct `raise` statement appears in this definition.

[View source #L133-L135](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L133-L135).

</details>

<details class="api-contract" id="contract-vllm_mlx.attention.MLXAttentionImpl" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionImpl</code> · class</summary>

```python
vllm_mlx.attention.MLXAttentionImpl(num_heads: int, head_size: int, scale: float, num_kv_heads: int | None = None, alibi_slopes: list[float] | None = None, sliding_window: int | None = None, kv_cache_dtype: str = 'auto', blocksparse_params: dict | None = None, logits_soft_cap: float | None = None, **kwargs)
```

MLX attention implementation.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `num_heads` | `int` | `yes` | `none` | Number of attention heads |
| `head_size` | `int` | `yes` | `none` | Size of each head |
| `scale` | `float` | `yes` | `none` | Attention scale factor |
| `num_kv_heads` | `int \| None` | `no` | `None` | Number of KV heads (for GQA/MQA) |
| `alibi_slopes` | `list[float] \| None` | `no` | `None` | ALiBi position encoding slopes |
| `sliding_window` | `int \| None` | `no` | `None` | Sliding window attention size |
| `kv_cache_dtype` | `str` | `no` | `'auto'` | KV cache data type |
| `blocksparse_params` | `dict \| None` | `no` | `None` | Block-sparse attention params |
| `logits_soft_cap` | `float \| None` | `no` | `None` | Soft cap for logits |
| `**kwargs` | `not annotated` | `no` | `none` | Additional variadic keyword inputs accepted by this callable. |

**Returns**

- Constructs: `vllm_mlx.attention.MLXAttentionImpl`

**Exceptions and behavior**

Class `MLXAttentionImpl` declares 2 direct member(s).
No direct `raise` statement appears in this definition.

[View source #L138-L240](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L138-L240).

</details>

<details class="api-contract" id="contract-vllm_mlx.attention.MLXAttentionImpl.__init__" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionImpl.__init__</code> · method</summary>

```python
vllm_mlx.attention.MLXAttentionImpl.__init__(num_heads: int, head_size: int, scale: float, num_kv_heads: int | None = None, alibi_slopes: list[float] | None = None, sliding_window: int | None = None, kv_cache_dtype: str = 'auto', blocksparse_params: dict | None = None, logits_soft_cap: float | None = None, **kwargs) -> not annotated
```

Initialize MLX attention.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `num_heads` | `int` | `yes` | `none` | Number of attention heads |
| `head_size` | `int` | `yes` | `none` | Size of each head |
| `scale` | `float` | `yes` | `none` | Attention scale factor |
| `num_kv_heads` | `int \| None` | `no` | `None` | Number of KV heads (for GQA/MQA) |
| `alibi_slopes` | `list[float] \| None` | `no` | `None` | ALiBi position encoding slopes |
| `sliding_window` | `int \| None` | `no` | `None` | Sliding window attention size |
| `kv_cache_dtype` | `str` | `no` | `'auto'` | KV cache data type |
| `blocksparse_params` | `dict \| None` | `no` | `None` | Block-sparse attention params |
| `logits_soft_cap` | `float \| None` | `no` | `None` | Soft cap for logits |
| `**kwargs` | `not annotated` | `no` | `none` | Additional variadic keyword inputs accepted by this callable. |

**Returns**

- Type: `not annotated`

**Exceptions and behavior**

Method `MLXAttentionImpl.__init__` updates `self.num_heads`, `self.head_size`, `self.scale`, `self.num_kv_heads`; calls `logger.debug`.
No direct `raise` statement appears in this definition.

[View source #L147-L186](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L147-L186).

</details>

<details class="api-contract" id="contract-vllm_mlx.attention.MLXAttentionImpl.forward" markdown="1">
<summary><code>vllm_mlx.attention.MLXAttentionImpl.forward</code> · method</summary>

```python
vllm_mlx.attention.MLXAttentionImpl.forward(query: Any, key: Any, value: Any, kv_cache: Any | None = None, attn_metadata: MLXAttentionMetadata | None = None, output: Any | None = None, **kwargs) -> Any
```

Compute attention.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `query` | `Any` | `yes` | `none` | Query tensor |
| `key` | `Any` | `yes` | `none` | Key tensor |
| `value` | `Any` | `yes` | `none` | Value tensor |
| `kv_cache` | `Any \| None` | `no` | `None` | Optional KV cache |
| `attn_metadata` | `MLXAttentionMetadata \| None` | `no` | `None` | Attention metadata |
| `output` | `Any \| None` | `no` | `None` | Optional output buffer |
| `**kwargs` | `not annotated` | `no` | `none` | Additional variadic keyword inputs accepted by this callable. |

**Returns**

- Type: `Any`
- Direct return expressions: `attn_output`

**Exceptions and behavior**

Method `MLXAttentionImpl.forward` calls `isinstance`, `mx.array`, `hasattr`, `query.numpy`; returns `attn_output`.
No direct `raise` statement appears in this definition.

[View source #L188-L240](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L188-L240).

</details>

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

```python
vllm_mlx.attention.create_mlx_attention_backend() -> type
```

Factory function to create MLX attention backend.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `type`
- Direct return expressions: `MLXAttentionBackend`

**Exceptions and behavior**

Function `create_mlx_attention_backend` returns `MLXAttentionBackend`.
No direct `raise` statement appears in this definition.

[View source #L243-L245](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L243-L245).

</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 |
| --- | --- | --- | --- | --- |
| [`MLXAttentionMetadata`](#contract-vllm_mlx.attention.MLXAttentionMetadata) | class | `MLXAttentionMetadata(seq_lens: list[int], max_seq_len: int, num_prefill_tokens: int = 0, num_decode_tokens: int = 0, block_tables: Any \| None = None, slot_mapping: Any \| None = None)` | Metadata for MLX attention computation. | [#L20-L39](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L20-L39) |
| [`MLXAttentionBackend`](#contract-vllm_mlx.attention.MLXAttentionBackend) | class | `MLXAttentionBackend()` | Attention backend using MLX's native attention. | [#L42-L135](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L42-L135) |
| [`MLXAttentionBackend.get_name`](#contract-vllm_mlx.attention.MLXAttentionBackend.get_name) | method | `MLXAttentionBackend.get_name() -> str` | Return backend name. | [#L55-L57](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L55-L57) |
| [`MLXAttentionBackend.get_impl_cls`](#contract-vllm_mlx.attention.MLXAttentionBackend.get_impl_cls) | method | `MLXAttentionBackend.get_impl_cls() -> type` | Return the implementation class. | [#L60-L62](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L60-L62) |
| [`MLXAttentionBackend.get_metadata_cls`](#contract-vllm_mlx.attention.MLXAttentionBackend.get_metadata_cls) | method | `MLXAttentionBackend.get_metadata_cls() -> type` | Return the metadata class. | [#L65-L67](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L65-L67) |
| [`MLXAttentionBackend.get_kv_cache_shape`](#contract-vllm_mlx.attention.MLXAttentionBackend.get_kv_cache_shape) | method | `MLXAttentionBackend.get_kv_cache_shape(num_blocks: int, block_size: int, num_kv_heads: int, head_size: int) -> tuple[int, ...]` | Get the shape of KV cache. | [#L70-L89](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L70-L89) |
| [`MLXAttentionBackend.get_supported_head_sizes`](#contract-vllm_mlx.attention.MLXAttentionBackend.get_supported_head_sizes) | method | `MLXAttentionBackend.get_supported_head_sizes() -> list[int]` | Return supported attention head sizes. | [#L92-L94](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L92-L94) |
| [`MLXAttentionBackend.validate_configuration`](#contract-vllm_mlx.attention.MLXAttentionBackend.validate_configuration) | method | `MLXAttentionBackend.validate_configuration(num_heads: int, head_size: int, num_kv_heads: int, dtype: 'torch.dtype', block_size: int, **kwargs) -> list[str]` | Validate attention configuration. | [#L97-L118](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L97-L118) |
| [`MLXAttentionBackend.supports_dtype`](#contract-vllm_mlx.attention.MLXAttentionBackend.supports_dtype) | method | `MLXAttentionBackend.supports_dtype(dtype: 'torch.dtype') -> bool` | Check if dtype is supported. | [#L121-L125](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L121-L125) |
| [`MLXAttentionBackend.supports_block_size`](#contract-vllm_mlx.attention.MLXAttentionBackend.supports_block_size) | method | `MLXAttentionBackend.supports_block_size(block_size: int) -> bool` | Check if block size is supported. | [#L128-L130](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L128-L130) |
| [`MLXAttentionBackend.supports_attn_type`](#contract-vllm_mlx.attention.MLXAttentionBackend.supports_attn_type) | method | `MLXAttentionBackend.supports_attn_type(attn_type: str) -> bool` | Check if attention type is supported. | [#L133-L135](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L133-L135) |
| [`MLXAttentionImpl`](#contract-vllm_mlx.attention.MLXAttentionImpl) | class | `MLXAttentionImpl(num_heads: int, head_size: int, scale: float, num_kv_heads: int \| None = None, alibi_slopes: list[float] \| None = None, sliding_window: int \| None = None, kv_cache_dtype: str = 'auto', blocksparse_params: dict \| None = None, logits_soft_cap: float \| None = None, **kwargs)` | MLX attention implementation. | [#L138-L240](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L138-L240) |
| [`MLXAttentionImpl.__init__`](#contract-vllm_mlx.attention.MLXAttentionImpl.__init__) | method | `MLXAttentionImpl.__init__(num_heads: int, head_size: int, scale: float, num_kv_heads: int \| None = None, alibi_slopes: list[float] \| None = None, sliding_window: int \| None = None, kv_cache_dtype: str = 'auto', blocksparse_params: dict \| None = None, logits_soft_cap: float \| None = None, **kwargs) -> not annotated` | Initialize MLX attention. | [#L147-L186](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L147-L186) |
| [`MLXAttentionImpl.forward`](#contract-vllm_mlx.attention.MLXAttentionImpl.forward) | method | `MLXAttentionImpl.forward(query: Any, key: Any, value: Any, kv_cache: Any \| None = None, attn_metadata: MLXAttentionMetadata \| None = None, output: Any \| None = None, **kwargs) -> Any` | Compute attention. | [#L188-L240](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L188-L240) |
| [`create_mlx_attention_backend`](#contract-vllm_mlx.attention.create_mlx_attention_backend) | function | `create_mlx_attention_backend() -> type` | Factory function to create MLX attention backend. | [#L243-L245](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/attention.py#L243-L245) |
