I’ve put together a tutorial on how I think you could engineer PyMC3 models into production systems - e.g. as web APIs with various endpoints, depending on whether you want a point estimate, highest-density interval or density, etc.
I’ve tried to address what the machine learning lifecycle might look like for a PyMC3 project, how to engineer the service (using FastAPI) and then deploy it to Kubernetes using Bodywork (an open-source ML deployment tool that I contribute to).
The project used in the tutorial is hosted on GitHub,
And you should be able to use this as a template for deploying your own projects.
I’ve been involved in the ML engineering and MLOps side of things for a couple of years now, but I’ve been a PyMC3 fanatic for a lot longer. It struck me, that there’s almost no talk of Bayesian methods and probabilistic programming in these fields, which is odd, given that there aren’t many other pragmatic approaches for tackling uncertainty in prediction (as far as I can see).
@AlexIoannides thank you for posting here! I had always wondered good API endpoints would be, as they define the language that we use in prod. Looks like you’ve nailed a great starting point:
Point
Interval
Density
These nouns have a natural mapping to the probabilistic output. I think I’ve been blinded by sklearn-style point prediction functions that always return a /predict API.
Personally, I didn’t think that pickling and persisting the Model alongside saving the netCDF inference data, was ‘that’ big a deal. It’s certainly no different to the recommended way of persisting PyTorch models (‘models’ and weights persisted separately).
What am I missing?
I’ll consider it further and post my comments on GitHub.