facebookresearch / beanmachine

A library that allows for inference on probabilistic models
https://beanmachine.org/
MIT License
264 stars 49 forks source link

minibmg: a more automated optimizer (with its own DSL) #1805

Closed gafter closed 1 year ago

gafter commented 1 year ago

Summary: This diff replaces the local optimizer with one that implements a little embedded DSL (domain specific language) so that it is easy to add local transformations. In fact, each transformation is specified as a single line. For example, to eliminate double negation we have the rule

    {-(-x), x},

or to handle common identities, we have rules like

    {0 + x, x},
    {x + 0, x},
    {0 - x, -x},
    {x - 0, x},
    {x - x, 0},
    {0 * x, 0},
    {x * 0, 0},
    {1 * x, x},
    {x * 1, x},

We also add a whole buncha new rules. This improves the performance of NUTS slightly beyond its previous performance.

The optimizer using this approach is actually quite a bit smaller than the brute force one.

This diff also reorganizes the sources a bit to put all the graph and node rewriters in their own directory.

Differential Revision: D40838954

facebook-github-bot commented 1 year ago

This pull request was exported from Phabricator. Differential Revision: D40838954