# `examples.benchmark_detokenizer`

Benchmark: Streaming Detokenizer vs Naive Decode Compares performance of: 1.

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

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

::: examples.benchmark_detokenizer
    options:
      members:
        - benchmark_naive_decode
        - benchmark_streaming_detokenizer
        - main
      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-examples.benchmark_detokenizer.benchmark_naive_decode" markdown="1">
<summary><code>examples.benchmark_detokenizer.benchmark_naive_decode</code> · function</summary>

```python
examples.benchmark_detokenizer.benchmark_naive_decode(tokenizer, tokens, iterations = 10) -> not annotated
```

Benchmark naive decode approach (old method).

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tokenizer` | `not annotated` | `yes` | `none` | Required positional or keyword input. |
| `tokens` | `not annotated` | `yes` | `none` | Required positional or keyword input. |
| `iterations` | `not annotated` | `no` | `10` | Optional positional or keyword input; defaults to `10`. |

**Returns**

- Type: `not annotated`
- Direct return expressions: `{'method': 'naive_decode', 'mean_ms': statistics.mean(times) * 1000, 'std_ms': statistics.stdev(times) * 1000 if len(ti…`

**Exceptions and behavior**

Function `benchmark_naive_decode` calls `range`, `time.perf_counter`, `tokenizer.decode`, `texts.append`; returns `{'method': 'naive_decode', 'mean_ms': statistics.mean(times) * 1000, 'std_ms': statistics.stdev(times) * 1000 if len(ti…`.
No direct `raise` statement appears in this definition.

[View source #L26-L48](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/benchmark_detokenizer.py#L26-L48).

</details>

<details class="api-contract" id="contract-examples.benchmark_detokenizer.benchmark_streaming_detokenizer" markdown="1">
<summary><code>examples.benchmark_detokenizer.benchmark_streaming_detokenizer</code> · function</summary>

```python
examples.benchmark_detokenizer.benchmark_streaming_detokenizer(tokenizer, tokens, detokenizer_class, iterations = 10) -> not annotated
```

Benchmark streaming detokenizer approach (new method).

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tokenizer` | `not annotated` | `yes` | `none` | Required positional or keyword input. |
| `tokens` | `not annotated` | `yes` | `none` | Required positional or keyword input. |
| `detokenizer_class` | `not annotated` | `yes` | `none` | Required positional or keyword input. |
| `iterations` | `not annotated` | `no` | `10` | Optional positional or keyword input; defaults to `10`. |

**Returns**

- Type: `not annotated`
- Direct return expressions: `{'method': detokenizer_class.__name__, 'mean_ms': statistics.mean(times) * 1000, 'std_ms': statistics.stdev(times) * 10…`

**Exceptions and behavior**

Function `benchmark_streaming_detokenizer` calls `range`, `detokenizer_class`, `detok.reset`, `time.perf_counter`; returns `{'method': detokenizer_class.__name__, 'mean_ms': statistics.mean(times) * 1000, 'std_ms': statistics.stdev(times) * 10…`.
No direct `raise` statement appears in this definition.

[View source #L51-L78](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/benchmark_detokenizer.py#L51-L78).

</details>

<details class="api-contract" id="contract-examples.benchmark_detokenizer.main" markdown="1">
<summary><code>examples.benchmark_detokenizer.main</code> · function</summary>

```python
examples.benchmark_detokenizer.main() -> not annotated
```

Function `main` calls `print`, `Path`, `snapshot_download`, `load_tokenizer`.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `not annotated`

**Exceptions and behavior**

Function `main` calls `print`, `Path`, `snapshot_download`, `load_tokenizer`.
No direct `raise` statement appears in this definition.

[View source #L81-L182](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/benchmark_detokenizer.py#L81-L182).

</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 |
| --- | --- | --- | --- | --- |
| [`benchmark_naive_decode`](#contract-examples.benchmark_detokenizer.benchmark_naive_decode) | function | `benchmark_naive_decode(tokenizer, tokens, iterations = 10) -> not annotated` | Benchmark naive decode approach (old method). | [#L26-L48](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/benchmark_detokenizer.py#L26-L48) |
| [`benchmark_streaming_detokenizer`](#contract-examples.benchmark_detokenizer.benchmark_streaming_detokenizer) | function | `benchmark_streaming_detokenizer(tokenizer, tokens, detokenizer_class, iterations = 10) -> not annotated` | Benchmark streaming detokenizer approach (new method). | [#L51-L78](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/benchmark_detokenizer.py#L51-L78) |
| [`main`](#contract-examples.benchmark_detokenizer.main) | function | `main() -> not annotated` | Function `main` calls `print`, `Path`, `snapshot_download`, `load_tokenizer`. | [#L81-L182](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/benchmark_detokenizer.py#L81-L182) |
