about
Pattern Matching in AI Compilers and Its Formalization (Extended Version) (arxiv.org)
2 points by matt_d on Dec 19, 2024 | hide | past | pdf | discuss on HN

In plain words: A Python tool for writing compiler optimizations that spot parts of a computation graph and swap in faster kernels; patterns can loop, branch, and check tensor shapes. They distilled its code into a formal core and proved the matching rules and the matcher agree.

Abstract · Pattern Matching in AI Compilers and its Formalization (Extended Version)

PyPM is a Python-based domain specific language (DSL) for building rewrite-based optimization passes on machine learning computation graphs. Users define individual optimizations by writing (a) patterns that match subgraphs of a computation graph and (b) corresponding rules which replace a matched subgraph with an optimized kernel. PyPM is distinguished from the many other DSLs for defining rewriting passes by its complex and novel pattern language which borrows concepts from logic programming. PyPM patterns can be recursive, nondeterminstic, and can require checking domain-specific constraints such as the shapes of tensors. The PyPM implementation is thus similarly complicated, consisting of thousands of lines of C++ code. In this paper, we present our work on building PyPM, as well as formalizing and distilling and this complexity to an understandable mathematical core. We have developed a formal core calculus expressing the main operations of the PyPM pattern language. We define both a declarative semantics - describing which patterns match which terms - and an algorithmic semantics - an idealized version of the PyPM pattern interpreter - and prove their equivalence. The development is fully mechanized in the Coq proof assistant.

Joseph W. Cutler, Alex Collins, Bin Fan, Mahesh Ravishankar, Vinod Grover
arXiv:2412.13398 · cs.PL, cs.LG · submitted Dec 18, 2024
abstract · pdf · html · To appear at CGO'25

add comment on HN