ONNX support for Stan models

Hey all,

It’s been a while since I’ve been on here but something I’ve been thinking more about is interoperability with Stan and more importantly adding additional support for some additional frameworks like onnx. I would like to start working on developing a design doc for what onnx support would like for Stan but I would like some input from the Stan community about what people would like to see. Any feedback is much appreciated.

Here’s a link to the onnx project https://onnx.ai/



I had not previously heard of onnx, but looking through their tech spec it seems like it is restricted to models which can be represented graphically? Additionally, the built in list of ‘operators’ is quite small relative to something like Stan Math.

I think this means one could conceivably define a translation between a onnx model and a Stan program, but not the other way around

1 Like

Ah okay, I see what you mean. Thanks for letting me know @WardBrian, much appreciated! Would this also mean that a Stan model would have to part of some sort of DAG framework for this to work or it would need to be part of a DAG framework that onnx recognizes?

I think it is possible to write down models in Stan which are impossible to represent as a DAG in general. Whether onnx would be even more restrictive than that or not I cannot easily glean from their spec, but it seems like they can translate anything that TensorFlow can represent, so I suspect they do not have additional restrictions.

A similar issue is part of what stalled the stan2tfp compiler work, since it is not possible to represent a general Stan model as TensorFlow code without imposing more restrictions on the Stan language

1 Like

So, I made a GitHub issue under onnxmltools. They have a meetup where they talk about ONNX support and I’ll bring up the idea of having additional operators to help support probabilistic models.

Here’s a link to the issue: ONNX support for Stan models · Issue #549 · onnx/onnxmltools · GitHub

Here’s a link to the event: See LF AI & Data Day - ONNX Community Meetup - Silicon Valley at LF Online Community LF AI & Data Foundation

Wish me luck. Hopefully this can help out more people.

1 Like