Skip to content

Reuse first-byte vocabulary buckets - #786

Closed
Ubospica wants to merge 3 commits into
mlc-ai:mainfrom
Ubospica:perf/first-byte-vocab-buckets
Closed

Ubospica wants to merge 3 commits into
mlc-ai:mainfrom
Ubospica:perf/first-byte-vocab-buckets

Conversation

@Ubospica

Copy link
Copy Markdown
Collaborator

改动

词元是模型一次处理的文本单位。生成允许词元集合时,编译器会多次按词元首字节扫描已经排序的词表。本改动在编译器建立时一次性计算 256 个首字节各自对应的词表范围和最长后缀长度,后续所有语法共享这些只读结果,避免重复扫描。

本请求依赖 #722 提供的词元前缀批量处理与结果缓存。本分支中的前两个提交属于 #722;本请求需要审查的独立提交是 2a0ffedd

性能

结构标签是把触发文本、函数参数规则和结束文本组合起来的生成约束。JSON Schema 是描述 JSON 数据结构及字段约束的规则。允许词元集合生成时间是生成每一步筛选合法词元所需的平均时间。

输入 编译时间 允许词元集合生成时间
大型结构标签 278.897 -> 278.738 毫秒,减少 0.1% 37.495 -> 31.460 微秒,减少 16.1%
小型结构标签 1.513 -> 1.521 毫秒,增加 0.6% 28.799 -> 22.679 微秒,减少 21.3%
大型 JSON Schema 30.074 -> 30.250 毫秒,增加 0.6% 25.523 -> 19.682 微秒,减少 22.9%
小型 JSON Schema 2.817 -> 2.808 毫秒,减少 0.3% 32.637 -> 28.827 微秒,减少 11.7%

四类输入的允许词元集合生成均有明确收益;编译时间变化均小于 1%。

正确性

  • 四类正式输入中,优化前后接受行为差异为 0。
  • 使用严格警告检查完成发布构建。
  • 从构建产物进行不可编辑安装后,编译器和语法匹配器测试 57 项通过,18 项因需要额外模型词表而未执行。
  • 提交前格式检查全部通过。

Copilot AI review requested due to automatic review settings July 30, 2026 15:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants