fix: graph of ascend - #1461
Open
Jingbo-gao wants to merge 4 commits into
Open
Conversation
wooway777
requested changes
Aug 5, 2026
wooway777
left a comment
Collaborator
There was a problem hiding this comment.
之前应该是基于主分支以较少的改动调通过吧。为什么现在突然要这么多额外操作了?
Collaborator
There was a problem hiding this comment.
请参考其他rt方法的声明和分发方式,需要定义统一接口,在其他平台先定义空实现。然后用宏做dispatch。
不然以后这个文件很容易就炸了
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.
PR 内容
修复昇腾后端开启 graph 后,FIA decode 输出异常的问题。
本 PR 基于已有的 Ascend paged FlashAttention decode 实现,补充 FIA在 native graph replay 中的动态参数更新能力,并修复非连续 tensor 的临时contiguous buffer 生命周期不足问题。
Closes #1460
配套 InfiniLM PR:InfiniTensor/InfiniLM#526
问题原因
1.
actualSeqLengthsKv未在 graph replay 时更新FIA V4 的
actualSeqLengthsKv通过 hostaclIntArray传入。普通 nativegraph replay 只会重放已经捕获的 device task,不会根据更新后的 deviceseqlens_ktensor 自动重新构造 hostaclIntArray和 FIA executor。因此,decode 阶段即使更新了 device 序列长度 tensor,FIA 仍可能继续使用 graphcapture 时的 KV 有效长度,导致 Attention 上下文范围错误和输出精度异常。
2. 临时 contiguous buffer 的地址在 replay 时可能失效
原 FIA 实现会在
run()内通过tensor->contiguous()创建临时 tensor。eager模式下 FIA 会在临时 tensor 释放前完成执行,但 graph capture 会记录临时buffer 的 device 地址。当
run()返回后,临时 buffer 可能被释放或复用,后续 graph replay 继续使用捕获时的旧地址,可能造成旧数据读取、错误写入或输出精度异常。主要文件修改
Graph task-update 支持
include/infinicore/graph/graph.hppGraphOperator增加requires_task_update()能力;DispatchableGraphOperator增加 task-update opt-in 标记;src/infinicore/graph/graph.cctask;
infinirt ModelRI 接口
include/infinirt.hinfinirtGraphTaskGroup_t;src/infinirt/infinirt.ccsrc/infinirt/ascend/infinirt_ascend.hsrc/infinirt/ascend/infinirt_ascend.ccAscend FIA graph 更新
src/infinicore/ops/mha_kvcache/mha_kvcache.ccENABLE_ASCEND_FLASH_ATTN且运行设备为 Ascend 时,为MhaKVCache启用 task-update;MhaKVCache行为不变。src/infinicore/ops/mha_kvcache/ascend/mha_kvcache_flashattn_ascend.ccactualSeqLengthsKv;aclnnFusedInferAttentionScoreV4execute 调用;aclIntArray构造和GetWorkspaceSize保持在 task group 外;captured FIA task;
Contiguous Buffer 修复
PlannedMeta新增长生命周期的:处理方式:
PlannedMeta持有,生命周期覆盖整个 Graph;该修改保证 FIA capture 和 replay 始终使用稳定的 device 地址。
执行命令:ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python examples/bench.py --device ascend --model=/data/FM9G_70B_SFT_MHA/ --tp=8 --input-len=32,32 --output-len=256 --batch-size=16 --enable-paged-attn --attn=flash-attn --enable-graph
验证结果:
