Authors: Craig W. Schmidt, Chris Tanner, Yuval Pinter
Organizations: Kensho Technologies, Cambridge, MA 02138, USA · MIT, Cambridge, MA, USA · Institute for Applied AI Research, Ben-Gurion University of the Negev, Beer Sheva 8410501, Israel
Byte Pair Encoding (BPE) is a widely used tokenization algorithm, whose tokens cannot extend across pre-tokenization boundaries, functionally limiting it to representing at most full words. The BoundlessBPE and SuperBPE algorithms extend and improve BPE by relaxing this limitation and allowing the formation of superwords, which are combinations of pretokens that form phrases. However, previous implementations were impractical to train: for example, BoundlessBPE took 4.7 CPU days to train on 1GB of data. We show that supermerge candidates, two or more consecutive pretokens eligible to form a supermerge, can be aggregated by frequency much like regular pretokens. This avoids keeping full documents in memory, as the original implementations of BoundlessBPE and SuperBPE required, leading to a significant training speedup. We present a two-phase formulation of BoundlessBPE that separates first-phase learning of regular merges from second-phase learning of supermerges, producing identical results to the original implementation. We also show a near-equivalence between two-phase BoundlessBPE and SuperBPE, with the difference being that a manually selected hyperparameter used in SuperBPE can be automatically determined in the second phase of BoundlessBPE. These changes enable a much faster implementation, allowing training on that same 1GB of data in 603 and 593 seconds for BoundlessBPE and SuperBPE, respectively, a more than 600x increase in speed. For each of BoundlessBPE, SuperBPE, and BPE, we open-source both a reference Python implementation and a fast Rust implementation.
Figures & tables
Figure 1: Illustrative example of the aggregation process using a hand-constructed vocabulary. Light gray indicates pretokens that are either composed of multiple tokens or do not include a letter, rendering them ineligible for supermerges. Red indicates supermerge candidates, and purple, green, and blue indicate greedy splits of some candidates.
Figure 2: Unique and total counts versus the number of MiniPile documents, for BPE pretokens and for BoundlessBPE/SuperBPE supermerge candidates.
Figure 3: Comparison of original BoundlessBPE, two-phase BoundlessBPE, and SuperBPE. The original BoundlessBPE (left) performs ordinary merges and supermerges simultaneously. The two-phase approach (right) decomposes this into stages. In Phase 1, the input is pre-tokenized, a standard BPE model is trained, and supermerge candidates are identified via an aggregation procedure ( Section 2 ). BoundlessBPE and SuperBPE follow the same Phase 1 process but differ in the number of BPE merges performed: BoundlessBPE trains to the full vocabulary size, while SuperBPE reserves s merges for supermerges. In Phase 2, BoundlessBPE uses Algorithm 1 to dynamically determine how many merges are ordinary versus supermerges, while SuperBPE selects a fixed number of s supermerges.
Figure 4
Figure 6: Average training time for BPE and BoundlessBPE (including both phases) over 3 runs vs. vocabulary size for 1M documents. Error bars give min/max values over the 3 runs. SuperBPE results are similar.
Figure 7: The left plot gives the inference time for BoundlessBPE vs. number of documents, both with and without the shortcut in Rust and Python. The right plot shows the time overhead of using BoundlessBPE vs. the first-phase word BPE. The shortcut provides a bigger boost to BPE than BoundlessBPE since the supermerge stage doesn’t directly benefit. A “matching” SuperBPE model has the same merges as BoundlessBPE, so its inference times would be identical.
Appendix figures & tables5 assets
Supplementary material from the paper’s appendix.
Appendix
#
Matches
Input
Output
1
Optional space or punctuation, optional upper or uncased letters followed by one or more lowercase letters. Breaks before an uppercase letter that follows a lowercase one. Keeps trailing modifiers (accents).
' Hello world'
[[' Hello'],[' world']]
' camelCase'
[[' camel'],['Case']]
'FOObar'
[['FOObar']]
'(can't'
[['(can't']]
'café'
[['café']]
' 你好 '
[[' 你好 ']]
Appendix
Table 1: Behavior of each branch of GPT4O_REGEX ( Figure 8 ). The seven alternatives are tried in order; the first to match at the current position wins.
Figure 11: Type-token ratio (unique/total) by language for first-phase pretokens, second-phase supermerge candidates, and greedy-split candidates. Space-delimited scripts (EN→DE) present three calculations while non-space-delimited ones (KM→ZH) have an additional dark blue bar showing the first-phase ratio under the default GPT-4o regex. All results use 100K documents per language from CulturaX.
Figure 12: The merge counts of the selected supermerges for a BoundlessBPE run on 1M documents and a vocabulary size of 131,072, along with counts with the greedy splitting heuristic. The merge counts without the greedy split represent the number of merges that can actually be performed. Because of overestimated counts later in the merges, there were 50,832 supermerges selected with greedy splitting compared to 46,124 without.
Figure 13: Time vs. vocabulary size using the original BoundlessBPE implementation, for various numbers of documents. A linear fit of the data works well, and allows an extrapolation of the final time for 100K and 200K documents.
Pre-tokenization
Merge
Total
Method
Docs
Py
Rust
×
Py
Rust
×
Py
Rust
×
BPE
10K
11
6
1.7 ×
43
8
5.0 ×
62
18
3.4 ×
20K
23
13
1.8 ×
62
14
4.3 ×
94
31
3.0 ×
50K
59
35
1.7 ×
104
26
4.1 ×
173
65
2.7 ×
100K
118
69
1.7 ×
154
40
3.8 ×
284
115
2.5 ×
200K
234
141
1.7 ×
235
65
3.6 ×
484
212
2.3 ×
Appendix
Table 2: Training time comparison: Python vs. Rust implementation (seconds), averaged over 3 runs. Total includes all components; pre-tokenization and merge are shown separately.
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
Pre-training of Large Language Models is often prohibitively expensive and inefficient at scale, requiring complex and invasive modifications in order to achieve high data throughput. In this work, we present Token-Superposition Training (TST), a simple drop-in method that significantly improves the data throughput per FLOPs during pre-training without modifying the parallelism, optimizer, tokenizer, data, or model architecture. TST is done in two phases: (i) A highly efficient superposition phase where we combine many contiguous tokens into one bag and train using a multi-hot cross-entropy (MCE) objective, and (ii) a recovery phase where we revert back to standard training. We extensively evaluate TST on the scale of 270M and 600M parameters and validate on 3B and a 10B A1B mixture of experts model, demonstrating that it is highly robust in different settings. Ultimately, TST consistently outperforms baseline loss and downstream evaluations, and under equal-loss settings, TST yields up to a 2.5x reduction in total pre-training time at the 10B A1B scale.