Closed
[M1客户算子兼容性问题][Bug-Report|缺陷反馈]: ReplaceTensor pass 空指针解引用导致编译期 SIGSEGV(同 buffer 先写后读视图链触发) #3809
李圣贤Add on 18 days agoClosed at 18 days ago
18 days ago Added label: bug-report
18 days ago Assign KaiqiJin as responsible person
18 days ago changed custom priority from 无优先级 to 严重
18 days ago changed custom category from 任务 to 缺陷
李圣贤
18 days ago Comments:
18 days ago Comments:
18 days ago Change title to "[M1客户算子兼容性问题][Bug-Report|缺陷反馈]: ReplaceTensor pass 空指针解引用导致编译期 SIGSEGV(同 buffer 先写后读视图链触发)", originally titled "[客户算子兼容性问题][Bug-Report|缺陷反馈]: ReplaceTensor pass 空指针解引用导致编译期 SIGSEGV(同 buffer 先写后读视图链触发)".
18 days ago Change title to "[M1客户算子兼容性问题][Bug-Report|缺陷反馈]: ReplaceTensor pass 空指针解引用导致编译期 SIGSEGV(同 buffer 先写后读视图链触发)", originally titled "[客户算子兼容性问题][Bug-Report|缺陷反馈]: ReplaceTensor pass 空指针解引用导致编译期 SIGSEGV(同 buffer 先写后读视图链触发)".
李圣贤
18 days ago Comments:
18 days ago Comments:
客户分支compressor算子使用的是9月底的pypto框架代码,可以正常编译通过;切换到主线分支后,segment fault。请重点关注。


18 days ago Modify description of issue
李圣贤
18 days ago Comments:
18 days ago Comments:
18 days ago Assign wangqun23 as responsible person
18 days ago Assign hwwangmingjun as responsible person
18 days ago Removed responsible person KaiqiJin
wangqun23
18 days ago Comments:
18 days ago Comments:
自验证主线已修复。
拉取pypto-gym最新代码,应用patch,并增加精度通过打印信息。
if __name__ == "__main__":
test_csa2_entry_ratio2_prefill()
logger.info("PASS")
print("PASS !!! ")
修复代码未上线前复现问题:
/opt/buildtools/Python-3.11.4/lib/python3.11/site-packages/torch_npu/utils/_path_manager.py:66: UserWarning: Permission mismatch: The owner of /opt/buildtools/Python-3.11.4/lib/python3.11/site-packages/torch_npu/lib/libop_plugin_atb.so does not match.
warnings.warn(f"Permission mismatch: The owner of {path} does not match.")
segment fault !!!
libtile_fwk_interface.so(npu::tile_fwk::Function::IsFromInCast(std::shared_ptr<npu::tile_fwk::LogicalTensor> const&)+0x14) [0xfffec9b3d394]
libtile_fwk_interface.so(npu::tile_fwk::ReplaceTensor::FindBaseTensor(npu::tile_fwk::Function&, std::unordered_map<std::shared_ptr<npu::tile_fwk::LogicalTensor>, int, std::hash<std::shared_ptr<npu::tile_fwk::LogicalTensor> >, std::equal_to<std::shared_ptr<npu::tile_fwk::LogicalTensor> >, std::allocator<std::pair<std::shared_ptr<npu::tile_fwk::LogicalTensor> const, int> > > const&, std::vector<std::shared_ptr<npu::tile_fwk::LogicalTensor>, std::allocator<std::shared_ptr<npu::tile_fwk::LogicalTensor> > >&, std::shared_ptr<npu::tile_fwk::LogicalTensor>&)+0x7c) [0xfffeca92d614]
libtile_fwk_interface.so(npu::tile_fwk::ReplaceTensor::RunOnFunction(npu::tile_fwk::Function&)+0x880) [0xfffeca9381c8]
修复代码上线后:
/opt/buildtools/Python-3.11.4/lib/python3.11/site-packages/torch_npu/utils/_path_manager.py:66: UserWarning: Permission mismatch: The owner of /opt/buildtools/Python-3.11.4/lib/python3.11/site-packages/torch_npu/lib/libop_plugin_atb.so does not match.
warnings.warn(f"Permission mismatch: The owner of {path} does not match.")
PASS !!!


18 days ago changed custom state from 待办的 to 已完成
18 days ago Close issue
4 days ago Added label: Passes
4 days ago Removed responsible person hwwangmingjun
wangqun23
3 days ago Comments:
3 days ago Comments:
修复PR:https://gitcode.com/cann/pypto/pull/7445
修复内容:针对可能导致空指针的map做好前置初始化工作


2 days ago Associated pull request
2 days ago Added label: resolved
Describe the current behavior / 问题描述 (Mandatory / 必填)
报错日志
segment fault !!!
libtile_fwk_interface.so(npu::tile_fwk::Function::IsFromInCast(std::shared_ptrnpu::tile_fwk::LogicalTensor const&)+0x10)
libtile_fwk_interface.so(npu::tile_fwk::ReplaceTensor::FindBaseTensor(...)+0x7c)
libtile_fwk_interface.so(npu::tile_fwk::ReplaceTensor::RunOnFunction(...)+0x40c)
根因
崩溃直接原因:ReplaceTensor 的并查集分组中包含 nullptr LogicalTensor,FindBaseTensor 解引用空指针。
链路:
[ReplaceTensor.Operation] missing-sibling ASSEMBLE[11414] sibling-magic=72 not-in-order-index
[ReplaceTensor.Operation] missing-sibling ASSEMBLE[13096] sibling-magic=69 not-in-order-index
[ReplaceTensor.Tensor] null-curTensor in group size=7, skip
Environment / 环境信息 (Mandatory / 必填)
pypto(框架) 8c2042bfe5ccba2f8676d8d21de7ade5961cedc2(2026-11-09 19:55) 本地复现所用 HEAD,崩溃 100% 复现
pypto-gym(算子) https://gitcode.com/yyyfff/pypto-gym/tree/compressor2 pypto-gym/tests/ops/deepseek_v4_1/test_csa2_compressor.py
CANN Ascend-cann-toolkit_9.3.0~weekly.20261104.01_linux-aarch64 配套 Ascend-cann-A3-ops,设备 Ascend910_9392(A3)
Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)
pypto-gym(算子) https://gitcode.com/yyyfff/pypto-gym/tree/compressor2 pypto-gym/tests/ops/deepseek_v4_1/test_csa2_compressor.py
Describe the expected behavior / 预期结果 (Mandatory / 必填)
7.1 BSH decode
适配前
tok_kv = pypto.view(kv3, [b, 1, d], [0, 0, 0], valid_shape=[b_valid, 1, d])
tok_sc = pypto.view(sc3, [b, 1, d], [0, 0, 0], valid_shape=[b_valid, 1, d])
pypto.set_vec_tile_shapes(16, 1, d)
pypto.assemble(tok_kv, [b_idx * b, slot, 0], kv_state_total)
pypto.assemble(tok_sc, [b_idx * b, slot, 0], score_state_total)
if (start + 1) % ratio < 1:
# 组刚完成: 旧槽 0 + 当前 token (=slot 1) 组成完整组, 手动展开 ratio=2
# 的 softmax 池化 (与原 softmax+dsum 数值路径一致).
st0_kv = pypto.view(kv_state_total, [b, 1, d], [b_idx * b, 0, 0],
valid_shape=[b_valid, 1, d])
st0_sc = pypto.view(score_state_total, [b, 1, d], [b_idx * b, 0, 0],
valid_shape=[b_valid, 1, d])
pypto.set_vec_tile_shapes(4, 1, d) # SWIMLANE: 池化 vec tile 16->4 (4->16 task)
m = pypto.maximum(st0_sc, tok_sc)
...
适配后
tok_kv = pypto.view(kv3, [b, 1, d], [0, 0, 0], valid_shape=[b_valid, 1, d])
tok_sc = pypto.view(sc3, [b, 1, d], [0, 0, 0], valid_shape=[b_valid, 1, d])
# 旧槽 0 的视图必须建在 assemble 之前: 同一 buffer 的"先写后读"视图链会
# 在 ReplaceTensor pass 中把陈旧 rawMagic 兄弟并入同组 (null LogicalTensor
# -> FindBaseTensor 段错误, 见 CI gw6 crash)。槽位不重叠 (池化仅 slot 1 时
# 触发), 提前读旧槽数值等价.
st0_kv = pypto.view(kv_state_total, [b, 1, d], [b_idx * b, 0, 0],
valid_shape=[b_valid, 1, d])
st0_sc = pypto.view(score_state_total, [b, 1, d], [b_idx * b, 0, 0],
valid_shape=[b_valid, 1, d])
pypto.set_vec_tile_shapes(16, 1, d)
pypto.assemble(tok_kv, [b_idx * b, slot, 0], kv_state_total)
pypto.assemble(tok_sc, [b_idx * b, slot, 0], score_state_total)
if (start + 1) % ratio < 1:
# 组刚完成: 旧槽 0 + 当前 token (=slot 1) 组成完整组, 手动展开 ratio=2
# 的 softmax 池化 (与原 softmax+dsum 数值路径一致).
pypto.set_vec_tile_shapes(4, 1, d) # SWIMLANE: 池化 vec tile 16->4 (4->16 task)
m = pypto.maximum(st0_sc, tok_sc)
...
7.2 TH decode
适配前
tok_kv = pypto.view(kv3, [b, 1, d], [0, 0, 0], valid_shape=[b_valid, 1, d])
tok_sc = pypto.view(sc3, [b, 1, d], [0, 0, 0], valid_shape=[b_valid, 1, d])
pypto.set_vec_tile_shapes(16, 1, d)
pypto.assemble(tok_kv, [b_idx * b, slot, 0], kv_state_total)
pypto.assemble(tok_sc, [b_idx * b, slot, 0], score_state_total)
if (start + 1) % ratio < 1:
# 组刚完成: 旧槽 0 + 当前 token 两槽 softmax 池化
st0_kv = pypto.view(kv_state_total, [b, 1, d], [b_idx * b, 0, 0],
valid_shape=[b_valid, 1, d])
st0_sc = pypto.view(score_state_total, [b, 1, d], [b_idx * b, 0, 0],
valid_shape=[b_valid, 1, d])
pypto.set_vec_tile_shapes(4, 1, d)
m = pypto.maximum(st0_sc, tok_sc)
...
适配后
tok_kv = pypto.view(kv3, [b, 1, d], [0, 0, 0], valid_shape=[b_valid, 1, d])
tok_sc = pypto.view(sc3, [b, 1, d], [0, 0, 0], valid_shape=[b_valid, 1, d])
# 旧槽 0 的视图必须建在 assemble 之前 (同 BSH decode: 避免同 buffer
# 先写后读视图链触发 ReplaceTensor pass 的 null 分组段错误).
st0_kv = pypto.view(kv_state_total, [b, 1, d], [b_idx * b, 0, 0],
valid_shape=[b_valid, 1, d])
st0_sc = pypto.view(score_state_total, [b, 1, d], [b_idx * b, 0, 0],
valid_shape=[b_valid, 1, d])
pypto.set_vec_tile_shapes(16, 1, d)
pypto.assemble(tok_kv, [b_idx * b, slot, 0], kv_state_total)
pypto.assemble(tok_sc, [b_idx * b, slot, 0], score_state_total)
if (start + 1) % ratio < 1:
# 组刚完成: 旧槽 0 + 当前 token 两槽 softmax 池化
pypto.set_vec_tile_shapes(4, 1, d)
m = pypto.maximum(st0_sc, tok_sc)
适配前的代码正常编译通过,精度正确
Related log / screenshot / 日志 / 截图 (Mandatory / 必填)
segment fault !!!
libtile_fwk_interface.so(npu::tile_fwk::Function::IsFromInCast(std::shared_ptrnpu::tile_fwk::LogicalTensor const&)+0x10)
libtile_fwk_interface.so(npu::tile_fwk::ReplaceTensor::FindBaseTensor(...)+0x7c)
libtile_fwk_interface.so(npu::tile_fwk::ReplaceTensor::RunOnFunction(...)+0x40c)
Special notes for this issue/备注 (Optional / 选填)
当前先以规避方式上库,需要复现时,请参考适配前的代码进行复现。
复现patch:见下方