Skip to content

Reduce state continuation hash allocations - #787

Closed
Ubospica wants to merge 4 commits into
mlc-ai:mainfrom
Ubospica:perf/dense-state-hash
Closed

Ubospica wants to merge 4 commits into
mlc-ai:mainfrom
Ubospica:perf/dense-state-hash

Conversation

@Ubospica

Copy link
Copy Markdown
Collaborator

改动

有限状态机是一种用状态和状态转换表示允许路径的数据结构。编译器会为每个状态计算一个数字摘要,用于识别可复用的等价后续路径。本改动用按状态编号索引的连续数组替代树形映射,并用连续数组充当遍历队列,减少为每个状态反复分配映射节点和队列节点的开销。

本请求依赖 #722 的单状态摘要基础,以及 #781 的整条有限状态机摘要数组。当前分支包含这些前置提交;本请求需要审查的独立提交是 5a85941a

性能

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

输入 编译时间 允许词元集合生成时间
大型结构标签 127.211 -> 110.420 毫秒,减少 13.2% 44.915 -> 45.943 微秒,增加 2.3%
小型结构标签 2.080 -> 1.889 毫秒,减少 9.2% 33.480 -> 35.894 微秒,增加 7.2%
大型 JSON Schema 33.648 -> 27.951 毫秒,减少 16.9% 28.740 -> 29.384 微秒,增加 2.2%
小型 JSON Schema 3.647 -> 2.284 毫秒,减少 37.4% 40.876 -> 41.505 微秒,增加 1.5%

四类输入的编译时间均下降;允许词元集合生成时间有 1.5% 至 7.2% 的回退,改动本身不在生成阶段运行。

正确性

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

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