Scalable code generation with large language models: an open-source ensemble and reinforcement learning–based selector
摘要
Large Language Models (LLMs) increasingly support automated code generation, yet ensuring code quality–including correctness, maintainability, and reliability–remains challenging. This study investigates whether ensemble-based approaches with learned model selection can improve code quality compared to individual commercial LLMs. We evaluate three configurations across 133 programming problems in C++ and Java: three commercial LLMs, an open-source ensemble synthesizing outputs from six smaller models, and a reinforcement learning–based selector that adaptively chooses optimal model subsets. Quality assessment includes functional correctness, cyclomatic complexity, maintainability index, and execution efficiency. Results show that the RL-based selector achieves the lowest error rates (6–20%) while maintaining competitive code quality metrics and achieving 100% correctness on multi-threading tasks (3 tasks) where all commercial models failed. The RL-based approach further reduces inference latency by 40–45% and token usage by 50% compared to full ensemble baselines while maintaining or improving code quality. These findings suggest that learned model selection can enable quality-focused code generation that balances correctness, maintainability, and efficiency on algorithmic programming benchmarks, motivating further investigation into integration with quality-assured development workflows.