一句话:提出教师-学生框架 T-REX,用逐步自然语言执行语义理由训练小模型预测程序状态,超越 GPT-4o。
大型语言模型在代码搜索、摘要与生成等静态代码任务上表现优异,但在动态代码推理——即不实际运行程序而推断其执行行为——方面仍受限,原因在于训练数据缺乏运行时上下文。本文提出 T-REX,一个面向执行预测的教师-学生框架,将 LLM 训练锚定在真实执行与相应执行语义上。T-REX 让大型教师模型 Explainer 生成细粒度、逐步的自然语言理由,解释实际执行中程序状态如何从一条语句转移到另一条语句;这些理由用于训练较小的学生模型 Reasoner 预测下一程序状态,从而以更低计算成本精确模拟程序行为。这种基于执行、以理由驱动的训练与语句级、感知状态转移的执行语义对齐,提升了预测准确率。实验表明,Reasoner 在多个运行时行为预测维度上优于规模大得多的 GPT-4o 与 GPT-4o-mini,并有助于运行时错误的静态检测与调试。最后,作者讨论了如何通过此类教师-学生蒸馏将 T-REX 推广到对任意动态分析的静态模拟,并以 Python 动态程序切片为例说明。
Large language models (LLMs) have shown strong performance in static code tasks like code search, summarization, and generation, but remain limited in dynamic code reasoning, which involves inferring how programs behave during execution without actually running them. This limitation stems from LLMs being trained on static code and lacking the necessary runtime context. In this paper, we present T-REX, a novel teacher-student framework for execution prediction that addresses these limitations by grounding LLM training in actual execution and corresponding execution semantics. T-REX uses a large teacher model (Explainer) to generate fine-grained, stepwise natural language rationales explaining how program state transitions from one statement to another during actual execution. These rationales are used to train a smaller student model (Reasoner) to predict next program states, enabling accurate simulation of program behavior with lower computational cost. Our execution-grounded, rationale-driven training aligns with transition-aware execution semantics at the statement level, enhancing prediction accuracy. Our experiments show that T-REX enables Reasoner to outperform much larger GPT-4o and GPT-4o-mini models across multiple dimensions of runtime behavior prediction, while also aiding in static detection of runtime errors as well as in debugging. Finally, we discuss how T-REX can be generalized to static emulation of any dynamic analysis through such a teacher-student distillation, illustrating with the specific case of dynamic program slicing in Python.
@article{paperbot12121,
title = {T-REX: Teaching Large Language Models to Reason with Verbalized Execution Semantics},
author = {Yan Wang and Ling Ding and Jiechen Sun and Tien N. Nguyen and Shaohua Wang and Aashish Yadavally and Xin Xia and Yanan Zheng},
journal = {Proceedings of the ACM on Programming Languages},
volume = {10},
number = {OOPSLA2},
year = {2026},
doi = {10.1145/3839452}
}