[Paper Review] GPUTOK: GPU Accelerated Byte Level BPE Tokenization
GPUTOK implements a GPT-2-compatible, GPU-based byte-level BPE tokenizer that preserves greedy merges while delivering substantial speedups over CPU tokenizers for long sequences.
As large language models move toward million-token context windows, CPU tokenizers become a major slowdown because they process text one step at a time while powerful GPUs sit unused. We built a GPU-based byte-level BPE tokenizer that follows GPT-2's merge rules. It includes a basic BlockBPE-style kernel and a faster, optimized version that uses cuCollections static map, CUB reductions, and a pybind11 interface for Python. On WikiText103 sequences up to 131k tokens, the optimized GPU tokenizer produces the same tokens as a CPU version and, for the longest inputs, is about 1.7x faster than tiktoken and about 7.6x faster than the HuggingFace GPT-2 tokenizer. Nsight profiling shows that 70-80% of CUDA API time goes to memory allocation, so adding memory pooling should give the biggest speed boost next. Tests on generation tasks using WikiText103 prompts show that our GPU tokenizer's outputs stay within about one percentage point of tiktoken and HuggingFace GPT-2 on similarity and overlap metrics, meaning it keeps output quality while making long-context inference more practical.
Motivation & Objective
- Motivate the need for GPU-based tokenization to reduce latency in long-context LLM inference.
- Describe a GPU-oriented design for GPT-2 style byte-level BPE that preserves greedy merges.
- Provide a Python-friendly interface and open-source implementation for integration with PyTorch serving stacks.
- Benchmark performance and correctness against CPU-based tokenizers and baseline GPU approaches.
Proposed method
- Reconstruct GPT-2 byte encoder on the CPU and map bytes to GPT-2 style symbols.
- Store the GPT-2 merge vocabulary on the GPU using cuCollections static_map for fast lookups.
- Implement two CUDA kernels (baseline and optimized) that perform greedy BPE merges per sequence within a single CUDA block.
- Use a double-buffered, memory-efficient compaction scheme to update token sequences after each merge.
- Expose a pybind11 Python API to run tokenization on batches of strings and report kernel timing alongside results.

Experimental results
Research questions
- RQ1Can a GPU-resident, GPT-2 compatible BPE tokenizer reproduce CPU reference merges exactly?
- RQ2What performance gains are achievable for long sequences (e.g., up to 131k tokens) when tokenization is moved to the GPU?
- RQ3How do kernel design choices (baseline versus optimized compaction) affect throughput and latency?
- RQ4What is the impact of memory allocation overhead on GPU tokenization, and can memory pooling meaningfully reduce it?
- RQ5Does the GPU tokenizer maintain token-level correctness and downstream generation quality comparable to CPU baselines?
Key findings
- The optimized GPU kernel is about 1.7x faster than tiktoken and over 7x faster than HuggingFace GPT-2 tokenizer on 131k token sequences.
- GPU tokenization matches the CPU reference token sequences for WikiText103-scale inputs, indicating exact greedy merge semantics.
- On long inputs, GPU tokenization outperforms CPU-based tokenizers in end-to-end latency and throughput.
- Profiling shows 70–80% of CUDA API time is spent in memory allocation, suggesting memory pooling as a major future speedup.
- Generation similarity tests show outputs stay within about one percentage point of CPU-based tokenizers in overlap metrics.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.