Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/poogles/mlflow-mvp

MVP of storing models using MLflow
https://github.com/poogles/mlflow-mvp

Last synced: 19 days ago
JSON representation

MVP of storing models using MLflow

Awesome Lists containing this project

README

        

## MLflow models MVP example

This is intended to be viewed alongside the [MLflow docs](https://mlflow.org/docs/latest/models.html#mlflow-models).

### Installation

This demo is packaged using poetry, both 'parts' are packaged seperately.

```python
poetry install
```

### Exporting and running the model

To export our 'models' from the `model` directory run...

```bash
# Export the models
% cd model && poetry run python export.py
```

You should now see a pair of stored models on disk.

```bash
% ls -la /tmp/test_model/
total 0
drwxr-xr-x 4 spegler wheel 128 11 Sep 17:57 .
drwxrwxrwt 117 root wheel 3744 12 Sep 07:46 ..
drwxr-xr-x 9 spegler wheel 288 11 Sep 17:57 pyfunc_model.v1
drwxr-xr-x 9 spegler wheel 288 11 Sep 17:57 pyfunc_model.v2
```

You can now run the API to serve the models.

```bash
% cd ../api && poetry run fastapi dev
...
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```

The above message shows when the API is running and ready to serve traffic.

To test the models, run the following in another terminal window.

```bash
# Try v1 of the model.
% curl -H "Content-type: application/json" -d'{"version":"v1","input":"potato"}' http://127.0.0.1:8000/model
["P","O","T","A","T","O"]
# Try v2 of the model.
% curl -H "Content-type: application/json" -d'{"version":"v2","input":"potato"}' http://127.0.0.1:8000/model
["P","o","T","a","T","o"]
```

### Thoughts

1. Initial loading of the MLflow libraries takes some time, but once they're
in the python VM it's relatively quick to load a model (proportional to
the size of the model).
2. Currently it's not running the model outputs in an independent python env
between models so they're sharing dependencies. The docs indicate we can
fix this I've just not found the right invocation of function args yet.
3. Names for the models have to be different due to internal caches in MLflow.
[Here](https://mlflow.org/docs/latest/model/dependencies.html#limitation-of-code-paths-in-loading-multiple-models-with-the-same-module-name-but-different-implementations)
expands upon possible workarounds if we want models to have the same name.
I'm not sure we do, do we want to add a version in the name like the above?