Ariadne: analysis for machine learning programs

Julian Dolby, Avraham Shinnar, Allison Allain, Jenna M. Reinen

TL;DR

This paper introduces "Ariadne," a static analysis framework that extends the WALA analysis tool to Python, specifically targeting machine learning code that uses TensorFlow. By developing a novel type system for tensors and a dataflow analysis, Ariadne aims to catch subtle errors in ML code that could otherwise lead to scientifically invalid results.

What Problem Does This Paper Address?

Machine learning (ML) has become indispensable in fields like vision, translation, and scientific research. Python is the dominant language for ML due to its rich libraries, offering faster development cycles. However, dynamic languages like Python lack the robust compile-time error detection found in statically typed languages (e.g., Java with tools like Eclipse). This is particularly problematic for ML, where statistical methods can mask subtle coding errors, leading to plausible-looking but meaningless results that can undermine scientific findings. The paper addresses this gap by providing a static analysis tool that can detect such errors before runtime.

Methods

The core of Ariadne's approach is the adaptation of the WALA (Watson Libraries for Analysis) framework to support Python. This involved:

  • Python Front-End for WALA: Developing a mechanism to translate Python Abstract Syntax Trees (ASTs) into WALA's Common Abstract Syntax Tree (CAst) system, and subsequently into WALA's Internal Representation (IR). This leverages Jython's capabilities and involves handling Python's unique constructs.
  • Tensor Type System: Creating a novel type system specifically designed to capture the semantic properties of tensors, which are fundamental data structures in ML frameworks like TensorFlow. This system tracks tensor dimensions, labels, and nested structures.
  • Dataflow Analysis for Tensor Usage: Implementing a dataflow analysis to track how these tensors are used and transformed throughout the program. This analysis, combined with the tensor type system, allows for the verification of operations like reshaping.
  • IR Extensions: Extending WALA's IR to model TensorFlow-specific operations and constructs, enabling a deeper analysis of ML code. This includes programmatic creation of IR for functions and the use of XML to model popular ML frameworks.

Datasets

The paper uses the MNIST dataset for demonstrating and evaluating the analysis. Specifically, it analyzes example code that reads and processes the MNIST dataset for image recognition tasks. No new benchmarks are introduced; instead, existing ML code examples are used.

Key Insights and Ideas

  • The "Meaningless Results" Problem: The paper highlights a critical issue in ML: subtle errors can go undetected because statistical models can still produce outputs that appear valid, even if the underlying logic is flawed. This can lead to incorrect scientific conclusions.
  • Bridging the Gap for Dynamic Languages: Ariadne demonstrates that static analysis techniques, traditionally applied to statically typed languages, can be effectively adapted to dynamic languages like Python, particularly for specialized domains like ML.
  • Tensor Semantics are Key: The core innovation is the tensor type system, which goes beyond simple type checking to capture the structural and dimensional semantics of tensors. This allows for verification of operations like reshaping, which depend heavily on these properties.
  • Leveraging Existing Frameworks: The paper shows the power of extending existing robust analysis frameworks like WALA, rather than building a new one from scratch, by adapting its front-end and IR capabilities.

Key Results

The paper presents preliminary results from analyzing several TensorFlow examples, including those based on MNIST and neuroimaging data. The analysis was able to:

  • Parse and Analyze Programs: Ariadne successfully parsed and analyzed the tested programs.
  • Verify API Usage: For analyzed TensorFlow APIs (e.g., reshape, conv2d, conv3d, placeholder), the analysis was able to verify that they were used correctly in the context of the programs.
  • No False Positives: The authors report no false positives in their analysis of the tested programs.
  • Efficiency: The analysis of each program took only a few seconds on a normal laptop.

The paper includes a table (Table 1) summarizing the analysis of various TensorFlow APIs across different programs, indicating which APIs were analyzed and verified (✓) or not found/analyzed (X).

Limitations and Future Work

The authors acknowledge several limitations and suggest future directions:

  • Preliminary Implementation: The current implementation is described as preliminary, and the model of TensorFlow is not yet complete.
  • No Claims on False Negatives: Due to the preliminary nature, the authors make no claims about false negatives, meaning there might be correct uses of constructs that were not fully analyzed.
  • Incomplete API Coverage: The analysis focuses on a subset of the TensorFlow API. Future work would involve extending the analysis to cover more of the API.
  • Broader Language Support: While the focus is on Python and TensorFlow, extending the framework to other ML languages and frameworks would be valuable.
  • Integration with IDEs: Integrating such analysis tools into development environments (IDEs) would significantly enhance their practical utility for developers.

Summary updated

BibTeX
@inproceedings{dolby2018ariadne,
  author = {Julian Dolby and Avraham Shinnar and Allison Allain and Jenna M. Reinen},
  title = {{Ariadne: analysis for machine learning programs}},
  booktitle = {MAPL@PLDI},
  year = {2018},
  url = {https://openreview.net/forum?id=HRapZG13NRq},
}
Figure