Automatically repairing tensor shape faults in deep learning programs

Dangwei Wu,Beijun Shen,Yuting Chen,He Jiang,Lei Qiao
DOI: https://doi.org/10.1016/j.infsof.2022.107027
IF: 3.9
2022-01-01
Information and Software Technology
Abstract:Context: Software developers frequently invoke deep learning (DL) APIs to incorporate artificial intelligence solutions into software systems. However, misuses of these APIs can cause various DL faults, such as tensor shape faults. Tensor shape faults occur when restriction conditions of operations are not met; they are prevalent in practice, leading to many system crashes. Meanwhile, researchers and engineers still face a strong challenge in detecting tensor shape faults - static techniques incur heavy overheads in defining detection rules, and the only dynamic technique requires human engineers to rewrite APIs for tracking shape changes. Objective: This paper introduces a novel technique that leverages machine learning to detect tensor shape faults, and as well uses patterns to repair faults detected. Methods: We first construct SFData, a set of 146 buggy programs with crashing tensor shape faults (i.e., those causing programs to crash). We also conduct an empirical study on crashing tensor shape faults, categorizing them into four types and revealing twelve repair patterns. Then we propose Tensfa2, an automated approach to detecting and repairing crashing tensor shape faults. Tensfa2 employs a machine learning method to learn from crash messages and decision trees to detect tensor shape faults. Next, Tensfa2 tracks shape properties by a customized Python debugger, analyzes their data dependences, and uses the twelve patterns to generate patches. Tensfa2 is an extended version of Tensfa-our previous approach presented at ISSRE'21. Its performance is enhanced by two techniques: a search-based method for repairing shape value faults, and a bundle of three ranking strategies for prioritizing the repair patterns. Results: Tensfa2 is evaluated on SFData and IslamData (another dataset of tensor shape faults). The results show the effectiveness of Tensfa2. In particular, Tensfa2 achieves an F1-score of 96.88% in detecting the faults and repairs 82 out of 146 buggy programs in SFData. Conclusion: We believe that repair patches generated by our approach will help engineers fix their deep learning programs much more efficiently, saving their time and efforts.
What problem does this paper attempt to address?