PaD: Program-aided Distillation Can Teach Small Models Reasoning Better than Chain-of-thought Fine-tuning

Xuekai Zhu, Biqing Qi, Kaiyan Zhang, Xinwei Long, Zhouhan Lin, Bowen Zhou

Abstract

While large language models (LLMs) excel in various natural language processing tasks, their huge size and the inaccessibility of parameters present challenges for practical deployment. Previous studies try to distill task-specific ability from LLMs to smaller models, using data synthesis and chain-of-thought (CoT) fine-tuning. However, synthetic CoT data often contains faulty reasoning, which deteriorates the quality of distillation, especially in reasoning capabilities. In this work, we propose Program-aided Distillation (PaD), which introduces reasoning programs to suppress the errors in distilled data, and thus achieves better distillation quality for reasoning tasks. In PaD, we utilize the reasoning program to substitute the CoT, allowing automated error checking of synthetic data. Further, through error injecting and further training, the small distilling model could iteratively self-refine the reasoning. Moreover, we conduct a step-wise beam search by step-by-step verifying to acquire more exact reasoning chains. We evaluate PaD on arithmetic reasoning, symbolic reasoning, and general ability. Experimental results demonstrate that smaller models using PaD can not only outperform certain LLMs (e.g., LLaMA-1 13B) but also achieve strong improvement over baselines with a significantly smaller scale of parameters and data.

The Challenge of Reasoning in Small Models

Large Language Models (LLMs) like GPT-4 have set new benchmarks for reasoning, yet their deployment remains restricted by immense computational requirements. Distillation—the process of training a smaller "student" model using data generated by a larger "teacher"—is a common solution. Traditionally, this involves Chain-of-Thought (CoT) fine-tuning, where the student learns from step-by-step natural language explanations.

However, this approach is plagued by the "Buggy Teacher" problem. Synthetic CoT data is inherently noisy; a teacher model might arrive at the correct final answer through a logically flawed or "unfaithful" path. Because natural language is ambiguous, verifying these reasoning steps automatically is nearly impossible. Small student models, lacking the inherent robustness of their larger counterparts, are easily misled by these hallucinations, which caps their reasoning potential.

Comparison between natural language Chain-of-Thought (CoT) and Program-aided reasoning.

The PaD Framework: Reasoning as Code

To overcome the limitations of natural language reasoning, the researchers propose Program-aided Distillation (PaD). By shifting the reasoning format from prose to Python code, the framework introduces a rigorous, verifiable structure to the learning process. PaD is built on four technical pillars:

  1. Program-aided Synthesis: Instead of generating text-based steps, the teacher LLM (e.g., GPT-3.5) synthesizes a Python function to solve the problem.
  2. Automated Data Filtering: This is the core innovation. Since the reasoning is expressed as code, it can be executed by a Python interpreter. Any synthetic data that results in a runtime error or an incorrect final answer is discarded. This ensures the student model is trained exclusively on logically sound, "gold-standard" reasoning.
  3. Self-Refinement via Multi-Task Learning: To build robustness, the student is trained to fix its own errors. Researchers intentionally inject bugs into the code and provide the resulting error messages (e.g., NameError) as feedback, teaching the model to iteratively refine its logic.
  4. Step-wise Beam Search: During inference, the model generates code line-by-line. A reward function scores the "faithfulness" of each step, allowing the model to perform a guided search for the most logical path rather than simply guessing the entire program at once.

Empirical Performance

The researchers evaluated PaD across arithmetic reasoning (GSM8K, ASDiv), symbolic reasoning (Coin Flip), and general ability (Big Bench Hard). The results demonstrate that structured code-based reasoning allows sub-billion parameter models to punch far above their weight class.

Solve rates on GSM8K comparing small models using PaD against larger pre-trained models.

As shown in the figure above, a 770M parameter model (CodeT5-large) using PaD achieved a 44.9% score on GSM8K. This significantly outperforms much larger models, such as the 13B parameter LLaMA-1 (17.8%) and the 60B parameter PaLM (29.9%). Furthermore, PaD achieved a 10% improvement over standard CoT baselines while requiring only 35% of the training data.

Key Insights and Trade-offs

  • The Interpreter as Ground Truth: Unlike natural language, code can be unit-tested. The Python interpreter acts as an objective verifier, ensuring that the "thought process" of the model is computationally valid.
  • Specialization vs. Breadth: The study highlights a "no free lunch" scenario. While PaD models become specialists in logic and math, their performance on general knowledge tasks (measured by Big Bench Hard) tends to decline. This suggests that the model trades general-purpose breadth for algorithmic depth.
  • Symbolic Mastery: PaD showed near-perfect accuracy (100%) on symbolic tasks like "Last Letter Concatenation," where standard fine-tuned models often fail to reach 20% accuracy.

Conclusion

Program-aided Distillation proves that for small models, the format of reasoning is just as important as the quality of the teacher. By leveraging the strict syntax of programming languages and the verification power of interpreters, PaD enables small models to achieve reasoning capabilities previously reserved for models 20 to 80 times their size. Future work will focus on balancing this reasoning specialization with general knowledge retention and expanding the toolset beyond Python to handle more diverse, non-algorithmic reasoning tasks.

Summary updated

BibTeX
@inproceedings{zhu2024pad,
  author = {Xuekai Zhu and Biqing Qi and Kaiyan Zhang and Xinwei Long and Zhouhan Lin and Bowen Zhou},
  title = {{PaD: Program-aided Distillation Can Teach Small Models Reasoning Better than Chain-of-thought Fine-tuning}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  url = {https://openreview.net/forum?id=Rl7LWDCN8a},
}
Figure