小模型也能写出高效CUDA代码,靠的是大模型的优化思路迁移。
From Large to Small: Transferring CUDA Optimization Expertise via Reasoning Graph
- 构建推理图结构,用搜索算法复现大模型的优化逻辑。
- 在两个评测集上平均提速2.33倍,接近大模型性能。
- 无需训练,适合注重隐私和算力成本的开发者使用。
尽管CUDA编程和领域专用库持续演进,利用具有大规模并行架构的GPU仍具挑战性。大语言模型(LLMs)在从顺序代码生成优化CUDA代码方面展现出强大潜力。然而,实际应用中面临两大难题:云API存在代码泄露风险,本地部署则常因计算开销大而效率低下。这促使人们关注轻量级小语言模型(SLMs),它们更省资源且更私密。虽有研究显示SLMs在特定任务上可媲美LLMs,但我们的实验表明其在复杂CUDA生成任务中因推理能力有限而表现不佳。为此,我们提出ReGraphT——一种无需训练、基于检索增强生成的框架,将LLM级别的推理能力迁移至小模型。ReGraphT将CUDA优化轨迹组织为结构化推理图,将联合优化视为状态转移,并采用蒙特卡洛图搜索(MCGS)实现高效探索。我们还设计了一个按推理复杂度分层的专用CUDA评测基准。实验表明,ReGraphT优于特定于高性能计算的微调模型及其他检索增强方法,在CUDAEval和ParEval上平均获得2.33倍加速。当与DeepSeek-Coder-V2-Lite-Instruct和Qwen2.5-Coder-7B-Instruct结合时,该框架使SLMs在无隐私风险和高算力负担的前提下逼近LLM性能。
原文摘要 · Abstract (English)
Despite significant evolution of CUDA programming and domain-specific libraries, effectively utilizing GPUs with massively parallel engines remains difficult. Large language models (LLMs) show strong potential in generating optimized CUDA code from sequential code. However, using LLMs in practice faces two major challenges: cloud-based APIs pose risks of code leakage, and local deployment is often computationally expensive and inefficient. These drawbacks have spurred interest in small language models (SLMs), which are more lightweight and privacy-friendly. Encouragingly, recent studies show that SLMs can achieve performance comparable to LLMs on specific tasks. While SLMs can match LLMs on domain-specific tasks, their limited reasoning abilities lead to suboptimal performance in complex CUDA generation according to our experiments. To bridge this gap, we propose ReGraphT, a training-free, retrieval-augmented generation framework that transfers LLM-level reasoning to smaller models. ReGraphT organizes CUDA optimization trajectories into a structured reasoning graph, modeling the combined CUDA optimizations as state transitions, and leverages Monte Carlo Graph Search (MCGS) for efficient exploration. We also present a CUDA-specific benchmark with difficulty tiers defined by reasoning complexity to evaluate models more comprehensively. Experiments show that ReGraphT outperforms HPC-specific fine-tuned models and other retrieval-augmented approaches, achieving an average 2.33X speedup on CUDAEval and ParEval. When paired with DeepSeek-Coder-V2-Lite-Instruct and Qwen2.5-Coder-7B-Instruct, ReGraphT enables SLMs to approach LLM-level performance without the associated privacy risks or excessive computing overhead.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。