SelfCodeAlign: Self-Alignment for Code Generation
作者: Yuxiang Wei, Federico Cassano, Jiawei Liu, Yifeng Ding, Naman Jain, Zachary Mueller, Harm de Vries, Leandro von Werra, Arjun Guha, Lingming Zhang
分类: cs.CL, cs.LG, cs.SE
发布日期: 2024-10-31 (更新: 2024-11-01)
备注: Accepted to NeurIPS 2024
💡 一句话要点
SelfCodeAlign:一种用于代码生成的自对齐框架,无需人工标注或知识蒸馏。
🎯 匹配领域: 支柱二:RL算法与架构 (RL & Architecture) 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 代码生成 自对齐 指令调优 大型语言模型 沙箱验证
📋 核心要点
- 现有代码LLM依赖人工标注或知识蒸馏,成本高昂且透明度不足,限制了其发展和应用。
- SelfCodeAlign通过自生成任务、沙箱验证和指令调优,实现代码LLM的自对齐,无需人工干预。
- 实验表明,SelfCodeAlign在多个基准测试中超越了现有方法,并成功创建了StarCoder2-Instruct。
📝 摘要(中文)
指令调优是一种监督式微调方法,可显著提高大型语言模型(LLM)遵循人类指令的能力。我们提出了SelfCodeAlign,这是第一个完全透明且许可宽松的自对齐代码LLM的流程,无需大量人工标注或知识蒸馏。SelfCodeAlign在整个数据生成过程中对推理采用相同的基模型。它首先从高质量的种子代码片段中提取不同的编码概念,以生成新的任务。然后,它为每个任务采样多个响应,将每个响应与测试用例配对,并在沙箱环境中验证它们。最后,选择通过验证的示例进行指令调优。在我们的主要实验中,我们使用SelfCodeAlign和CodeQwen1.5-7B生成了一个包含74k指令-响应对的数据集。在此数据集上进行微调后,模型在HumanEval+上实现了67.1的pass@1,超过了CodeLlama-70B-Instruct,尽管其规模小了十倍。在所有基准测试中,此微调模型始终优于使用OctoPack训练的原始版本,OctoPack是先前最先进的无需人工标注或知识蒸馏的指令调优方法。此外,我们表明SelfCodeAlign在从3B到33B的各种大小的LLM中均有效,并且基模型可以从与其自身数据分布的对齐中受益更多。我们进一步验证了管道中每个组件的有效性,表明SelfCodeAlign优于GPT-4o的直接蒸馏以及领先的基于GPT-3.5的蒸馏方法,例如OSS-Instruct和Evol-Instruct。SelfCodeAlign还促成了StarCoder2-Instruct的创建,这是第一个完全透明、许可宽松且自对齐的代码LLM,可实现最先进的编码性能。
🔬 方法详解
问题定义:现有代码LLM的指令调优通常依赖于人工标注的数据集或从更强大的模型(如GPT-4)进行知识蒸馏。人工标注成本高昂,且难以覆盖所有可能的代码场景。知识蒸馏则引入了外部模型的偏差,限制了模型的泛化能力。因此,需要一种更高效、透明且可扩展的方法来对齐代码LLM。
核心思路:SelfCodeAlign的核心思路是利用模型自身的能力来生成训练数据,并使用沙箱环境进行自动验证。通过从高质量的代码片段中提取概念,生成新的编程任务,并对模型的输出进行测试,从而实现模型的自对齐。这种方法避免了人工标注的成本和外部模型的偏差。
技术框架:SelfCodeAlign包含以下几个主要阶段:1) 任务生成:从高质量的代码片段中提取编码概念,并基于这些概念生成新的编程任务。2) 响应采样:对于每个任务,模型生成多个可能的响应。3) 沙箱验证:将每个响应与测试用例配对,并在沙箱环境中执行,以验证其正确性。4) 数据选择:选择通过测试的指令-响应对作为训练数据。5) 指令调优:使用选择的数据对模型进行指令调优。
关键创新:SelfCodeAlign的关键创新在于其完全自对齐的流程,无需任何人工标注或知识蒸馏。它利用模型自身的能力来生成和验证训练数据,从而避免了外部依赖和偏差。此外,沙箱验证确保了训练数据的质量,提高了模型的性能。
关键设计:在任务生成阶段,论文使用了启发式方法从代码片段中提取编码概念。在响应采样阶段,使用了不同的采样策略来增加数据的多样性。在沙箱验证阶段,使用了标准的测试框架来评估代码的正确性。在指令调优阶段,使用了标准的监督学习方法,并对学习率和batch size等超参数进行了调整。
📊 实验亮点
使用SelfCodeAlign和CodeQwen1.5-7B生成的数据集进行微调后,模型在HumanEval+上实现了67.1的pass@1,超过了CodeLlama-70B-Instruct,尽管模型规模小了十倍。该模型在所有基准测试中均优于使用OctoPack训练的原始版本,并且优于GPT-4o的直接蒸馏以及领先的基于GPT-3.5的蒸馏方法。
🎯 应用场景
SelfCodeAlign可用于构建更强大、更易于定制的代码LLM,应用于代码生成、代码补全、代码修复等领域。该方法降低了代码LLM的开发成本,并提高了其透明度和可控性,促进了AI在软件开发领域的应用。
📄 摘要(原文)
Instruction tuning is a supervised fine-tuning approach that significantly improves the ability of large language models (LLMs) to follow human instructions. We propose SelfCodeAlign, the first fully transparent and permissive pipeline for self-aligning code LLMs without extensive human annotations or distillation. SelfCodeAlign employs the same base model for inference throughout the data generation process. It first extracts diverse coding concepts from high-quality seed snippets to generate new tasks. It then samples multiple responses per task, pairs each with test cases, and validates them in a sandbox environment. Finally, passing examples are selected for instruction tuning. In our primary experiments, we use SelfCodeAlign with CodeQwen1.5-7B to generate a dataset of 74k instruction-response pairs. Finetuning on this dataset leads to a model that achieves a 67.1 pass@1 on HumanEval+, surpassing CodeLlama-70B-Instruct despite being ten times smaller. Across all benchmarks, this finetuned model consistently outperforms the original version trained with OctoPack, the previous state-of-the-art method for instruction tuning without human annotations or distillation. Additionally, we show that SelfCodeAlign is effective across LLMs of various sizes, from 3B to 33B, and that the base models can benefit more from alignment with their own data distribution. We further validate each component's effectiveness in our pipeline, showing that SelfCodeAlign outperforms both direct distillation from GPT-4o and leading GPT-3.5-based distillation methods, such as OSS-Instruct and Evol-Instruct. SelfCodeAlign has also led to the creation of StarCoder2-Instruct, the first fully transparent, permissively licensed, and self-aligned code LLM that achieves state-of-the-art coding performance.