perf: optimize causal conv1d and mega chunk gdn for qwen3.5.#15
Open
Sinle4Cat wants to merge 1 commit into
Open
perf: optimize causal conv1d and mega chunk gdn for qwen3.5.#15Sinle4Cat wants to merge 1 commit into
Sinle4Cat wants to merge 1 commit into
Conversation
Sinle4Cat
force-pushed
the
prefill_opt_conv1d_gdn
branch
from
July 16, 2026 02:37
38497ca to
26a0b26
Compare
Sinle4Cat
marked this pull request as draft
July 16, 2026 02:53
Sinle4Cat
force-pushed
the
prefill_opt_conv1d_gdn
branch
from
July 16, 2026 04:04
26a0b26 to
7b3191d
Compare
Sinle4Cat
force-pushed
the
prefill_opt_conv1d_gdn
branch
from
July 16, 2026 08:43
7b3191d to
d9ce99c
Compare
Sinle4Cat
marked this pull request as ready for review
July 18, 2026 01:20
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.
背景
Qwen3.5 LinearAttention 的 prefill 路径原先包含以下数据处理:
这些独立算子增加了 kernel launch、GM 读写和 BF16/FP16 转换开销。
本 PR 对该路径进行两项优化:
CausalConv1dQkv,直接产生 MegaChunkGdn 所需的 packed Q/K/V。MegaChunkGdn增加完整 BF16 specialization。优化后数据流
Conv cache 的更新语义保持不变。
CausalConv1dQkv
新增完整 ACLNN 自定义算子,包括:
算子复用现有 CausalConv1d kernel,通过新增
activationMode=2启用 packed-QKV 路径,不维护重复的 Conv 实现。Kernel 内完成:
Q/K 以
headDim=128分 head 计算:输出物理布局为:
后续可以直接构造 Q/K/V tensor view,减少 Slice、reshape、Cast、Concat 和 Pack。
通用 Tiling
新增动态属性:
Host tiling 根据以下信息动态规划 token/channel 切分:
对于 Qwen3.5-27B TP2 的经典 shape:
保留 QK/V 双块映射;其他 shape 使用按 UB 容量和 headDim 对齐的通用切分。
当前支持范围:
headDim=128模型MegaChunkGdn BF16
原 MegaChunkGdn 在 Python 包装和 kernel 内部强制使用 FP16。本 PR 将计算 dtype 统一改为
DTYPE_Q。完成适配的阶段包括:
以下 tensor 支持 FP16/BF16:
G、mask 和必要的累加仍保持 FP32,避免降低关键计算精度。
Workspace 大小和地址偏移改为根据
sizeof(DTYPE_Q)计算,不再隐含假设 FP16。同步 flag 改为使用 PTO 上游同步框架提供的定义,以兼容动态 H/Hg 和 FFTS 同步机制。
测试
CausalConv1dQkv
覆盖:
16384 × 10240shape结果:
ATK 融合算子标准结果:
唯一严格 FP16 用例存在
0.0009765625的差异,即 1 FP16 ULP;BF16 输入、BF16 输出以及 Conv cache 均满足准入标准。MegaChunkGdn BF16
基础 ATK:
大 shape/stress:
模型验证
Qwen3.5-27B TP2 MTP C-Eval 冒烟:
结果与历史同配置一致。
性能
CausalConv1dQkv 算子级 ATK:
整分支 Qwen3.5-27B TP2 2048-token prefill 对比:
该结果是完整优化分支相对 xLLM main 的模型级结果,不能将全部收益单独归因于某一个 kernel。
变更范围
本 PR 仅包含
xllm_ops侧修改: