We propose a novel algorithm for incremental Byte Pair Encoding (BPE) tokenization. The algorithm processes each input byte in worst-case $\mathcal{O}(\log^2 t)$ time, leading to an overall complexity of $\mathcal{O}(n \log^2 t)$, 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 ${\sim}3\times$ 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


翻译:我们提出了一种新颖的增量字节对编码(BPE)分词算法。该算法以最坏情况下的$\mathcal{O}(\log^2 t)$时间处理每个输入字节,从而在输入长度为$n$且最大分词长度为$t$时,总体复杂度为$\mathcal{O}(n \log^2 t)$。该算法增量式地维护输入文本每个前缀的BPE分词结果,实现了由固定合并规则集定义的标准BPE合并过程。这使得在流式处理场景中能够实现高效部分分词。作为标准BPE的即插即用替代方案,我们的方法相比Hugging Face的分词器实现了高达${\sim}3$倍的加速,并在病态输入上相比OpenAI的tiktoken展现出显著的延迟降低。我们进一步引入了一种急迫输出算法,能够在增量分词过程中一旦确定分词边界便即时输出分词结果,从而实现流式输出。总体而言,我们的结果表明,BPE分词可以在具有强最坏情况保证的情况下增量执行,同时为现代大语言模型流水线提供实际延迟收益。代码:https://github.com/ModelTC/mtc-inc-bpe

0
下载
关闭预览

相关内容

将一个汉字序列切分成一个一个单独的词
【CVPR2023】基础模型驱动弱增量学习的语义分割
专知会员服务
18+阅读 · 2023年3月2日
《分布式多智能体强化学习的编码》加州大学等
专知会员服务
56+阅读 · 2022年11月2日
推荐系统算法合集,满满都是干货(建议收藏)
七月在线实验室
17+阅读 · 2018年7月23日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
VIP会员
最新内容
学习数据的几何:形状空间分析数学综述
专知会员服务
6+阅读 · 6月17日
定向能反无人机系统最新发展动态
专知会员服务
7+阅读 · 6月17日
从燃煤战舰到算法战争:水面指挥的永恒要求
专知会员服务
4+阅读 · 6月17日
相关VIP内容
【CVPR2023】基础模型驱动弱增量学习的语义分割
专知会员服务
18+阅读 · 2023年3月2日
《分布式多智能体强化学习的编码》加州大学等
专知会员服务
56+阅读 · 2022年11月2日
相关基金
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
Top
微信扫码咨询专知VIP会员