Skip to main content

Machine learning microservices based on gRPC

Project description

Aigear

Aigear is an MLOps work orchestration framework that is serverless and aims to help you build pipelines more quickly. It will not change the programming style of Python and provides an optimized out-of-the-box toolbox.

Aigear believes that everything is a task, and it allows you to make any extensions according to the task. Within Aigear, it performs topology analysis on tasks to achieve optimal parallel execution.

You need to note that aigear only executes functions created by yourself in parallel.

Getting started

Aigear requires Python 3.8 or later. To install the latest or upgrade to the latest version of Aigear, run the following command:

pip install -U aigear

With just two decorators(@task and @workflow), you can create a pipeline. Please refer to /aigear/example/pipeline.

Here is an example of iris classification:

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from aigear.pipeline import workflow, task
import pickle
import json
import os


@task
def load_data():
    iris = load_iris()
    return iris


@task
def split_dataset(iris):
    X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=42)
    return X_train, X_test, y_train, y_test


@task
def fit_model(X_train, y_train):
    clf = LogisticRegression(random_state=0, max_iter=1000, solver="lbfgs")
    model = clf.fit(X_train, y_train)
    return model


@task
def evaluate(clf, X_test, y_test):
    y_pred = clf.predict(X_test)
    accuracy = accuracy_score(y_test, y_pred)
    return y_pred, accuracy


@task
def get_env_variables():
    with open("env.json", "r") as f:
        env = json.load(f)
    model_path = env.get("grpc", {}).get("servers", {}).get("demo", {}).get("modelPath")
    return model_path


@task
def save_model(model, model_path):
    with open(model_path, "wb") as md:
        pickle.dump(model, md)


@workflow
def my_pipeline():
    iris = load_data()
    X_train, X_test, y_train, y_test = split_dataset(iris)
    model = fit_model(X_train, y_train)
    y_pred, accuracy = evaluate(model, X_test, y_test)
    print("accuracy:", accuracy)

    model_path = get_env_variables()
    save_model(model, model_path)


if __name__ == '__main__':
    # # Run the pipeline directly
    # my_pipeline()
    
    # Run pipeline in parallel
    my_pipeline.run_in_executor()

Similarly, the task can also be executed in two ways.

if __name__ == "__main__":
    # # Run the pipeline directly
    # load_data()
    
    # Run pipeline in parallel
    load_data.run_in_executor()

If you want to deploy a pipeline or create a model service in local docker, it's quite simple.

if __name__ == '__main__':
    current_directory = os.getcwd()
    volumes = {
        current_directory: {'bind': "/pipeline", 'mode': 'rw'}
    }
    hostname = "demo-host"
    ports = {'50051/tcp': 50051}
    service_dir = "demo"

    my_pipeline.deploy(
        volumes=volumes,
        skip_build_image=False
    ).to_service(
        hostname=hostname,
        ports=ports,
        volumes=volumes,
        tag=service_dir,
    )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aigear-0.0.1.tar.gz (34.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aigear-0.0.1-py3-none-any.whl (48.4 kB view details)

Uploaded Python 3

File details

Details for the file aigear-0.0.1.tar.gz.

File metadata

  • Download URL: aigear-0.0.1.tar.gz
  • Upload date:
  • Size: 34.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aigear-0.0.1.tar.gz
Algorithm Hash digest
SHA256 dec00b9f46bab1aa4f52cf3dfbfdb364d1c3903574c7fac73fea0befd75d4ee3
MD5 55e348ba4f145fdfd8f579bc322f19d3
BLAKE2b-256 1c52224a230b0ccacf28a5a77db47d7c0447a36e7271000acaa3108e4beb3382

See more details on using hashes here.

Provenance

The following attestation bundles were made for aigear-0.0.1.tar.gz:

Publisher: publish.yml on retail-ai-inc/aigear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aigear-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: aigear-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 48.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aigear-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62966da5f4412e957833a71078ec4f51792904c104bdbda3397cd05fefc1086d
MD5 4a137dd986e796435542b140303db672
BLAKE2b-256 7ce2ef756e827d021f6cb408e0899ee4495431fc1ab94ff6923b04b07787ed74

See more details on using hashes here.

Provenance

The following attestation bundles were made for aigear-0.0.1-py3-none-any.whl:

Publisher: publish.yml on retail-ai-inc/aigear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page