14 Commits
Author SHA1 Message Date
Lu Fan(SonnyCalcr) 649747f8cd feat(server): 神经网络整句效果优先模型改为按需下载 (#838)
效果优先模型(sentence-model-desktop.safetensors,约 25 MB)不再随安装包分发,
改为和八股文模型一样在设置页下载后才能使用。

- engine:SentenceAssociationOptions 新增 neural_desktop_model 路径,留空即模型缺席、
  静默不重排;词典不再从资源目录固定加载效果档。load_file 按 UTF-8 打开路径,
  数据目录在非 ASCII 用户目录下也能读到模型
- server:新增 settings/neural_model,下载到 <数据目录>\models\neural-desktop\,
  下载与导入都按 neural-model/lock.json 的字节数和 SHA256 校验后原子落位;
  会话层只在开关打开时解析模型路径
- ui-html:设置页增加下载 / 导入 / 删除 / 浏览器下载,模型未就绪时开关置灰
- installer:不再打包效果档模型;旧版装进数据目录根下的那份在覆盖安装与卸载时清掉

原有配置项 sentence_neural_desktop 保持不变,用户的开关状态升级后保留。
2026-10-11 18:08:33 +08:00
luojiyin ecbc932009 perf(engine): reuse int8 weights across eight rows 2026-10-06 09:24:24 +08:00
luojiyin 7e2d9990a5 perf(engine): use AVX2 for vocabulary projection
Pack active hidden rows before the tied vocabulary projection.

Reuse the existing int8 AVX2 kernel when the CPU supports it.
Keep the original scalar path for other CPUs and float weights.
The projection and complete scoring both run faster with locked models.
2026-10-04 16:16:30 +08:00
Jia Sui 7d83aed411 docs(engine): 说明 wake 谓词依赖的跨表不变量
wake_ 的谓词按模型判空槽、不比键,成立的前提是 pending_ 与 active_keys_ 不可能
同时持有同一个模型:待办是在 worker 取走的那一刻才从表里 erase 的,在那之前同一
模型的键只挂在 active_keys_ 上。

这个不变量此前没有文字说明。谁哪天在 order_for 里改成「在算的也照样排一份」
(在 42aeda08 之前看着像无害的加固),谓词会把正在算的那批重排一遍——正是该字段
引入前要消灭的重复计算。纯注释,行为不变。
2026-10-04 03:45:53 +08:00
Jia Sui 7a8b441509 fix(engine): RescoreWorker 不再丢弃更新的重排请求
active 分支命中时(同一批正在算)原先会顺手清掉该模型的 pending_ 待办,
理由是「排在它后面的旧待办没人要了」。这个前提不成立:

- 模型 M 正在算 K1,用户继续打字把 K2 排进 pending_
- K1 算完写 done_ 并回调重查;若重查赶在工作线程擦 active_keys_ 之前,
  且 done_ 刚被 kMaxResults 重置清空过,done_.find 未命中就落进 active 分支
- K2 被静默抹掉,而本次调用拿到 nullopt、也不会有回调

失败模式是那次重排永久缺失,不是延迟。active 分支只表达「这批正在算,
别重复排」,两件事拆开;pending_ 本就按模型只留一格、下次 order_for 直接覆盖。
2026-10-04 03:45:53 +08:00
luo jiyin 9a22905fb7 perf(engine): add blocked AVX2 int8 linear kernel (#608)
Reuse each widened weight chunk across up to four activation rows.

Use a scalar path when the CPU lacks AVX2 or FMA.
The blocked kernel reduces scoring time for both locked models.
Keep a focused test for row blocks, input tails, and optional bias.
2026-10-04 00:06:38 +08:00
luojiyin 895d637300 perf(engine): reuse neural forward buffers
Reuse temporary vectors across Transformer blocks within one forward call.

The keyboard model uses 76 allocations per scoring call, down from 135.
The desktop model uses 76 allocations per scoring call, down from 157.
Scores match the original implementation for both models.
2026-10-03 21:35:12 +08:00
luo jiyin 136d440517 Merge branch 'develop' into perf/neural-skip-padding 2026-10-03 17:05:48 +08:00
luojiyin 1b5e7a71e4 refactor(engine): name compact logit slots
Use slot for compact logits and row for Transformer positions.
2026-10-03 16:40:00 +08:00
luojiyin 1acc3d6745 perf(engine): skip unused neural scoring positions
Skip vocabulary projection for positions without targets.

Remove the final unused Transformer position from each candidate row.

Add coverage for empty candidates in mixed batches. Refs #593.
2026-10-03 16:40:00 +08:00
fanlusky b8ceeef7f9 fix(engine): 重查时不再重复排正在打分的同一批候选
回调触发的重查会问到刚被后台取走、还没算完的那一批:结果表里没有,待办位也空着,
于是同一批又排了一份。用户连续打字时每个回调都可能白算一次;benchmark 里这份重复
任务会在 clear() 之后写回结果,让下一轮误报 neural_already_visible 或把等待计入
async_ms。

按模型记下正在算的键,同键请求直接返回并丢掉该模型更旧的待办。
2026-10-03 16:35:48 +08:00
Jia Sui 5d8487a490 fix(engine): 别让重排后台线程的异常把输入法带走
Signed-off-by: Jia Sui <jsfaint@gmail.com>
2026-09-30 22:08:23 +08:00
fanlusky e365a8d1b5 perf(engine): 大模型改为只读映射并按需载入,缩短每键查询路径
- sc.lm 改用 kenlm 的 LAZY 载入:Windows 上默认的 POPULATE_OR_READ 会退成 READ,
  把 33 MB 整份拷进私有堆且永不释放;现在是 MapViewOfFile 只读映射,可被系统回收
- dict_japanese.dat 在 Windows 上同样改为只读映射,与 POSIX 分支一致
- 神经整句模型改为开关首次生效时才载入(LazySentenceModel),默认关闭的桌面模型
  不再占用约 24 MB
- 新增 reset_sentence_cache():重排结果与上文只影响词格整句,只清 series 一层,
  逐前缀查库与切分缓存保持热;set_rescoring_context 也改用它
- CircularBuffer 新增 find():命中时返回指针而不复制整份候选列表,并改为真正的 LRU;
  全拼、双拼每键的命中路径改用它
- Google 解码器去掉每次调用前的 im_reset_search,沿用上游的公共前缀增量搜索
- 测试:出货 sc.lm 能映射载入并正常打分;增量搜索与从头搜结果逐步一致
2026-09-30 19:58:18 +08:00
fanlusky e7f7addd4f feat(engine): 神经网络整句联想与词格 n-best 重排
- 新增 engine/neural:移植 chinese-ime-lm 的字符级 Transformer 推理,在词格解出的最多 12 条
  n-best 里重排挑选整句,desktop / keyboard 两档模型各出一条首选,后台 worker 异步打分
- 词格支持 n-best 输出与重排(quanpin/lattice_rerank),全拼、双拼共用
- 新增 SentenceAssociationOptions,经 QueryRequest 传给各 provider;四个来源默认全关
- 资源契约登记两个 safetensors 与 NOTICE;模型二进制不进仓库,由
  scripts/fetch-neural-model.ps1 按 neural-model/lock.json 下载并校验 SHA256
- 新增 neural_sentence 测试
2026-09-24 14:03:39 +08:00