arXiv:2610.22003cs.SEOct 2026

Manuscript Offprint

arXiv:2610.22003

Stateful Testing for Deep Learning Compilers

Jiatao Ge, Ruixiang Qian, Yibo Hu, Yanzhou Mu, Yinglong Zou, Jiawei Liu, Zhenyu Chen, Chunrong Fang

JIATAO GE, State Key Laboratory for Novel Software Technology, Nanjing University, China

RUIXIANG QIAN, State Key Laboratory for Novel Software Technology, Nanjing University, China

YIBO HU, State Key Laboratory for Novel Software Technology, Nanjing University, China

YANZHOU MU, UNIST, Republic of Korea

YINGLONG ZOU, State Key Laboratory for Novel Software Technology, Nanjing University, China

JIAWEI LIU, State Key Laboratory for Novel Software Technology, Nanjing University, China

ZHENYU CHEN, State Key Laboratory for Novel Software Technology, Nanjing University, China

CHUNRONG FANG*, State Key Laboratory for Novel Software Technology, Nanjing University, China

Modern deep learning compilers compile models lazily and cache compiled artifacts for reuse across invocations. Compiler state is information retained by compilers across invocations that can affect later invocations. Examples include cached code and the guards for reusing it. Compiler state from earlier invocations can cause an incorrect result in a later invocation. To understand these stateful compiler bugs, we analyze 26 publicly reported issues in PyTorch, JAX, and TensorFlow that describe such bugs. The analysis shows that detecting these bugs requires two steps, establishing the relevant compiler state through earlier invocations, and making a later invocation that exposes the bug. To meet this requirement, we represent each test case as ⟨model,invocationsequence⟩\langle model, invocation sequence \rangle. A fixed initial state and invocation sequence determine the resulting compiler state. Based on this representation, we develop RONDO, a stateful testing method for deep learning compilers. RONDO generates test cases by mutating invocation sequences. For each test case, it runs the invocation sequence on the model and records compilation behavior. A Markov chain Monte Carlo (MCMC) sampler uses this behavior as feedback to guide generation, favoring rarely observed compilation behaviors. RONDO identifies possible bugs through three-way differential testing, comparing results without compilation, compiled results without compiler state from earlier invocations, and compiled results with that state. A stateful bug is confirmed when the same invocation produces an incorrect result with compiler state retained and a correct result after that state is reset. Lastly, RONDO attempts to shorten the invocation sequence while preserving the original bug to obtain a smaller script that reproduces it. We evaluate RONDO on four representative deep learning frameworks using 24 common model architectures. We detect 117 bugs, including 35 stateful bugs, and submit 39 bug reports, including 18 for stateful bugs. Developers confirm 35 reports, including 16 for stateful bugs, and fix 18 bugs, including 11 stateful bugs. RONDO achieves the highest behavior coverage and compiler Python source-line coverage in the baseline comparison. Its bug checks achieve 99.26% alarm precision. It shortens 44 of 117 invocation sequences while preserving the original bugs, reducing the lengths of these 44 sequences by 83.34% on average.

CCS Concepts: • Software and its engineering → Software testing and debugging.

Additional Key Words and Phrases: deep learning compiler testing, mutation testing

1 Introduction

Deep learning compilers are part of deep learning frameworks and provide important infrastructure for running models [3, 10, 11, 24]. These compilers compile models lazily and cache compiled

∗^{*}Corresponding author.

Authors' Contact Information: Jiatao Ge, State Key Laboratory for Novel Software Technology, Nanjing University, Nanjing, China, gejiatao@smail.nju.edu.cn; Ruixiang Qian, State Key Laboratory for Novel Software Technology, Nanjing University, Nanjing, China, qianrx@smail.nju.edu.cn; Yibo Hu, State Key Laboratory for Novel Software Technology, Nanjing University, Nanjing, China, yibohu@smail.nju.edu.cn; Yanzhou Mu, UNIST, Ulsan, Republic of Korea, 602022320006@smail.nju.edu.cn; Yinglong Zou, State Key Laboratory for Novel Software Technology, Nanjing University, Nanjing, China, 652023320004@smail.nju.edu.cn; Jiawei Liu, State Key Laboratory for Novel Software Technology, Nanjing University, Nanjing, China, jwliu@nju.edu.cn; Zhenyu Chen, State Key Laboratory for Novel Software Technology, Nanjing University, Nanjing, China, zychen@nju.edu.cn; Chunrong Fang, State Key Laboratory for Novel Software Technology, Nanjing University, Nanjing, China, fangchunrong@nju.edu.cn.

Ge et al.

artifacts for reuse across invocations. For example, PyTorch’s compiler caches compiled artifacts for later reuse [2]. Similarly, MindSpore’s compiler caches compiled graphs for later model invocations. These caching mechanisms improve efficiency and make the compilers stateful. Compiler state is information retained by compilers across invocations that can affect later invocations. Compiler state established by prior invocations can cause an incorrect result in a later invocation, even when the same invocation is correct in isolation. We call these bugs stateful compiler bugs.

Existing deep learning compiler testing methods aim to detect framework bugs by generating diverse models and model inputs [27, 37]. Most of these methods test individual model invocations. We write such a test case as a pair ⟨model,invocation⟩\langle model, invocation \rangle, where the model describes the computation under test and the invocation specifies the model inputs. This representation captures the current invocation but does not explicitly capture the compiler state established by prior invocations. To understand stateful compiler bugs, we analyze 26 publicly reported bug issues in PyTorch, JAX, and TensorFlow. The analysis shows that these bugs can produce incorrect outputs and affect training. Detecting these bugs requires generating invocation sequences that establish compiler state and expose bugs in later invocations. This requirement gives rise to three challenges.

Challenge 1. Bug triggers across invocations. For a stateful bug, the invocation that creates the relevant compiler state and the invocation that exposes the bug are different. Representing a test case as ⟨model,invocation⟩\langle model, invocation \rangle does not explicitly capture these invocations and their order. For example, invocation A may establish compiler state that causes a later invocation B to produce an incorrect result. Testing A and B separately would miss this bug. Detecting it therefore requires explicitly searching invocation sequences such as ⟨A,B⟩\langle A, B \rangle [5, 22].

Challenge 2. A large test space. A test case for stateful bugs consists of a model and an invocation sequence. For a fixed model, k possible choices at each position give knk^{n} invocation sequences of length n. This makes exhaustive search infeasible as sequences become longer. Finding sequences that trigger rarely observed compiler behaviors is also difficult because compiler state is not directly observable. For example, invocation B may trigger a new compiler behavior after A, but does not trigger one after A′A'. It is therefore difficult to choose which sequences to extend or change, and random search may repeatedly trigger common behaviors.

Challenge 3. Oracle Unavailable. After running a test case, ground truth is often unavailable for determining whether its results are correct [52]. Traditional differential oracles compare results from different modes, but an inconsistency alone does not establish whether it is caused by a compiler bug or whether the bug depends on compiler state. For example, an invocation may produce different results with and without compilation. This comparison does not tell us which result is incorrect. It also does not show whether compiler state from earlier invocations caused the inconsistency.

To address these challenges, we formulate the testing problem and define compiler state. The complete compiler state is not directly observable, so we use invocation sequences to represent compiler state. We represent each test case as ⟨model,invocation sequence⟩\langle model, invocation\ sequence\rangle. A fixed initial state and a fixed invocation sequence determine the resulting compiler state. We can explore different compiler states by generating invocation sequences and reach the same state again by replaying the same sequence (addressing Challenge 1). Based on this representation, we develop RONDO, a stateful testing method for deep learning compilers. RONDO first generates test cases by mutating invocation sequences or using an SMT solver. It runs the invocation sequences and uses feedback to guide subsequent test case generation toward rarely observed compiler behaviors (addressing Challenge 2). It then compares results from invocations without compiling the model, compiled invocations without compiler state from earlier invocations, and compiled invocations with that state. To check whether a bug depends on compilation or compiler state, RONDO compares the same invocation with its inputs and program state fixed. A stateful bug is detected when the result is incorrect with compiler state from earlier invocations and correct after that state is reset (addressing Challenge 3). Finally, it shortens the invocation sequence while preserving the original bug.

We implement RONDO for PyTorch, JAX, TensorFlow, and MindSpore and evaluate it using 24 common model architectures, including multilayer perceptrons (MLPs), convolutional neural networks (CNNs), and Transformers. We detect 117 bugs, including 35 stateful bugs, and submit 39 bug reports, including 18 for stateful bugs. Developers confirm 35 reports, including 16 for stateful bugs, and fix 18 bugs, including 11 stateful bugs. RONDO achieves the highest behavior coverage and compiler Python source-line coverage in the baseline comparison. Its bug checks achieve 99.26% alarm precision. It shortens 44 of 117 invocation sequences while preserving the original bugs, reducing the lengths of these 44 sequences by 83.34% on average.

Our work makes the following contributions.

  • A new perspective on compiler testing. We study stateful compiler bugs and define compiler state to describe their dependence on earlier invocations. We represent each test case as ⟨\langlemodel, invocation sequence ⟩\rangle. The sequence establishes compiler state for later invocations. We detect stateful bugs by comparing the same invocation with compiler state retained and reset, while keeping its inputs and program state fixed. Our analysis of 26 publicly reported bug issues guides this design.

  • A novel stateful testing method. We propose RONDO, which generates test cases through mutation or SMT-based synthesis and uses compilation feedback to guide generation toward rarely observed compiler behaviors. It checks results through structured comparison and semantic checks, then shortens invocation sequences while preserving the original bug and its reproduction conditions.

• An empirical evaluation on production compilers. We evaluate RONDO on four frameworks using 24 common model architectures. It achieves the highest behavior coverage and compiler Python source-line coverage among the evaluated methods. We detect 117 bugs, including 35 stateful bugs, and submit 39 bug reports, including 18 for stateful bugs. Developers confirm 35 reports, including 16 for stateful bugs, and fix 18 bugs, including 11 stateful bugs.

• Open-science artifacts. To support future research and community reuse, we release RONDO’s implementation, the results of bug discovery, and the experimental results reported in this paper [1]. We welcome community contributions to extend these artifacts.

References (21)