[Paper Review] ShapeFlow: Dynamic Shape Interpreter for TensorFlow
ShapeFlow is a dynamic abstract interpreter for TensorFlow that analyzes tensor shape compatibility without code annotations, achieving 499X average speedup and 100% accuracy (only one false negative) in detecting shape incompatibility errors across 52 deep learning benchmarks, offering a practical, annotation-free debugging solution for machine learning developers.
We present ShapeFlow, a dynamic abstract interpreter for TensorFlow which quickly catches tensor shape incompatibility errors, one of the most common bugs in deep learning code. ShapeFlow shares the same APIs as TensorFlow but only captures and emits tensor shapes, its abstract domain. ShapeFlow constructs a custom shape computational graph, similar to the computational graph used by TensorFlow. ShapeFlow requires no code annotation or code modification by the programmer, and therefore is convenient to use. We evaluate ShapeFlow on 52 programs collected by prior empirical studies to show how fast and accurately it can catch shape incompatibility errors compared to TensorFlow. We use two baselines: a worst-case training dataset size and a more realistic dataset size. ShapeFlow detects shape incompatibility errors highly accurately -- with no false positives and a single false negative -- and highly efficiently -- with an average speed-up of 499X and 24X for the first and second baseline, respectively. We believe ShapeFlow is a practical tool that benefits machine learning developers. We will open-source ShapeFlow on GitHub to make it publicly available to both the developer and research communities.
Motivation & Objective
- Address the high frequency and costly detection of shape incompatibility errors in deep learning code, which commonly cause crashes and waste computational resources.
- Overcome the limitations of prior static analysis tools like Ariadne and Pythia, which require manual code annotations and are therefore impractical for widespread use.
- Develop a dynamic, lightweight, and accurate technique that analyzes tensor shapes during execution without modifying the original code or requiring programmer annotations.
- Enable fast and precise detection of shape-related bugs early in the deep learning pipeline to reduce debugging time and computational waste.
- Provide a practical, open-source tool that integrates seamlessly with TensorFlow and supports real-world deep learning workflows without burdening developers.
Proposed method
- ShapeFlow implements a shape-capturing variant of TensorFlow’s APIs that only tracks tensor shapes during execution, discarding actual tensor values.
- It constructs a custom shape computational graph analogous to TensorFlow’s original computational graph, enabling dynamic shape analysis.
- The tool runs in a dynamic, interpretation-based manner, inferring input tensor shapes from data and propagating shape constraints through operations.
- ShapeFlow detects shape incompatibility errors by checking whether operations receive inputs that violate their shape preconditions during execution.
- It leverages Python and TensorFlow’s runtime environment to execute programs without modification, ensuring compatibility and ease of use.
- The system returns a 'no error detected' message if all shape constraints are satisfied, or crashes with a shape error message if a mismatch is found.
Experimental results
Research questions
- RQ1Can a dynamic shape analysis technique detect tensor shape incompatibility errors in deep learning code more efficiently and accurately than existing static analysis tools?
- RQ2To what extent can a shape analysis tool be both fast and precise without requiring code annotations or modifications?
- RQ3How does the performance of a dynamic shape interpreter compare to full TensorFlow execution in terms of speed and error detection accuracy?
- RQ4What is the false positive and false negative rate of such a tool when evaluated on real-world deep learning programs with known shape bugs?
- RQ5Can such a tool be practically adopted by developers without imposing additional engineering or maintenance overhead?
Key findings
- ShapeFlow detected shape incompatibility errors with 100% accuracy on 51 out of 52 buggy programs, reporting only a single false negative.
- It produced zero false positives on all corrected versions of the programs, demonstrating high precision in error detection.
- ShapeFlow achieved an average speed-up of 499X compared to full TensorFlow execution when using a worst-case training dataset size.
- Even with a more realistic dataset size, ShapeFlow maintained a significant 24X average speed-up over full execution.
- The tool required no code annotations or modifications, making it practical and developer-friendly for real-world use.
- The implementation modifies only 118 out of thousands of TensorFlow APIs, ensuring maintainability and extensibility for future support.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.