Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
长 prompt 的采样路径超过 Python 递归上限时,cache-aware PD 选点的插入和匹配会抛出
RecursionError。本次改为压缩 radix tree,同时消除选点与命中信息查询之间的重复匹配。长边整体存储与比较,在分叉或插入终点拆分;整条路径刷新后合并不再需要的单子边,避免多轮聊天追加内容形成长节点链。容量仍按采样字符数计算,保留字符级叶到根 LRU 顺序,驱逐时可以裁剪叶边。每次插入只取一次时间戳。选点返回 worker 和同一次匹配生成的命中信息,负载均衡改派后仍返回零命中率,不共享跨请求的匹配状态。
单字符边直接复用 children 查找的匹配结果,跳过通用前缀比较;输入 key 长度在循环外计算,避免高分支密度下压缩树退化为单字符链时的额外开销。
最新提交
b88fc7c3a的正确性复测(两个 sub-agent 独立执行正确性与性能验证):单字符快速路径 CPU A/B/C(
b88fc7c3a):基线为
d6a34eb,涉及的三个 selector 文件与upstream/main 3d9415f44完全一致;修复前为3d902a7。Intel Xeon Platinum 8568Y+、Python 3.12.9、默认sample_stride=512,固定同一 CPU,3 轮预热后交错测量 7 轮取中位数;通过exp保存源码哈希、补丁和结果。使用真实select_p_d_node()、4 个模拟 prefill worker,保留日志格式化但关闭输出。以下通过公开插入接口构造每个采样点都有分叉的边界树形;恰好一个 worker 空闲,旧版和新版都只匹配一次:
该场景相对 upstream 的性能退化已消除。高分支密度和第三采样字符失配的 16 个完整 selector 场景,选中 worker 与估算命中率在三组实现中一致。另有 16 个完整 selector 场景覆盖单压缩边完整匹配和根失配。36 个树微基准同时覆盖短串、长压缩边、根失配、浅失配、深失配、碎片化树和重插入。
快速路径判断在部分长压缩边匹配微基准中增加约 0.03–0.10 µs;原有浅失配相对 upstream 的小幅开销仍存在,不能据此声称所有树形和请求均更快。
以下常规路径数据采集于
3d902a7,保留作为压缩 radix tree 与单次匹配复用的初始测量;本次快速路径的三组对照见上表。速度基线为上述
upstream/main 3d9415f44,不是 PR 原来的迭代版本。Intel Xeon Platinum 8568Y+、Python 3.12.9、sample_stride=512,固定 CPU,3 轮预热后交错测量 9 轮取中位数;所有实验通过exp记录。完整 CPU 选点使用真实
LoadBalancedCacheAwareSelector.select_p_d_node和 4 个模拟 prefill worker,包含 decode 加权抽样与命中信息生成。两边关闭日志输出,保留字符串格式化成本。下表为 ASCII prompt 的 upstream/本次实现耗时倍率:1,536,000 字符空闲场景从 878.30 µs 降至 9.36 µs,全忙场景从 881.88 µs 降至 11.91 µs。
单路径前缀树微基准,524,288 字符 / 1,024 个采样字符:
64 条随机分支、共享前 16 个采样字符、每条深度 1,024 时,新分支插入快 104×,重插入快 79.9×,完整匹配快 25×,半深度匹配快 8.6×。逻辑采样字符数同为 64,528,实体节点从 64,528 降至 65;
tracemalloc测得树的保留内存从 20,654,896 B 降至 160,049 B,约减少 129×,输入文本不计入。256 轮追加式聊天,每轮追加 4 个采样字符并执行插入和匹配,末轮为 524,288 字符:总耗时从 87.640 ms 降至 2.303 ms,快 38.1×,最终保持一个压缩边。5,000 个采样字符的路径在 upstream 默认递归上限 4,000 下插入失败,本次实现插入与匹配成功。
仅命中第一个采样字符的浅匹配仍有约 0.14–0.25 µs 回退,根未命中基本持平。微基准计时不含建树准备,计时期间关闭 GC;较大的倍率来自消除逐字符 Python 节点操作,不能换算为服务吞吐或 GPU 推理提速。