Saved in:
Bibliographic Details
Main Authors: Cutler, Joseph W., Collins, Alex, Fan, Bin, Ravishankar, Mahesh, Grover, Vinod
Format: Preprint
Published: 2024
Subjects:
Online Access:https://arxiv.org/abs/2412.13398
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866929636382867456
author Cutler, Joseph W.
Collins, Alex
Fan, Bin
Ravishankar, Mahesh
Grover, Vinod
author_facet Cutler, Joseph W.
Collins, Alex
Fan, Bin
Ravishankar, Mahesh
Grover, Vinod
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2412_13398
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Pattern Matching in AI Compilers and its Formalization (Extended Version)
Cutler, Joseph W.
Collins, Alex
Fan, Bin
Ravishankar, Mahesh
Grover, Vinod
Programming Languages
Machine Learning
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.
title Pattern Matching in AI Compilers and its Formalization (Extended Version)
topic Programming Languages
Machine Learning
url https://arxiv.org/abs/2412.13398