[论文解读] Optimizing Large Language Model Hyperparameters for Code Generation
本研究系统评估了四个关键超参数——温度、top-p、频率惩罚和存在惩罚——对使用 GPT-3.5 Turbo 模型在 13 个 Python 任务中代码生成性能的影响。研究识别出最优设置(温度 < 0.5,top-p < 0.75,频率惩罚 ∈ [−1, 1.5],存在惩罚 > −1),可最大化功能性代码的输出,为基于大语言模型的代码生成中的超参数调优提供了实证依据。
Large Language Models (LLMs), such as GPT models, are increasingly used in software engineering for various tasks, such as code generation, requirements management, and debugging. While automating these tasks has garnered significant attention, a systematic study on the impact of varying hyperparameters on code generation outcomes remains unexplored. This study aims to assess LLMs' code generation performance by exhaustively exploring the impact of various hyperparameters. Hyperparameters for LLMs are adjustable settings that affect the model's behaviour and performance. Specifically, we investigated how changes to the hyperparameters: temperature, top probability (top_p), frequency penalty, and presence penalty affect code generation outcomes. We systematically adjusted all hyperparameters together, exploring every possible combination by making small increments to each hyperparameter at a time. This exhaustive approach was applied to 13 Python code generation tasks, yielding one of four outcomes for each hyperparameter combination: no output from the LLM, non executable code, code that fails unit tests, or correct and functional code. We analysed these outcomes for a total of 14,742 generated Python code segments, focusing on correctness, to determine how the hyperparameters influence the LLM to arrive at each outcome. Using correlation coefficient and regression tree analyses, we ascertained which hyperparameters influence which aspect of the LLM. Our results indicate that optimal performance is achieved with a temperature below 0.5, top probability below 0.75, frequency penalty above -1 and below 1.5, and presence penalty above -1. We make our dataset and results available to facilitate replication.
研究动机与目标
- 探究超参数调优如何影响大语言模型(LLMs)生成代码的正确性与功能性。
- 识别出可最大化生成正确且可执行 Python 代码的最优超参数配置。
- 解决在软件工程背景下,针对基于大语言模型的代码生成中超参数影响缺乏系统性实证分析的问题。
- 提供可复现的数据集与结果,以支持未来研究及大语言模型在代码生成中的实际部署。
提出的方法
- 对温度、top-p、频率惩罚和存在惩罚的 1,134 种唯一组合进行了全面的超参数搜索。
- 针对每组组合,使用 GPT-3.5 Turbo API 为 13 个预定义的 Python 代码生成任务生成代码。
- 通过自动化验证评估生成的代码:无输出、不可执行代码、单元测试失败或正确且功能完整的代码。
- 使用 Python 的 unittest 库和断言检查实现单元测试,以验证正确性。
- 通过皮尔逊相关系数和回归树分析,识别超参数对代码质量结果的影响。
- 为避免对输出长度和内容施加人为限制,研究排除了最大 token 数和 logit 偏置。
实验结果
研究问题
- RQ1大语言模型超参数的变化是否会对生成代码的质量产生可测量的影响?
- RQ2在 Python 任务中,实现最高正确与功能性代码生成率的最优超参数设置是什么?
- RQ3哪些超参数对代码正确性、可执行性及生成成功率具有最显著的影响?
- RQ4与 OpenAI API 的默认超参数设置相比,优化后的配置在代码生成性能上表现如何?
主要发现
- 温度对代码生成结果的影响最强,温度低于 0.5 时可获得最高比例的正确且功能完整的代码。
- top-p 值低于 0.75 显著降低了单元测试失败的可能性,从而提升了代码正确性。
- 频率惩罚设置在 −1 到 1.5 之间可降低生成不可执行代码的风险,极端值则会提高失败率。
- 存在惩罚高于 −1 可带来代码质量的微小提升,但其整体影响有限。
- OpenAI API 的默认超参数设置并不能始终产生最优结果,表明需要根据任务进行特定调优。
- 共生成并评估了 14,742 个代码片段,形成一个全面的数据集,可供复现与进一步研究。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。