Model router for ML systems
Project description
README for Magic-Carpet Python Package
Overview
Magic-Carpet is a versatile Python package that enables users to easily manage and deploy multiple model endpoints. It is designed to streamline the process of handling various machine learning models by providing a unified interface. With Magic-Carpet, users can create a customized router to dynamically choose which model to use based on the input, allowing for more efficient and targeted model inference.
Features
- Multiple Model Management: Easily spin up and manage multiple model endpoints using the
NamedModelclass. - Customized Routing: Design a customized router to decide per-input which model endpoint to hit.
- Dynamic Model Selection: Dynamically route requests to different models based on the input data.
- Ease of Integration: Simple integration with existing Python applications and machine learning workflows.
- Extensive Documentation: Includes detailed examples and use cases in
examples/.
Installation
To install Magic-Carpet, simply run:
pip install magic-carpet
Usage
Setting Up Models
Use the NamedModel class to define and spin up your model endpoints:
from magic_carpet import NamedModel
# Define models
foo = NamedModel(name="foo", function=lambda x: x + 1)
bar = NamedModel(name="bar", function=lambda y: 2 * y)
print(foo(1), bar(2)) # 2, 4
Customizing the Router
Subclass the NamedRouter class to create a customized router for dynamic model selection:
from magic_carpet import NamedRouter
class CustomRouter(NamedRouter):
def route(self, input, custom_arg):
# Implement logic to choose model based on input_data
if (custom_arg is not None) and input > 0:
return self.models["foo"]
return self.models["bar"]
# Initialize the router
foobar_router = CustomRouter([foo, bar])
Running the Router
The router itself is an instance of NamedModel and thus can be called just like you would a NamedModel
# Process an input
print(foobar_router(5, custom_arg="hello"), foobar_router(-1)) # 6, -2
Running Evaluations
We also provide util functions to test out multiple models over various evalaution functions. To learn more about this please refer to examples/testing/example.ipynb.
Examples
For a comprehensive guide and examples on how to use Magic-Carpet, please refer to the Jupyter notebooks in examples/ included in the package. These notebook provides more detailed instructions and use-cases for using this package.
Support
For issues, questions, or contributions, please refer to the GitHub repository: Magic-Carpet GitHub.
License
Magic-Carpet is released under the MIT License. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file magic_carpet-0.2.0.tar.gz.
File metadata
- Download URL: magic_carpet-0.2.0.tar.gz
- Upload date:
- Size: 29.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Darwin/21.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcca5d786b4ec56c6dd1b24543c6c52c532932bcdfc23a4aae065fb67710a44e
|
|
| MD5 |
015f8aac080ad961f18808dcfaa13e14
|
|
| BLAKE2b-256 |
490a8952b834c3c5beb11f5335cf79cabf7ea52ee798a2de02f4add8fda20f2b
|
File details
Details for the file magic_carpet-0.2.0-py3-none-any.whl.
File metadata
- Download URL: magic_carpet-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Darwin/21.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3634e1f69689e991abaad3b701ab497d8389cb703a117085470b179da1014c49
|
|
| MD5 |
e0553fa67b1c1b03ec4dd5eabe2f9d0e
|
|
| BLAKE2b-256 |
8d7e05f1e377f85606249357248adb31c179028aa6ffe852e02bfe3d0bc07a4a
|