👍 🎉 First off, thanks for taking the time to read the guidelines and for considering contributing! 🎉 👍
The following is a set of guidelines for contributing to the functions' repository and its packages. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
- What Should I Know Before I Start?
- Installation Guide
- Creating A New Function
- Updating An Existing Function
- Testing Functions
- The functions CLI
All the executions in MLRun are based on Serverless Functions, the functions allow specifying code and all the operational aspects (image, required packages, cpu/mem/gpu resources, storage, environment, etc.), the different function runtimes take care of automatically transforming the code and spec to fully managed and elastic services over Kubernetes which save significant operational overhead, address scalability and reduce infrastructure costs.
MLRun supports batch functions (based on Kubernetes jobs, Spark, Dask, Horovod, etc.) or Real-time functions for serving, APIs, and stream processing (based on the high-performance Nuclio engine).
Further reading:
MLRun docs
Function runtimes
Nuclio docs
A structure of configuration resembles the Kubernetes resource definitions, and includes the apiVersion, kind, metadata, spec, and status sections. This file is the result of running:
import mlrun
fn = mlrun.code_to_function(...)
fn.export()
Further reading:
Code to function
Function configuration
Deploying functions
The function marketplace is a user-friendly representation of the mlrun/functions
repository. The
main purpose of the Function Marketplace is to provide a simple (yet interactive) and explorable interface for users to
find, filter and discover MLRun functions. It is partially inspired by the helm’s ArtifactHub.
Further reading:
Visit Function Marketplace
Helm Chart Artifact Hub
A structure of configuration that enables:
- Generating a
function.yaml
without introducing any configuration in the example notebook - Allows the function to be listed on the marketplace
This is a suggested function structure, deviating from this structure template will cause issues with marketplace rendering.
<FUNCTION_NAME>
|
|__ <FUNCTION_NAME>.py (Containing the implementation code of FUNCTION_NAME)
|
|__ <FUNCTION_NAME>.ipynb (Containing an example for running and deploying the FUNCTION_NAME)
|
|__ item.yaml (Containing the spec for generating function.yaml and being listed on the marketplace)
|
|__ function.yaml (Containing the spec for deploying the function)
|
|__ test_<FUNCTION_NAME>.py (optional)
|
|__ test_<FUNCTION_NAME>.ipynb (optional)
apiVersion: v1
categories: [] # List of category names
description: '' # Short description
example: '' # Path to examole notebook
generationDate: # Automatically created when creating a new item using the cli
hidden: false # Hide function from the UI
icon: '' # Path to icon file
labels: {} # Key values label pairs
maintainers: [] # List of maintainers
mlrunVersion: '' # Function’s MLRun version requirement, should follow python’s versioning schema
name: '' # Function name
platformVersion: '' # Function’s Iguazio version requirement, should follow python’s versioning schema
spec:
filename: '' # Implementation file
handler: '' # Handler function name
image: '' # Base image name
kind: '' # Function kind
requirements: [] # List of Pythonic library requirements
customFields: {} # Key value pairs of custom spec fields
env: [] # Spec environment params
version: 0.0.1 # Function version, should follow the standard semantic versioning schema
The table below represents the available options to choose from when filling item.yaml
's categories
property. Please
select one or more categories and feel free to suggest additional options.
Name | How should it be written in item.yaml | When should i choose this category? |
---|---|---|
Data Preparation | data-preparation | A function that prepares, cleans or otherwise processes data in any other number of ways |
Extract, Transform, Load | etl | A function that can be used to take data from some source, transforms it and finally load it to some destination |
Machine Learning | machine-learning | A function that is related to machine learning in any way, can be used along-side categories like Data Preparation, Model Training, Model Serving |
Model Serving | model-serving | A function that can be used to serve models via V2ModelServer |
Model Training | model-training | A function that can be used for training Machine Learning models |
Model Testing | model-testing | A function that can be used to test trained models |
Data Analysis | data-analysis | A function that can be used to preform analysis and exploration on data |
Deep Learning | deep-learning | A function that can be used to teaches computers to process data in a way that is inspired by the human brain |
Monitoring | monitoring | A function that can be used to monitor and/or measure metrics regarding data, models and model endpoints |
Utilities | Utilities | A function that is used to alert, notify or provide services in any way |
It is highly advised using the functions package in a dedicated environment, since Pipenv is used as part of the testing routine, conda can be used instead.
- Install miniconda (or any other environment manager)
- Clone the repository
git clone https://github.com/mlrun/functions.git
- cd to the functions directory
cd functions
- Create a new environment
conda install -n functions python=3.8
- Activate the environment
source activate functions
- Install the requirements
pip install -r requirements.txt
See command line utility > section 6
See function directory structure
See testing functions
-
Fork the
mlrun/functions
repository -
Open a branch with a name describing the function that is being changed, and what was changed
* Make sure to update the version of the function in the
item.yaml
* If any business logic changed, make to update thefunction.yaml
by running thepython function.py item-to-function [OPTIONS]
command -
Submit a PR
(WORK IN PROGRESS)
The command line utility supports multiple sub-commands:
- Help
python functions.py --help
Usage: functions.py [OPTIONS] COMMAND [ARGS]...
Options:
--help Show this message and exit.
Commands:
build-marketplace
create-legacy-catalog
function-to-item
item-to-function
new-item
run-tests
- Build Functions build-marketplace
python functions.py build-docs
Usage: functions.py build-marketplace [OPTIONS]
Options:
-s, --source-dir TEXT Path to the source directory
-sn, --source-name TEXT Name of source, if not provided, name of source directory will be used instead (optional)
-m, --marketplace-dir TEXT Path to marketplace directory
-T, --temp-dir TEXT Path to intermediate build directory (optional)
-c, --channel TEXT Name of build channel
-v, --verbose When this flag is set, the process will output extra information (optional)
--help Show this message and exit.
- Create Legacy Catalog
python functions.py create-legacy-catalog
Usage: functions.py create-legacy-catalog [OPTIONS]
Options:
-r, --root-dir TEXT Path to root project directory
--help Show this message and exit.
- Item To Function
python functions.py item-to-function
Usage: functions.py item-to-function [OPTIONS]
Options:
-i, --item-path TEXT Path to item.yaml file or a directory containing one
-o, --output-path TEXT Path to code_to_function output, will use item-path directory if not provided (optional)
-c, --code_output If spec.filename or spec.example is a notebook, should a python file be created (optional)
-fmt, --format_code If -c/--code_output is enabled, and -fmt/--format is enabled, the code output will be
formatted by black formatter (optional)
--help Show this message and exit.
- Function To Item
python functions.py function-to-item
Usage: functions.py function-to-item [OPTIONS]
Options:
-p, -path TEXT Path to one of: specific function.yaml, directory containing function.yaml or a root directory to
search function.yamls in
--help Show this message and exit.
- New Item
python functions.py new-item
Usage: functions.py new-item [OPTIONS]
Options:
-p, --path TEXT Path to directory in which a new item.yaml will be created
-o, --override Override if already exists
--help Show this message and exit.
This sub command will create a directory (if doesn't exist already) with a copy the item.yaml template.
-o/--override
can be used to override an existing item.yaml.
- Test Suite
python functions.py run-tests
-r, --root-directory TEXT Path to root directory
-s, --suite TEXT Type of suite to run [py/ipynb/examples/items]
-mp, --multi-processing TEXT run multiple tests
-fn, --function-name TEXT run specific function by name
-f, --stop-on-failure When set, the test entire test run will fail once a single test fails
--help Show this message and exit.