arXiv(opens in a new tab)cs.DCOct 2026Cited by 2 papers on PaperVantage

Manuscript Offprint

arXiv:2610.13325

Taking Tokenization off the Host for Agentic LLM Serving

Mohammad Siavashi, Pascal Schwinte, Ali Banaei, Gerald Q. Maguire, Marco Chiesa, Dejan Kostić

ABSTRACT

Agentic workloads resend long contexts that barely change between calls. Prefix caching now skips most of their prefill, yet every request must still be tokenized in full before the cache can even be consulted. Tokenization, a CPU stage long treated as negligible, becomes the largest part of time-to-first-token (TTFT), and a frontend that tokenizes for a whole GPU fleet limits how many GPUs it can feed. We present GRAPHTOK, a GPU tokenizer that runs the entire encoding pipeline, from pre-tokenization through byte-pair encoding (BPE) merging to token-ID assembly, as one replayable CUDA graph. GRAPHTOK reproduces the reference token IDs bit-for-bit on GPT-2, Llama 3, Qwen 2.5, DeepSeek-V3, and Gemma 3, hands short inputs to a CPU engine where the GPU cannot win, and plugs into unmodified vLLM and NVIDIA Dynamo. GRAPHTOK encodes one million GPT-2 tokens in 1.7–3.2 ms including data transfers, and on Llama 3 it is 4.7–6.0× faster than gigatoken, the strongest CPU tokenizer. On TokTier's own single-request benchmark, it is 2.6–3.9× faster than gigatoken and up to 18.1× faster than TokTier. In vLLM with a cached prefix, it lowers mean TTFT by 2.1–2.4×. The largest gain is capacity. Within a 2 s P99 target, one Dynamo frontend with GRAPHTOK sustains 518 requests/s of 121k-token traffic, the busiest-hour load of 56 GPUs, against 296 with gigatoken and 18.5 with the default tokenizer. Across 121k to one million tokens, this is 1.75–2.5× the load gigatoken sustains, with a P99 up to 64× lower where gigatoken's tail breaks.

1 INTRODUCTION

With the rise of Large Language Model (LLM)-powered agents, a growing fraction of LLM serving workloads comes from applications that invoke the model repeatedly. A single coding task, for example, may involve many model calls as an agent reasons, invokes a tool, observes its output, and continues execution. Each call carries forward the accumulated conversation, code, earlier tool calls, and retrieved data, while adding only a small amount of new text. TraceLab's study of roughly 4,300 real coding-agent sessions illustrates this asymmetry: the median model invocation contains about 119K cached-prefix tokens but only 875 newly appended tokens and 214 output tokens, and 95.7% of input tokens are served from the prefix cache (Zhu et al., 2026). Agentic workloads therefore combine long, growing contexts with relatively small updates between consecutive model calls.

Modern LLM serving engines (Kwon et al., 2023; vLLM Team, 2026; Zheng et al., 2024; Qin et al., 2025; NVIDIA, 2026b) exploit this repetition through prefix caching. By reusing the key-value (KV) state of previously processed prefix tokens, they avoid expensive prefill computation over most of the repeated context and reduce time-to-first-token (TTFT). One cost remains, however. The request must still be tokenized before the KV cache can be queried, because

Figure

Figure 1. TTFT breakdown for a cold cache and a prefix-cache hit in unmodified vLLM. The y-axes are broken, and each model has its own scale.

cache lookup requires token IDs. Nor can the suffix simply be appended: appending new text can change the resulting tokenization, so tokenizing only the new suffix and concatenating it with a previously tokenized prefix is not safe in general.

Tokenization nevertheless remains a CPU-side stage in common serving stacks, even though model execution and the KV cache reside on the GPU. This division of work was his-torically reasonable because tokenization was inexpensive compared with prefill. Prefix caching changes the balance: once most prefill work is removed, the previously negligible tokenization stage becomes a significant part of TTFT. Figure 1 shows this effect in unmodified vLLM 0.27 with its CPU tokenizer on one H100 NVL. With a cold cache, tokenization accounts for only 2% of median TTFT for a 130k-token Llama 3.1 8B prompt and 1% for a 40.5k-token Qwen3 32B prompt. After a prefix-cache hit removes most of the prefill, these shares rise to 67% and 49%, respectively, and tokenization becomes the largest remaining component.

Three approaches can reduce this frontend cost. The first adds more CPU tokenizer workers, improving aggregate throughput, but this is expensive, does little for the latency of an individual long request, and competes for CPU cores that retrieval, orchestration, networking, and tool execution also need (Section 2). The second caches previously computed token IDs. This helps for stable prefixes, but because appending text can change the tokenization, NVIDIA Dynamo reuses token IDs only up to safe boundaries, such as completed chat turns, and still tokenizes the remaining text (NVIDIA, 2026b). The third moves tokenization to the GPU. BlockBPE and GPUTOK show that BPE merging can be parallelized on the accelerator (You, 2025; Kadamba & Jaisankar, 2026), but neither reproduces the complete reference-tokenizer pipeline. BlockBPE changes the tokenizer semantics by removing the regular-expression pre-tokenizer, and GPUTOK keeps part of the processing on the host but, in dropping that pre-tokenizer as well, merges pairs that the reference keeps separate (Section 6).

In this paper, we present GRAPHTOK, a GPU tokenizer that executes the complete supported encoding path while preserving the ordered token IDs of the reference tokenizer. GRAPHTOK builds on the observation that both major stages of BPE tokenization contain more parallelism than their reference implementations suggest. Pre-tokenization is usually implemented as a sequential regular-expression scan, yet for the tokenizer families we support, whether a new pre-token begins at a position can be determined from local character classes together with compact run information. Accordingly, GRAPHTOK evaluates these boundaries in parallel across the input. BPE merging exposes a different form of parallelism: within a pre-token the merges are ordered, but the threads of a warp cooperate to identify the next highest-priority merge without changing the reference merge order.

Fast kernels alone do not make a fast tokenizer. A call that completes in a few milliseconds still pays for repeated kernel launches, per-request allocation, and host synchronization between stages. GRAPHTOK therefore captures the complete device-side encoding pipeline, from device-resident raw bytes to the final token IDs, as a single CUDA graph. It separates a fixed graph capacity from the actual work of each request: buffers and launch geometry are provisioned in advance, and counters on the GPU record the live occupancy. The same captured graph can therefore process any request up to its capacity without intermediate allocation, synchronization, or host-side dispatch.

We evaluate GRAPHTOK on an NVIDIA H100 NVL with five production tokenizers, GPT-2, Llama 3, Qwen 2.5, DeepSeek-V3, and Gemma 3. GRAPHTOK produces the same ordered token IDs as the corresponding reference tokenizer in every timed cell of the evaluation campaign (Section 6.2). Depending on the tokenizer, the complete call tokenizes the largest English input, one million GPT-2 tokens, in 1.7–3.2 ms including transfers to and from the GPU. On Llama 3 this is 4.7–6.0× faster than gigatoken, the strongest CPU baseline we measure. On the single-request protocol of TokTier (Zhang & Cao, 2026), a tokenizer developed concurrently and independently, GRAPHTOK is 2.6–3.9× faster than gigatoken with an empty cache and 2.0–18.1× faster than the released TokTier, from 100k to 4.4M characters.

The end-to-end benefit appears when prefix caching exposes the frontend. With a cold cache, replacing vLLM's stock tokenizer improves mean TTFT by only 2–4%, whereas at 99% reuse it improves mean TTFT by 2.1–2.4× for prompts between 32k and 128k tokens. For a single uncontended request in one vLLM engine, however, fast CPU tokenizers come within 4% of GRAPHTOK in mean TTFT, so the distinguishing benefit is frontend CPU and capacity. As a separate process on a model's GPU, GRAPHTOK does not measurably slow inference, and under NVIDIA's Multi-Process Service (MPS) or a fine-grained scheduler it runs on the same streaming multiprocessors (SMs) the inference leaves idle, overlapping it (Section 6).

The capacity benefit materializes in NVIDIA Dynamo, where one frontend tokenizes for a whole GPU fleet. There, GRAPHTOK cuts the tokenization of a 121k-token request from 235 ms to 1.2 ms (mean tokenize-stage time at one GPU's load). We report the sustained load in offered requests/s and, in parentheses, as the number of GPUs whose traffic that rate feeds, at 9.25 requests/s per GPU, BurstGPT's busiest hour (Section 6.9). Within a 2 s P99 target, the default tokenizer lets a frontend sustain 18.5 requests/s (2 GPUs) of 121k-token agentic traffic and 4.6 (0.5) at 512k tokens. TokTier, with its added-token boundary split, sustains 111 (12) and 18.5 (2), and GRAPHTOK sustains 518 (56) and 129.5 (14). This is 1.75× the load the frontend sustains with gigatoken at 121k–512k tokens and 2.5× at one million, and at the load where gigatoken's tail breaks, its P99 is up to 64× higher than that of GRAPHTOK.

Challenges. Turning these observations into a tokenizer that a serving engine can use raises three challenges.

Preserving tokenizer semantics across different families. A production tokenizer does considerably more than execute the BPE merge loop (Section 3), and its preprocessing steps differ between model families, from different regular-expression rules to SentencePiece-style whitespace handling and byte fallback. A GPU implementation therefore cannot simply accelerate one common merge kernel and assume that the surrounding preprocessing is interchangeable. For every supported configuration, GRAPHTOK must parallelize the frontend while preserving the pre-token boundaries, initial symbols, merge order, and final ordered token IDs produced by the reference tokenizer.

Handling input-dependent work inside a fixed CUDA graph. Tokenization is irregular. The number of pre-tokens, their lengths, the number of merges within each one, and the final number of output tokens all depend on the input. A straightforward GPU implementation would discover these quantities at runtime, allocate buffers of matching size, return intermediate counts to the host, and choose subsequent kernels based on those counts. This is a poor fit for CUDA graphs, whose advantage comes from replaying a previously captured execution without such host-side decisions. Uncommon inputs that contain very long pre-tokens complicate the problem further, because they must still be processed correctly rather than rejected. GRAPHTOK must therefore accommodate variable amounts of work within a fixed captured execution.

Making the complete encoding call fast. At millisecond-scale latencies, preprocessing left on the CPU, repeated kernel launches, memory allocation, host-device synchronization, and output assembly can cost as much as the computation itself. Existing serving engines still expect host-visible token IDs for tasks such as request admission and prefix-cache lookup, while future GPU-native consumers may prefer to keep the result on the device. GRAPHTOK must therefore accelerate the complete supported encoding path rather than only the merge operation, and it must support both host-returning and device-resident outputs. It must also account for the fixed cost of GPU execution, which can make a CPU tokenizer preferable for very short inputs.

Contributions. This paper addresses these three challenges with the following contributions.

Exact parallel tokenization across heterogeneous frontends. GRAPHTOK moves the frontend of each supported family, and not only BPE merging, onto the GPU. For each supported configuration, GRAPHTOK parallelizes these operations while preserving pre-token boundaries, merge ordering, and the final ordered token IDs of the reference tokenizer (Section 4).

Graph-resident execution of ragged tokenization. GRAPHTOK separates the fixed capacity of a captured graph from the live occupancy of each request, and an exact overflow path handles unusually long pre-tokens without leaving the captured execution (Section 4).

A complete serving-compatible GPU encoding path. GRAPHTOK executes the supported frontend, BPE merging, and token-ID assembly on the GPU rather than accelerating only the merge kernels. It can either return a conventional host-visible token sequence or expose the result directly on the device. We integrate GRAPHTOK into two serving systems and retain the reference tokenizer as a fallback in both. It enters unmodified vLLM through the tokenizer factory, and it serves NVIDIA Dynamo as a native tokenizer backend of its Rust frontend, selected by one environment variable (Section 5). Our evaluation measures the complete host-returning call, including transfers and output materialization, rather than kernel time alone (Section 6). GRAPHTOK is open source and available at https://github.com/Msiavashi/GraphTok.

References (27)