Exact incremental BPE maintains the canonical tokenization state after every appended byte. The recent algorithm of Jiang and Gong (2026) does this in O(log2t) worst-case time, where t is the maximum canonical token length. Its centroid search visits O(logt) components and can pay another O(logt) for ordered point location at each one. Within Jiang and Gong's normalized/proper merge-stage model, we change only that local search. Each interval is weighted by the size of the recursive component it selects, so a move from size m to size m′ costs O(1+log(m/m′)). These charges telescope, giving O(logt) time per append and O(nlogt) over an n-byte stream, with the same BPE semantics and asymptotic space. We also construct a normalized proper BPE family over a fixed alphabet where count-balanced search uses Θ(log2t) probes on a reachable update, while the weighted search uses Θ(logt). A Rust implementation matches the predicted probe counts on every tested instance. On ordinary vocabularies the queried degrees are small, however, and the improvement is a worst-case guarantee rather than an average-speed result.
Figures & tables
Figure 1: Exact interval-record probes on the reachable final update. Markers are measurements and curves are the proved formulas for the executable family. At t=8192 , count-balanced search uses 92 probes and component-weighted search uses 13.
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
Vocabulary
Corpus
Record probes
Endpoint comparisons
Binary
Weighted
Binary
Weighted
GPT-2
English
2/4/5/5/7
1/2/2/3/4
2/4/5/5/7
2/4/4/5/7
GPT-2
Code
2/4/5/6/7
1/2/2/3/4
2/4/5/6/7
2/4/4/6/8
RoBERTa-base
English
2/4/5/5/7
1/2/2/3/4
2/4/5/5/7
2/4/4/5/7
RoBERTa-base
Code
2/4/5/6/7
1/2/2/3/4
2/4/5/6/7
2/4/4/6/8
GPT-NeoX-20B
English
2/4/5/5/7
1/2/2/3/3
2/4/5/5/7
2/4/4/5/6
Appendix
Table 1: Search-conditional tails over one million updates. Each tuple is p50/p95/p99/p99.9/max.
Vocabulary
Corpus
Search (%)
Max degree
p99 probes
Max probes
ns/update
GPT-2
English
9.53
4
5→2
7→4
13.15→13.72
GPT-2
Code
7.40
4
5→2
7→4
9.49→9.67
RoBERTa-base
English
9.53
4
5→2
7→4
13.27→14.65
RoBERTa-base
Code
7.40
4
5→2
7→4
10.22→10.25
GPT-NeoX-20B
English
9.57
4
5→2
7→3
12.78→14.45
GPT-NeoX-20B
Code
12.26
5
5→2
8→4
10.57→11.11
Appendix
Table 2: Ordinary-vocabulary results over one million updates per row. Each paired value is count-balanced → component-weighted. Probes are conditional on entering interval search; time measures the complete update.
Retained MB
Search bytes/interval
Initialization ms
Vocabulary
Binary
Weighted
Binary
Weighted
Binary
Weighted
GPT-2
38.50
44.71
144.71
190.17
41.21 [40.05,43.16]
49.49 [49.30,50.93]
RoBERTa-base
38.50
44.71
144.71
190.17
41.72 [40.88,42.08]
49.58 [48.37,49.84]
GPT-NeoX-20B
38.32
44.60
142.17
186.87
39.82 [39.60,39.87]
54.48 [52.79,55.23]
Appendix
Table 3: Separate-process initialization. Memory is decimal MB; times are median [q1,q3] over nine builds.
We propose a novel algorithm for incremental Byte Pair Encoding (BPE) tokenization. The algorithm processes each input byte in worst-case O(log2t) time, leading to an overall complexity of O(nlog2t), where n is the input length and t is the maximum token length. The algorithm incrementally maintains BPE tokenization results for every prefix of the input text, implementing the standard BPE merge procedure defined by a fixed set of merge rules. This enables efficient partial tokenization in streaming settings. Functioning as a drop-in replacement for standard BPE, our approach achieves a speedup of up to ∼3× over Hugging Face's tokenizers, and demonstrates significant latency reductions over OpenAI's tiktoken on pathological inputs. We further introduce an eager output algorithm that enables streaming output, emitting tokens as soon as token boundaries are determined during incremental tokenization. Overall, our results demonstrate that BPE tokenization can be performed incrementally with strong worst-case guarantees, while providing practical latency benefits in modern large language model pipelines. Code: https://github.com/ModelTC/mtc-inc-bpe
Byte Pair Encoding (BPE) is widely used for subword tokenization, but standard BPE exposes every learned merge token to the downstream model, including tokens that mainly serve as intermediate construction units and rarely appear in the final encoded corpus. This paper proposes Pruned BPE, a post-training visibility-pruning and token-reallocation method that separates merge construction from model-visible vocabulary selection. After standard BPE training, tokens are evaluated by final exposure. Low-exposure tokens are retained as internal-only merge nodes, while their visible vocabulary slots are reassigned to better-exposed candidates learned through resumed training. During encoding, internal-only tokens are recursively expanded into visible descendants while the original BPE merge order is preserved. Experiments on two non-overlapping English- and Chinese-dominated corpora and their combination show that Pruned BPE consistently reduces encoded length relative to Standard BPE at the same training corpus, evaluation corpus, and model-visible vocabulary size. At a 40% exposure threshold, the reduction is approximately 0.27%--0.36% on same-corpus evaluations. In a vocabulary-only evaluation using a shared exact minimum-token dynamic-programming encoder, Pruned BPE retains an advantage of approximately 0.23%--0.31%, indicating that the improvement arises from a more efficient visible vocabulary. These gains represent a meaningful fraction of the approximately 1.5%--3.8% marginal reduction that would otherwise require adding another 2K Standard BPE tokens. Qualitative analysis shows that internal-only tokens include reusable English fragments, Chinese components, partial UTF-8 byte sequences, and structured-text fragments. The results indicate that post-training visibility pruning can improve BPE vocabulary efficiency without increasing the vocabulary exposed to the language model.
Kenny Shao
Department of Computer Science Florida International University
Recent work has shown that subword vocabularies can be trained to optimize compression for a specific inference rule rather than relying on greedy heuristics such as Byte Pair Encoding (BPE). We extend this approach to greedy left-to-right longest-match decoding, the fast and widely used inference rule underlying WordPiece. We introduce Joint Optimization for Greedy Longest-Match Tokenization (JOLT), which formulates vocabulary learning as an integer program over vocabulary-selection and segmentation-choice variables. Greedy-consistency constraints ensure that each optimized segmentation exactly matches the segmentation produced by longest-match decoding under the selected vocabulary, aligning the training objective with deployment-time tokenization. To scale the optimization, we solve a linear programming relaxation and selectively introduce higher-order segmentations only for unresolved pretokens. The resulting relaxation is nearly integral: rounded solutions fall within 0.008 - 0.176 % of the LP lower bound on the training scope. The bound also shows that BPE is already within 1 - 2 % of the best achievable compression under greedy longest-match decoding, while JOLT closes 89.6 - 99.4 % of the remaining gap. On held-out validation data across four training scopes and vocabulary sizes of 32,000 and 64,000, JOLT produces up to 0.78 % fewer tokens than BPE, with improvements generally increasing as the training scope grows. These results demonstrate that inference-aligned vocabulary optimization can recover most of the limited compression headroom left by BPE while providing a certificate of near-optimality.
Adhiraj Singh, Deepanshu Mody, Ghina Al Shdaifat +4
Center for Data Science, New York University New York, NY, USA · Kensho Technologies Cambridge, MA, USA