Skip to content

[Core:Bugfix] 修复循环子模块输入复制缓存未刷新导致的 CIF 错误 - #5014

Merged
wangzhaode merged 1 commit into
alibaba:masterfrom
vklonghml:feature/seaco-cif-shapes
Oct 23, 2026
Merged

wangzhaode merged 1 commit into
alibaba:masterfrom
vklonghml:feature/seaco-cif-shapes

Conversation

@vklonghml

Copy link
Copy Markdown
Contributor

问题

在 ARM64 CPU 的 low 精度模式下,SeACoParaformer 完整图对相同音频连续推理时,第一轮正常,第二轮 CIF 输出帧数可能从 14 变为 11,随后 decoder 报 Broad cast error, dim1 = 14, dim2 = 11。

定位到 CIF 循环内部:累计权重为 0.994140625 时,比较算子正确输出条件 0,但后续 Select 的后端输入副本仍为上一轮的 1,导致错误减去 1。encoder 和 predictor 两轮输出一致。

StaticModule::_resize 原来仅在输入 Tensor* 地址变化时将输入复制缓存标脏。同一输入对象内容更新,或循环临时对象释放后地址被复用,都不能通过地址比较可靠地检测。顶层 NetModule 每轮 clearCache() 掩盖了简单独立调用中的问题,而 WhileModule 连续调用内部子模块时会触发。

修改

  • 每次带输入的子模块 forward 都将输入复制缓存标脏,保证后端副本读取当前内容;继续复用缓存内存,不强制整图 resize。
  • 新增 expr/ModuleInputCopyRefresh:构造 Select(condition, 2, 3),模拟循环直接连续调用内部子模块,对同一输入对象交替写入 0/1,检查输出交替为 3/2。用固定对象复现,避免测试依赖分配器偶然复用地址。

验证

基于 master d662ce36175956038cfd6ed13f84cb3343a287d2,启用 ARM82、LOW_MEMORY、TRANSFORMER_FUSE 和 MNN 线程池;实际模型测试未开启 Session_Debug。

  • 新增用例:未修复 low 失败、normal 通过;修复后 normal/low 均通过。
  • expr/ModuleInputCopyRefresh、expr/ModuleShapeInfer、op/select、op/binary:normal/low 合计 90 次测试全部通过。
  • 完整图两段音频、每轮热词编码/缓存热词三组 low 场景:未修复均在重复调用时失败,修复后每组连续 6 次通过;normal 对照也通过。两段输入分别保持 14、25 个 token,相同输入的 token IDs 逐轮一致,检查的输出均为有限值。
  • 固定音频扩展到 1/4 线程、normal/low,每组连续 10 次均通过。

单测命令:

./run_test.out expr/ModuleInputCopyRefresh 0 2 4
./run_test.out expr/ModuleShapeInfer 0 2 4
./run_test.out op/select 0 2 4
./run_test.out op/binary 0 2 4
# 将 precision 参数 2 换为 0,重复 normal 对照。

与已有修复的关系

本问题是输入内容变化但复制副本未更新,与 #4974 的 shape 输入内容缓存、#5006 的输入布局变化缓存失效不同。实际应用 #4974,或同时应用 #4974/#5006,均不能解决原始 CIF 重复调用失败。

本 PR 单独应用后,交替不同长度音频仍会遇到已有的 encoder 动态形状问题(94/132 帧,normal 也触发)。与 #4974 组合后,1/4 线程 × normal/low × 固定/交替长度共 8 组、80 次推理全部通过,相同音频的帧数、token 数和 token IDs 保持一致。本 PR 不重复纳入 #4974 的修改。

@CLAassistant

CLAassistant commented Oct 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@vklonghml
vklonghml force-pushed the feature/seaco-cif-shapes branch from 092454d to ec3dd6a Compare October 21, 2026 09:56
@wangzhaode wangzhaode added the type:bug 功能缺陷 label Oct 22, 2026
@wangzhaode wangzhaode self-assigned this Oct 22, 2026
@wangzhaode
wangzhaode merged commit 97715f8 into alibaba:master Oct 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug 功能缺陷

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants