计算机科学 > 分布式、并行与集群计算
[提交于 2026年10月9日 (v1),最后修订于 2026年11月25日 (此版本, v2)]
标题:CompileMask: Bridging the Gap Between Expressiveness and Efficiency in Attention Masking
查看原文 PDF 中文 PDF (下批处理) EasyResearch 阅读摘要:Modern attention workloads require diverse masks whose shapes depend on per-sequence parameters, yet efficient attention kernels natively support only a small set of mask patterns. Existing methods for custom masks face an expressiveness-efficiency trade-off. Predicate-based methods are expressive but evaluate a user-defined predicate on every element at substantial cost, whereas interval-based methods execute efficiently but lack the expressiveness for complex masks. We present CompileMask, which bridges this gap by compiling the mask predicate users write into an Execution Descriptor that the attention kernel executes efficiently. We design a compiler that automatically lowers a mask predicate into an intermediate representation and generates a mask-specific preprocessing kernel, which builds the descriptor for each batch with a few expressions per row rather than by evaluating the predicate on every element. We further propose Tile-local Records, a compact representation of row visibility within each tile that lets the attention kernel check every element with a few integer operations, so that masking stays efficient even for complex masks. Experiments show that CompileMask achieves up to $3.3\times$ speedup over FlexAttention and up to $1.2\times$ over FlashMask in single-operator benchmarks, while supporting complex masks that FlashMask cannot express.
提交历史
来自:Hongzheng Li[v1] 2026年10月9日 星期五 12:10:13 UTC (378 KB)
[v2] 2026年11月25日 星期三 09:44:45 UTC (555 KB)