examples.benchmark_detokenizer¶
Benchmark: Streaming Detokenizer vs Naive Decode Compares performance of: 1.
View the complete module source at #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
¶
Benchmark: Streaming Detokenizer vs Naive Decode
Compares performance of: 1. Old method: tokenizer.decode([token]) for each token 2. New method: StreamingDetokenizer.add_token() + last_segment
Run
python examples/benchmark_detokenizer.py
examples.benchmark_detokenizer.benchmark_naive_decode
¶
Benchmark naive decode approach (old method).
Source code in examples/benchmark_detokenizer.py
examples.benchmark_detokenizer.benchmark_streaming_detokenizer
¶
Benchmark streaming detokenizer approach (new method).
Source code in examples/benchmark_detokenizer.py
examples.benchmark_detokenizer.main
¶
Source code in examples/benchmark_detokenizer.py
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 | |
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.
examples.benchmark_detokenizer.benchmark_naive_decode · function
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.
examples.benchmark_detokenizer.benchmark_streaming_detokenizer · function
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.
examples.benchmark_detokenizer.main · function
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.
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 |
function | benchmark_naive_decode(tokenizer, tokens, iterations = 10) -> not annotated |
Benchmark naive decode approach (old method). | #L26-L48 |
benchmark_streaming_detokenizer |
function | benchmark_streaming_detokenizer(tokenizer, tokens, detokenizer_class, iterations = 10) -> not annotated |
Benchmark streaming detokenizer approach (new method). | #L51-L78 |
main |
function | main() -> not annotated |
Function main calls print, Path, snapshot_download, load_tokenizer. |
#L81-L182 |