Search arXiv⌕ Search

arXiv · 2610.19139

Online Tokenization with Optimal Delay in Linear Time

Abstract

Tokenization is an essential preprocessing step in almost all large language models (LLMs). One of the most popular frameworks is BPE tokenization, which consists of special token segmentation, pretokenization, and byte-pair encoding (BPE). However, existing algorithms are sequential, with each stage only processing complete output from the previous stage. In order to reduce latency and memory footprints, recent works (Jiang and Gong, ICML 2026) (Li, Yang and Mamouras, ASPLOS 2026) (Mamouras, Li and Yang, PLDI 2026) have initiated the study of online algorithms for subroutines such as pretokenization and BPE with a goal of streaming input to output as the input arrives online. However, the search for efficient online tokenization remains open. In this work, we formalize and resolve online tokenization. We introduce the notion of delay for online tokenization which characterizes the extent to which the algorithm output lags behind the (possibly computationally intractable) optimum. We give a near-linear time algorithm with optimal delay (up to constant factors). We complement this algorithm with a conditional lower bound: unless $\mathbf{P} = \mathbf{NP}$, there is no polynomial time algorithm that beats the delay of our algorithm by more than a constant factor. We implement a practical variant for tokenizers from OpenAI's tiktoken and HuggingFace's tokenizers. We obtain a $7.9\times$-$34.8\times$ latency advantage (measured as time to first token) over tiktoken (as well as the recent gigatoken tokenizer) and our implementation maintains approximately constant memory usage independent of input size. Our implementation also achieves a $2.4\times$-$7.0\times$ improvement in throughput over tiktoken and $15.8\times$-$38.1\times$ over tokenizers.

Explore related subjects

Keep this discovery

Explore connections, maps & timelines

BibTeXRIS

Mina Dalirrooyfard, Christopher Ye. 2026-10-13. Online Tokenization with Optimal Delay in Linear Time. https://arxiv.org/abs/2610.19139

Cite the original work for its findings. Save a collection to share your selection of sources.

KEEP EXPLORING

Related papers

Reweighted Spectral Partitioning Works: A Simple Algorithm for Vertex Separators in Special Graph Classes

We establish that a practical polynomial-time algorithm obtains near-optimal $\frac23$-balanced vertex separators for a number of graph classes, including genus-$g$ graphs, $K_h$-minor-free graphs, and geometric graphs. For many of these classes, our polynomial-time separator bounds improve on previous work. Moreover, unlike previous work, all these separators are produced by a single unified algorithm that has no specialization for the graph class, and this algorithm admits a scalable implementation with good empirical results. Furthermore, our approach is robust to graphs falling just outside these classes, making it appropriate for practical applications like road networks. A key distinction of our approach, compared to previous work, is the disentanglement of our algorithm and its analysis for specific graph classes. Our algorithm is based on a newly improved form of a recent Cheeger-style inequality relating the value of a special semidefinite program to vertex expansion. Our analysis then only has to directly bound the value of this semidefinite program for each graph class, and constructions for these bounds need not be algorithmic. Finally, we obtain several results of independent interest. These include an improved (existential) separator theorem for intersection graphs of $k$-ply $d$-dimensional balls, an improved bound on the Fiedler value of genus-$g$ graphs, and a complete spectral proof of the planar separator theorem.

cs.DS↗

Quality control in sublinear time: a case study via random graphs

Many algorithms are designed to work well on average over inputs. But when such an algorithm is run on an arbitrary input, the question arises: Can we trust the algorithm on this input? This question is especially relevant in network science, where algorithms for theoretical random graph models are often applied to individual real-world networks. We identify a new class of algorithmic problems addressing this, which we call "Quality Control Problems." These problems are specified by a "quality function" $ρ$ and a distribution $D$ such that, with high probability, a sample drawn from $D$ is "high quality," meaning its $ρ$-value is near $1$. The goal is to accept most inputs $x \sim D$ and reject potentially adversarially generated inputs $x$ with $ρ(x)$ far from $1$. In this work, we consider the sublinear version of the quality control problem, where $D \in Δ(\{0,1\}^N)$ and the goal is to solve the $(D,ρ)$-quality problem with $o(N)$ queries and time. As a case study, we consider random graphs, i.e., $D = G_{n,p}$ (and $N = \binom{n}2$), and the $k$-clique count function $ρ_k := C_k(G)/\mathbb{E}_{G' \sim G_{n,p}}[C_k(G')]$, where $C_k(G)$ is the number of $k$-cliques in $G$. In suitable parameter ranges, worst-case approximate $k$-clique counting requires $p^{-Ω(k^2)}$ queries. In contrast, we show that the quality control problem for $G_{n,p}$ (with $n\geq p^{-ck}$ for some constant $c$) with respect to $ρ_k$ can be tested with $p^{-O(k)}$ queries and time, showing quality control is provably superpolynomially more efficient in this setting. More generally, for a motif $H$ of maximum degree $Δ(H)$, we show that the corresponding quality control problem can be solved with $p^{-O(Δ(H))}$ queries and running time.

cs.DS↗

Deterministic Volume Estimation of Truncated Hypercubes

We present a deterministic polynomial-time algorithm for estimating the volume of a hypercube intersected by a fixed number of constraints, where each constraint is the sum of univariate functions that are each nonnegative, monotone, and convex. Such constraints include knapsack and norm-ball constraints. The case of the unit hypercube truncated by a single linear constraint (halfspace) is already #P-hard. Given a fixed number of such constraints in a given dimension, together with an error parameter, our algorithm computes a multiplicative approximation of the volume of their intersection with the unit hypercube in time polynomial in the dimension, reciprocal error, input encoding length, and output encoding length.

cs.DS↗