arXiv:2510.17598cs.AIcs.CL2025-10

将大模型的代码推理能力迁移到小模型,提升生成质量与效率

Reasoning Distillation and Structural Alignment for Improved Code Generation

  • 通过结构感知损失让小模型学习大模型的解题路径
  • 在MBPP等基准上pass@1提升显著,语法匹配率更高
  • 适合资源有限但需高质量代码生成的场景

高效的代码生成依赖于准确理解提示意图,并通过算法推理生成能通过多种测试用例且符合目标语言语法的正确代码。与一般语言任务不同,代码生成不仅要求精确的词元预测,更需要理解解决方案层面和结构关系。超大规模语言模型(VLLM)在解决复杂问题时具备详细推理能力,而较小模型通常缺乏此能力。本文提出一种方法,将VLLM的推理能力蒸馏到更小、部署更快更低成本的模型中。该方法通过学习正确解题路径并建立问题定义与潜在解决方案之间的结构对应关系,采用新颖的结构感知损失优化,使小模型超越词元级生成,深入理解问题解决方案的整体结构。实验结果表明,经过简单高效训练后,该模型在MBPP、MBPP Plus和HumanEval基准上,于pass@1、平均数据流和平均语法匹配指标上均显著优于基线模型。

原文摘要 · Abstract (English)

Effective code generation with language models hinges on two critical factors: accurately understanding the intent of the prompt and generating code that applies algorithmic reasoning to produce correct solutions capable of passing diverse test cases while adhering to the syntax of the target programming language. Unlike other language tasks, code generation requires more than accurate token prediction; it demands comprehension of solution-level and structural relationships rather than merely generating the most likely tokens. very large language model (VLLM) are capable of generating detailed steps toward the correct solution of complex tasks where reasoning is crucial in solving the problem. Such reasoning capabilities may be absent in smaller language models. Therefore, in this work, we distill the reasoning capabilities of a VLLM into a smaller, more efficient model that is faster and cheaper to deploy. Our approach trains the model to emulate the reasoning and problem-solving abilities of the VLLM by learning to identify correct solution pathways and establishing a structural correspondence between problem definitions and potential solutions through a novel method of structure-aware loss optimization. This enables the model to transcend token-level generation and to deeply grasp the overarching structure of solutions for given problems. Experimental results show that our fine-tuned model, developed through a cheap and simple to implement process, significantly outperforms our baseline model in terms of pass@1, average data flow, and average syntax match metrics across the MBPP, MBPP Plus, and HumanEval benchmarks.

代码生成模型蒸馏推理能力

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。