Skip to main content

pynavio

pynavio is a publicly available Python package that helps a user automate some steps for wrapping and simplify the handling of navio models.

pynavio is available on PyPi.

Features

  • Pynavio.mlflow.to_navio function calls mlflow.pyfunc.save_model function, saving a model zip file as required by navio.
  • Pynavio.infer_external_dependencies is a helper function that infers the external dependencies based on the file path. For its limitations please refer to its doc string.
  • Pynavio.infer_imported_code_path is a helper function that infers the imported code paths based on the file path and the root path. For its limitations please refer to its doc string.
  • Pynavio.make_example_request generates a request schema for a navio model from data.

Metadata

To automate the generation of metadata field values for the MLmodel file, use pynavio.mlflow.to_navio setting the corresponding keywords to their corresponding values: example_request, explanations, dataset and oodd, e.g. :

to_navio(...,
example_request=example_request,
explanations='disabled',
dataset=dataset,
oodd='disabled')

Saving a model

pynavio.mlflow.to_navio - this function calls the mlflow.pyfunc.save_model function, saving a model zip file following specifications as required by navio.

Infer Dependencies

pynavio.infer_external_dependencies is a helper function that infers the external dependencies based on the file path, automating the step of mangaging the model's dependencies to some extent. For its limitations please refer to its doc string. The inferred dependencies can be provided to pip_package argument to pynavio.mlflow.to_navio:

to_navio(...,
pip_packages=infer_external_dependencies(__file__)
)

Code Path

pynavio.infer_imported_code_path is a helper function that infers the imported code paths based on the file path and the root path For its limitations please refer to its doc string.

This function needs to be called from the script that imports the model source code (with the to_navio call), so that the code paths are inferred relative to the script. The derived code path can be then passed to the model setup function.

# model.py
...
def setup(code_path):
...
to_navio(...,
code_path=code_path
)

# main_script.py
import model
code_path = infer_imported_code_path(__file__, rootpath)
model.setup(code_path)

Request Schema

pynavio.make_example_request generates a request schema for a navio model from data.

example_request = make_example_request(
df.to_dict(orient='records')[0], 'target')
to_navio(...,
example_request=example_request)

In order to automate the inclusion of a model's data set into MLflow model archive, pynavio.mlfow.to_navio dataset keyword needs to be set:

dataset = dict(name='data', path=f'{tmp_dir}/data.csv')
to_navio(...,
dataset=dataset)