Toolkit for developing and maintaining ML models

Overview

Logo

modelkit

Python framework for production ML systems.


modelkit is a minimalist yet powerful MLOps library for Python, built for people who want to deploy ML models to production.

It packs several features which make your go-to-production journey a breeze, and ensures that the same exact code will run in production, on your machine, or on data processing pipelines.

Quickstart

modelkit provides a straightforward and consistent way to wrap your prediction code in a Model class:

from modelkit import Model

class MyModel(Model):
    def _predict(self, item):
        # This is where your prediction logic goes
        ...
        return result

Be sure to check out our tutorials in the documentation.

Features

Wrapping your prediction code in modelkit instantly gives acces to all features:

  • fast Model predictions can be batched for speed (you define the batching logic) with minimal overhead.
  • composable Models can depend on other models, and evaluate them however you need to
  • extensible Models can rely on arbitrary supporting configurations files called assets hosted on local or cloud object stores
  • type-safe Models' inputs and outputs can be validated by pydantic, you get type annotations for your predictions and can catch errors with static type analysis tools during development.
  • async Models support async and sync prediction functions. modelkit supports calling async code from sync code so you don't have to suffer from partially async code.
  • testable Models carry their own unit test cases, and unit testing fixtures are available for pytest
  • fast to deploy Models can be served in a single CLI call using fastapi

In addition, you will find that modelkit is:

  • simple Use pip to install modelkit, it is just a Python library.
  • robust Follow software development best practices: version and test all your configurations and artifacts.
  • customizable Go beyond off-the-shelf models: custom processing, heuristics, business logic, different frameworks, etc.
  • framework agnostic Bring your own framework to the table, and use whatever code or library you want. modelkit is not opinionated about how you build or train your models.
  • organized Version and share you ML library and artifacts with others, as a Python package or as a service. Let others use and evaluate your models!
  • fast to code Just write the prediction logic and that's it. No cumbersome pre or postprocessing logic, branching options, etc... The boilerplate code is minimal and sensible.

Installation

Install with pip:

pip install modelkit
Comments
  • NamedTuple Error with python 3.9.5

    NamedTuple Error with python 3.9.5

    I had this error running pytest in python 3.9.5

      File "/Users/clemat/.pyenv/versions/3.9.5/lib/python3.9/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
      File "/Users/clemat/.pyenv/versions/3.9.5/envs/modelkit/lib/python3.9/site-packages/_pytest/assertion/rewrite.py", line 170, in exec_module
        exec(co, module.__dict__)
      File "/Users/clemat/dev/modelkit/tests/assets/conftest.py", line 18, in <module>
        from modelkit.assets.manager import AssetsManager
      File "/Users/clemat/dev/modelkit/modelkit/__init__.py", line 3, in <module>
        from modelkit.core.library import ModelLibrary, load_model  # NOQA
      File "/Users/clemat/dev/modelkit/modelkit/core/__init__.py", line 1, in <module>
        from modelkit.core.library import ModelLibrary, load_model
      File "/Users/clemat/dev/modelkit/modelkit/core/library.py", line 35, in <module>
        from modelkit.core.model import Asset, AsyncModel, Model
      File "/Users/clemat/dev/modelkit/modelkit/core/model.py", line 31, in <module>
        from modelkit.utils.cache import Cache, CacheItem
      File "/Users/clemat/dev/modelkit/modelkit/utils/cache.py", line 15, in <module>
        class CacheItem(NamedTuple, Generic[ItemType]):
      File "/Users/clemat/.pyenv/versions/3.9.5/lib/python3.9/typing.py", line 1881, in _namedtuple_mro_entries
        raise TypeError("Multiple inheritance with NamedTuple is not supported")
    TypeError: Multiple inheritance with NamedTuple is not supported
    ======================================================================================= short test summary info ========================================================================================
    ERROR  - TypeError: Multiple inheritance with NamedTuple is not supported
    
    opened by CyrilLeMat 8
  • Pickable storage driver clients

    Pickable storage driver clients

    Hi !

    This PR aims at adding a way to pickle the ModelLibrary which, for the moment, is impossible due to storage drivers (especially boto3 and gcs).

    It introduces a MODELKIT_LAZY_DRIVER environment variable which, if set, will prevent the Storage Providers from storing the drivers (boto3, gcs, azure), instead, the configuration settings will be stored allowing the corresponding Storage Provider to build it on the fly.

    This will make way easier the use of python libraries which use pickle such as Apache Spark and multi-processing, leveraging modelkit.

    Thanks for reviewing, as always!

    opened by antoinejeannot 7
  • configurations: allow models without CONFIGURATIONS dict

    configurations: allow models without CONFIGURATIONS dict

    Tired of having to add empty CONFIGURATIONS attributes to your models?

    Look no further, in this PR, I introduce what I think is a neat little feature for Models. Whenever there is no CONFIGURATIONS dict defined, the model will still be available with a name corresponding to its class name, but snaked case.

    So,

    from modelkit import Model, ModelLibrary
    
    class ModelWithoutConfig(Model):
        def _predict(self, item):
            return item
    
    library = ModelLibrary(models=ModelWithoutConfig)
    model = library.get("model_without_config")
    

    This is much better, in particular because unless the type is specified fully, mypy will complain, so the current alternative is much more verbose:

    class ModelWithoutConfig(Model):
        CONFIGURATIONS : Dict[str, Any] = {
            "model_without_config": {}
        }
    
        def _predict(self, item):
            return item
    
    

    What do you think?

    opened by victorbenichoux 6
  • docs: add NLP x Sentiment Analysis tutorial

    docs: add NLP x Sentiment Analysis tutorial

    In this draft, I propose an overview of most Modelkit's features, by solving a Sentiment Analysis problem.

    I am pretty sure they are still typos, but they will be fixed anytime soon!

    Looking forward to having your opinion on this.

    documentation 
    opened by antoinejeannot 6
  • Assets azure

    Assets azure

    In this PR I add support for assets stored in Azure blob storage. It's relatively simple, since I only need to correctly implement the driver in assets/drivers/azure.py.

    The rest follows: I add an assets manager fixture in tests/assets/conftest.py, and then duplicate a bunch of tests using the same approach as for other drivers.

    opened by victorbenichoux 5
  • Support usage of inheritance for model definitions

    Support usage of inheritance for model definitions

    After change done in #123,

    Abstract base model that were previously bypassed during configure step because of missing CONFIGURATIONS dict are now considered as valid Model to load.

    Hence breaking usage where those Abstract base model are part of the same module than the Concrete derived model and we decide to load full python module.

    With this change modelkit can support this use-case with small adaptation of client code:

    class YourABCModel(AbstractMixin, Asset):
        ...
    
    class YourDerivedModel(ConcreteMixin, YourABCModel):
       ...
    

    Doing so will ensure ABC model are again bypassed by configure step but not the Derived model.

    opened by ldeflandre 4
  • Improve model describe method with load time and memory including dependencies

    Improve model describe method with load time and memory including dependencies

    I noticed a model _load_time and _load_memory_increment doesn't include its dependencies info. It makes sense but I feel that, as we push for composable models, it is more informative to cumulate the model data if all of its dependencies. @victorbenichoux what do you think? Is there a specific need to get the model load time and memory without its dependencies?

    opened by CyrilLeMat 4
  • Assets versioning with dates

    Assets versioning with dates

    As of today, assets can only be versioned with numbers (eg: 1.4) https://cornerstone-ondemand.github.io/modelkit/assets/managing_assets/

    Modelkit should support date versionning (eg: 2021-10-16) to support organisations where models are trained on a monthy/weekly/daily basis

    opened by CyrilLeMat 4
  • Add tests configurations

    Add tests configurations

    This PR aims at introducing test_cases in the CONFIGURATIONS map defined at class level, so that to be able to write tests restricted to a given model.

    Moreover, TEST_CASES is now the way to go if you want to define upper-level class tests, which will be ran for every model configuration.

    E.g.:

    class TestableModel(Model[ModelItemType, ModelItemType]):
        CONFIGURATIONS: Dict[str, Dict] = {
            "some_model_a": { 
                "test_cases": {
                    "cases": [
                        {"item": {"x": 1}, "result": {"x": 1}},
                        {"item": {"x": 2}, "result": {"x": 2}},
                    ],
                }
            },
            "some_model_b": {},
        }
        def _predict(self, item):
            return item
    

    Thanks for reviewing

    opened by antoinejeannot 4
  • click 8.1.0 breaks spaCy 3.2.3

    click 8.1.0 breaks spaCy 3.2.3

    Installing with pip install modelkit spacy results in click 8.1.0 and spacy 3.2.3 being installed. But click 8.1.0 contains a breaking change and is incompatible with spaCy 3.2.3 (https://github.com/explosion/spaCy/issues/10564).

    Until updated spaCy is realeased, you need to install with pyenv exec pip install modelkit spacy "click==8.0.4"

    opened by mihaimm 3
  • Enable assets manager to run on read-only filesystem when assets do not need to be downloaded

    Enable assets manager to run on read-only filesystem when assets do not need to be downloaded

    Current state

    During asset creation development process, or if you want to embed assets in a container at build time, Modelkit can be configured to use StorageProvider with LocalStorageDriver and a AssetsDir pointing to the same location of the LocalStorage. This allow to only use local file and do not duplicate them on local file system.

    However, modelkit still requires to have write permission on the filesystem because the management of lock files is not disabled in this condition.

    Fix

    Idea is to disable the lock files management in this configuration. It is fine to do that since we are guaranteed that we will not download anything in this configuration

    opened by ldeflandre 3
  • Ignore modules in library search path

    Ignore modules in library search path

    Sometimes it makes sense to group helper utilities together in in the library search path.

    However, we don't always want these files to be loaded if for example the model itself is not used.

    • The problem is that modelkit traverses and loads all python modules in the search path. It would be useful to be able to skip over specific files.

    This could maybe be done with a common naming convention, for example prefixing files that should be ignored with some standard prefix, eg. library._my_module would be ignored and skipped over (this follows private convention, with the underscore indicating a module that should not be exposed publicly), while library.my_module would be traversed and loaded.

    opened by nmichlo 0
  • Warn or raise Exception when 2 models have the same name

    Warn or raise Exception when 2 models have the same name

    If 2 models have the same configuration name, modelkit will silently use one of them.

    It should at least warn the user but maybe we just want to raise an Exception ?

    enhancement 
    opened by tgenin 0
  • Handle breaking batch behaviour options

    Handle breaking batch behaviour options

    Currently breaking a prediction_batch example, breaks the call and raise the error

    we may want another option like (for example) returning all the batches returns except the breaking ones (set to none or set to the Exception) and a mask or something like that

    enhancement 
    opened by tgenin 0
  • Be able to push assets directly from remote storage to remote storage (for s3)

    Be able to push assets directly from remote storage to remote storage (for s3)

    Currently asset new or asset update push data from local to MODELKIT_STORAGE_PROVIDER

    https://cornerstone-ondemand.github.io/modelkit/assets/managing_assets/#create-a-new-asset

    which mean asset must be on local storage to be pushed

    It could be interesting to be able to directly push asset from remote to remote without writing on local disk

    Note: the feature seems to be partially for gcs but it just download locally to repush :

    https://github.com/Cornerstone-OnDemand/modelkit/blob/6e71fe78155887fd349df4907b3633ade72d565c/modelkit/assets/cli.py#L201

    (idk if it still works)

    So maybe at least implement an automatic redownload + push for s3

    Or better find a way to do it directly (idk if it is possible at least with 2 remotes with same credentials)

    enhancement 
    opened by tgenin 0
Releases(v0.0.25)
  • v0.0.25(Sep 1, 2022)

    What's Changed

    • Make asset requirements for remote storage optional #167
    • tf_serving_fixture expects a new parameter: version of the tensorflow/serving image (used to be pinned to v2.4.0) #162

    This version contains breaking changes:

    • if you are using a remote storage, check this part of the documentation to understand the new optional dependencies.

    Full Changelog: https://github.com/Cornerstone-OnDemand/modelkit/compare/v0.0.24...v0.0.25

    Source code(tar.gz)
    Source code(zip)
  • v0.0.24(Jun 29, 2022)

  • v0.0.21(Jan 17, 2022)

    What's Changed

    • Support python 3.10 by @tbascoul in https://github.com/Cornerstone-OnDemand/modelkit/pull/130

    New Contributors

    • @tbascoul made their first contribution in https://github.com/Cornerstone-OnDemand/modelkit/pull/130

    Full Changelog: https://github.com/Cornerstone-OnDemand/modelkit/compare/v0.0.20...v0.0.21

    Source code(tar.gz)
    Source code(zip)
  • v0.0.20(Jan 6, 2022)

    What's Changed

    • Support usage of inheritance for model definitions by @ldeflandre in https://github.com/Cornerstone-OnDemand/modelkit/pull/128
    • Intuitive abstract support by stopping support of no CONFIGURATIONS by @ldeflandre in https://github.com/Cornerstone-OnDemand/modelkit/pull/129

    Full Changelog: https://github.com/Cornerstone-OnDemand/modelkit/compare/v0.0.19...v0.0.20

    Source code(tar.gz)
    Source code(zip)
  • v0.0.19(Dec 20, 2021)

    What's Changed

    • configurations: allow models without CONFIGURATIONS dict by @victorbenichoux in https://github.com/Cornerstone-OnDemand/modelkit/pull/123
    • Raise ModelsNotFound exception when Model is not found by @tgenin in https://github.com/Cornerstone-OnDemand/modelkit/pull/125
    • Enable read-only filesystem when assets do not need to be downloaded by @ldeflandre in https://github.com/Cornerstone-OnDemand/modelkit/pull/127

    New Contributors

    • @ldeflandre made their first contribution in https://github.com/Cornerstone-OnDemand/modelkit/pull/127

    Full Changelog: https://github.com/Cornerstone-OnDemand/modelkit/compare/v0.0.18...v0.0.19

    Source code(tar.gz)
    Source code(zip)
  • v0.0.18(Dec 9, 2021)

    This release includes:

    • a fix to be able to install and use modelkit on apple silicon https://github.com/Cornerstone-OnDemand/modelkit/issues/119
    • a new storage driver to support azure blob storage
    Source code(tar.gz)
    Source code(zip)
  • v0.0.17(Nov 30, 2021)

  • v0.0.16(Nov 17, 2021)

  • v0.0.11(Jun 24, 2021)

    • validation of downloads in ASSETS_DIR with .SUCCESS files
    • MODELKIT_STORAGE_FORCE_DOWNLOAD to force download of remote assets
    • MODELKIT_STORAGE_TIMEOUT to control timeout on storage download lock
    • Improved debug level logs when fetching assets
    Source code(tar.gz)
    Source code(zip)
  • v0.0.2(Jun 7, 2021)

    This is quite a major update, with numerous breaking changes.

    • separated sync and async Models for clarity (https://github.com/clustree/modelkit/pull/10)
    • reworked batching predict logic: predict no longer automatically switches between single items and batches. Model.predict takes single items, predict_batch only accepts lists of items, and predict_gen knows how to deal with generators (https://github.com/clustree/modelkit/pull/15, https://github.com/clustree/modelkit/pull/16, https://github.com/clustree/modelkit/pull/19, https://github.com/clustree/modelkit/pull/20)
    • caching with native python caches now available (https://github.com/clustree/modelkit/pull/22, https://github.com/clustree/modelkit/pull/23)
    • documentation improvements
    Source code(tar.gz)
    Source code(zip)
  • v0.0.1(May 28, 2021)

REST API with FastAPI and PostgreSQL

REST API with FastAPI and PostgreSQL To have the same data in db: create table CLIENT_DATA (id SERIAL PRIMARY KEY, fullname VARCHAR(50) NOT NULL,email

Luis Quiñones Requelme 1 Nov 11, 2021
FastAPI IPyKernel Sandbox

FastAPI IPyKernel Sandbox This repository is a light-weight FastAPI project that is meant to provide a wrapper around IPyKernel interactions. It is in

Nick Wold 2 Oct 25, 2021
FastAPI framework plugins

Plugins for FastAPI framework, high performance, easy to learn, fast to code, ready for production fastapi-plugins FastAPI framework plugins Cache Mem

RES 239 Dec 28, 2022
Full stack, modern web application generator. Using FastAPI, PostgreSQL as database, Docker, automatic HTTPS and more.

Full Stack FastAPI and PostgreSQL - Base Project Generator Generate a backend and frontend stack using Python, including interactive API documentation

Sebastián Ramírez 10.8k Jan 08, 2023
Run your jupyter notebooks as a REST API endpoint. This isn't a jupyter server but rather just a way to run your notebooks as a REST API Endpoint.

Jupter Notebook REST API Run your jupyter notebooks as a REST API endpoint. This isn't a jupyter server but rather just a way to run your notebooks as

Invictify 54 Nov 04, 2022
Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.

The Mixer is a helper to generate instances of Django or SQLAlchemy models. It's useful for testing and fixture replacement. Fast and convenient test-

Kirill Klenov 871 Dec 25, 2022
Socket.IO integration for Flask applications.

Flask-SocketIO Socket.IO integration for Flask applications. Installation You can install this package as usual with pip: pip install flask-socketio

Miguel Grinberg 4.9k Jan 03, 2023
A dynamic FastAPI router that automatically creates CRUD routes for your models

⚡ Create CRUD routes with lighting speed ⚡ A dynamic FastAPI router that automatically creates CRUD routes for your models Documentation: https://fast

Adam Watkins 943 Jan 01, 2023
cookiecutter template for web API with python

Python project template for Web API with cookiecutter What's this This provides the project template including minimum test/lint/typechecking package

Hitoshi Manabe 4 Jan 28, 2021
Toolkit for developing and maintaining ML models

modelkit Python framework for production ML systems. modelkit is a minimalist yet powerful MLOps library for Python, built for people who want to depl

140 Dec 27, 2022
A utility that allows you to use DI in fastapi without Depends()

fastapi-better-di What is this ? fastapi-better-di is a utility that allows you to use DI in fastapi without Depends() Installation pip install fastap

Maxim 9 May 24, 2022
fastapi-cache is a tool to cache fastapi response and function result, with backends support redis and memcached.

fastapi-cache Introduction fastapi-cache is a tool to cache fastapi response and function result, with backends support redis, memcache, and dynamodb.

long2ice 551 Jan 08, 2023
Flood Detection with Google Earth Engine

ee-fastapi: Flood Detection System A ee-fastapi is a simple FastAPI web application for performing flood detection using Google Earth Engine in the ba

Cesar Aybar 69 Jan 06, 2023
A FastAPI Plug-In to support authentication authorization using the Microsoft Authentication Library (MSAL)

FastAPI/MSAL - MSAL (Microsoft Authentication Library) plugin for FastAPI FastAPI - https://github.com/tiangolo/fastapi FastAPI is a modern, fast (hig

Dudi Levy 15 Jul 20, 2022
This code generator creates FastAPI app from an openapi file.

fastapi-code-generator This code generator creates FastAPI app from an openapi file. This project is an experimental phase. fastapi-code-generator use

Koudai Aono 632 Jan 05, 2023
Adds simple SQLAlchemy support to FastAPI

FastAPI-SQLAlchemy FastAPI-SQLAlchemy provides a simple integration between FastAPI and SQLAlchemy in your application. It gives access to useful help

Michael Freeborn 465 Jan 07, 2023
This is an API developed in python with the FastApi framework and putting into practice the recommendations of the book Clean Architecture in Python by Leonardo Giordani,

This is an API developed in python with the FastApi framework and putting into practice the recommendations of the book Clean Architecture in Python by Leonardo Giordani,

0 Sep 24, 2022
FastAPI + PeeWee = <3

FastAPIwee FastAPI + PeeWee = 3 Using Python = 3.6 🐍 Installation pip install FastAPIwee 🎉 Documentation Documentation can be found here: https://

16 Aug 30, 2022
Prometheus integration for Starlette.

Starlette Prometheus Introduction Prometheus integration for Starlette. Requirements Python 3.6+ Starlette 0.9+ Installation $ pip install starlette-p

José Antonio Perdiguero 229 Dec 21, 2022
🍃 A comprehensive monitoring and alerting solution for the status of your Chia farmer and harvesters.

chia-monitor A monitoring tool to collect all important metrics from your Chia farming node and connected harvesters. It can send you push notificatio

Philipp Normann 153 Oct 21, 2022