A Static Analyzer for Detecting Tensor Shape Errors in Deep Neural Network Training Code

We present an automatic static analyzer PyTea that detects tensorshape errors in PyTorch code. The tensor-shape error is critical in the deep neural net code; much of the training cost and intermediate results are to be lost once a tensor shape mismatch occurs in the midst of the training phase. Given the input PyTorch source, PyTea statically traces every possible execution path, collects tensor shape constraints required by the tensor operation sequence of the path, and decides if the constraints are unsatisfiable (hence a shape error can occur). PyTea’s scalability and precision hinges on the characteristics of real-world PyTorch applications: the number of execution paths after PyTea’s conservative pruning rarely explodes and loops are simple enough to be circumscribed by our symbolic abstraction. We tested PyTea against the projects in the official PyTorch repository and some tensor-error code questioned in the StackOverflow. PyTea successfully detects tensor shape errors in these codes, each within a few seconds. CCS CONCEPTS • Software and its engineering → Software testing and debugging.

[1]  Soumith Chintala,et al.  Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks , 2015, ICLR.

[2]  Cruz Camacho,et al.  Static Analysis of Python Programs using Abstract Interpretation: An Application to Tensor Shape Analysis , 2020 .

[3]  Natalia Gimelshein,et al.  PyTorch: An Imperative Style, High-Performance Deep Learning Library , 2019, NeurIPS.

[4]  Kilian Q. Weinberger,et al.  Deep Networks with Stochastic Depth , 2016, ECCV.

[5]  Yannis Smaragdakis,et al.  Static Analysis of Shape in TensorFlow Programs , 2020, ECOOP.

[6]  Geoffrey E. Hinton,et al.  A Simple Framework for Contrastive Learning of Visual Representations , 2020, ICML.

[7]  Nikolaj Bjørner,et al.  Z3: An Efficient SMT Solver , 2008, TACAS.

[8]  Mark Chen,et al.  Language Models are Few-Shot Learners , 2020, NeurIPS.

[9]  Shimpei Sawada,et al.  Semi-static type, shape, and symbolic shape inference for dynamic computation graphs , 2020, MAPL@PLDI.

[10]  K. Jarrod Millman,et al.  Array programming with NumPy , 2020, Nat..

[11]  Antoine Miné,et al.  Static Value Analysis of Python Programs by Abstract Interpretation , 2018, NFM.

[12]  Yannis Smaragdakis,et al.  Strictly declarative specification of sophisticated points-to analyses , 2009, OOPSLA '09.

[13]  Yannis Smaragdakis,et al.  P/Taint: unified points-to and taint analysis , 2017, Proc. ACM Program. Lang..

[14]  Yifan Chen,et al.  An empirical study on TensorFlow program bugs , 2018, ISSTA.

[15]  Sahil Verma,et al.  ShapeFlow: Dynamic Shape Interpreter for TensorFlow , 2020, ArXiv.

[16]  Julian Dolby,et al.  Ariadne: analysis for machine learning programs , 2018, MAPL@PLDI.