Modern language models (LMs) have gained widespread acceptance in everyday and professional contexts, particularly in programming. An essential procedure enabling this adoption is instruction tuning, which substantially enhances LMs' practical utility by training them to follow user instructions and human preferences. However, existing instruction tuning schemes overlook a crucial aspect: the security of generated code. As a result, even the state-of-the-art instruction-tuned LMs frequently produce unsafe code, posing significant security risks. In this work, we introduce SafeCoder to address this gap. SafeCoder performs security-centric fine-tuning using a diverse and high-quality dataset that we collected using an automated pipeline. We integrate the security fine-tuning with standard instruction tuning, to facilitate a joint optimization of both security and utility. Despite its simplicity, we show that SafeCoder is effective across a variety of popular LMs and datasets. It is able to drastically improve security (by about 30%), while preserving utility.
翻译:现代语言模型已在日常和专业领域获得广泛认可,尤其是在编程方面。实现这一应用的关键流程是指令微调,它通过训练模型遵循用户指令和人类偏好,显著提升了语言模型的实际可用性。然而,现有指令微调方案忽略了一个关键方面:生成代码的安全性。因此,即便最先进的指令微调语言模型也频繁生成不安全代码,带来重大安全风险。在本工作中,我们提出SafeCoder以填补这一空白。SafeCoder采用自动化流水线收集的多样化高质量数据集,执行以安全为中心的微调。我们将安全微调与标准指令微调相结合,以实现安全性与实用性的联合优化。尽管方法简单,我们证明SafeCoder在多种流行语言模型和数据集上均有效。它能在保持实用性的同时,大幅提升安全性(约30%)。