arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2611.02028cs.AI
收藏

LARK:面向大语言模型生成GPU内核的Lean辅助推理

LARK: Lean-Assisted Reasoning for LLM-Generated GPU Kernels

Imperial College London(帝国理工学院);University of Cambridge(剑桥大学);Quettaflop AI;University of Edinburgh(爱丁堡大学);EPFL(洛桑联邦理工学院)

Zixi Zhang, Jiayi Nie, Haoran Wu, Yujie Yan, Yann Herklotz, Rika Antonova, Robert Mullins, Yiren Zhao, George A. Constantinides, Jianyi Cheng

AI总结:

LARK是一种智能体框架,通过Lean 4形式化验证GPU内核与PyTorch参考实现的等价性,可提升LLM生成GPU内核的正确性,在基准测试中表现出良好的验证能力。

摘要:

高效的GPU内核通常是底层且与硬件高度相关的,而大语言模型(LLM)智能体如今生成GPU内核的速度已快于专家验证的速度。现有方法依赖测试,虽能提供证据但无法保证正确性。我们提出LARK,这是一种智能体框架,可针对GPU内核的PyTorch参考实现自动进行形式化验证。LARK在精确算术下证明了功能和内存行为的等价性,并建立了新的信任边界:仅需人工在GPU内核生成前验证算子级别的Lean语义,无需检查每一行生成的代码。LARK针对每种目标语言,在Lean 4中一次性形式化GPU机器模型和各操作的语义,任意输入内核的Lean 4语义均由这些预构建定义推导而来。LLM智能体随后分两步自动完成验证:第一步,智能体将整个内核语义分解为更小的片段,Lean 4会验证该分解过程,解决了直接证明大型内核等价性的难题;第二步,智能体编写Lean证明,确保每个内核片段与其高层级PyTorch对应部分匹配。两步结合可实现整个程序的等价性。我们验证了LARK的两项用途:1)确保现有代码生成智能体的正确性;2)自动验证人工编写的内核库。在KernelCraft GPU任务中,结合简单的ReAct智能体,LARK使GLM 5.3能完全验证12个Level-1内核中的10个,使Opus 5.5能完全验证全部5个Level-2内核。此外,从流行的开源LLM服务框架中随机抽取的10个生产级内核中,LARK验证了9个,并在第10个中发现了新的数据竞争bug。我们认为LARK是智能体时代可验证代码生成的重要一步。

英文摘要:

Efficient GPU kernels are typically low-level and hardware-specific, and LLM agents can now generate them faster than experts can verify. Existing approaches rely on testing, which provides evidence but not a guarantee of correctness. We introduce LARK, an agentic framework that automatically and formally verifies GPU kernels against their PyTorch reference implementations. LARK proves equivalence in functional and memory behavior under exact arithmetic and establishes a new trust boundary: human effort is only needed to verify operator-level Lean semantics ahead of kernel generation time, instead of checking every single line of generated code. LARK formalizes the GPU machine model and the semantics of each operation in Lean 4 once per target language, and the Lean 4 semantics of any incoming kernel is derived from these pre-built definitions. LLM agents then automate the proof in two steps. First, an agent decomposes the whole kernel semantics into smaller segments and Lean 4 verifies this segmentation, which addresses the intractability of proving equivalence for large kernels directly. Second, agents write Lean proofs that each kernel segment matches its high-level PyTorch counterpart. Together, the two steps give whole-program equivalence. We demonstrate that LARK can be used 1) to ensure correctness in existing code-generation agents and 2) to automatically verify human-written kernel libraries. On the KernelCraft GPU tasks, combined with a simple ReAct agent, LARK enables GLM 5.3 to fully verify 10 of 12 Level-1 kernels and Opus 5.5 all 5 Level-2 kernels. Moreover, over 10 production kernels randomly sampled from popular open-source LLM serving frameworks, LARK verifies 9 and identifies a new data race bug in the tenth. We believe LARK represents a significant step toward verifiable code generation in the agentic era.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑