Skip to main content

Modelzone SDK – a slim model training and serving toolkit

Project description

ModelZone SDK

A Python package for managing, training, and installing machine learning models. The package consists of:

  • A Python SDK used for writing the code for training and inference of a machine learning model.
  • A CLI used for tracking and registration of models in Azure ML.

Installation

pip install modelzone-sdk

Overview

Taking a look at the various Python machine learning frameworks out there, you will come across many different workflows used for training and prediction. ModelZone SDK uses the following definition:

A model project is a Python package with a training function, which is responsible for (1) tracking metrics and graphs used for comparing different model experiments and (2) generating model artifacts (such as model parameters and hyper-parameters) that need to be shipped with the package.

ModelZone SDK assumes your machine learning workflow looks more or less like the following:

  1. Experimentation by training different models (and hyper-parameters).
  2. Release of the best suited model for production usage.
  3. Using the released model for inference in operations.

alt text


Quick guide

We have made an example of how a training and inference project should look like:


Detailed guide

Model project structure

Training function

Your training function must be defined within the Python package:

# my-model/model.py
def train():
    X, y = ...
    lin_reg = LinearRegression()
    lin_reg.fit(X, y)

Tracking

If you have experience with the built-in logging module of Python, tracking experiment data with ModelZone SDK will feel much the same. Tracking is done using a global tracker, which needs to be configured before running your code (when using the CLI tool, this takes care of configuring your tracker to log to the correct place; local or Azure AI Workspace).

Metrics and visualziation

The tracker can be used for logging metrics and visualizations for your experiment run:

# my-model/model.py
import modelzone as mz

tracker = mz.get_tracker()

def train():
    X, y = ...
    lin_reg = LinearRegression()
    tracker.log_tag("model_type", "LinearRegression")
    lin_reg.fit(X, y)
    y_hat = lin_reg.predict(X)
    mae = (y - y_hat).abs().mean()
    tracker.log_metric("MAE", mae)

The tracker can also be used for logging artifacts for your experiment run (e.g. model parameters). You define an artifact by inheriting from the Artifact class available in ModelZone SDK (all this does is to provide methods for saving and loading the class using the pickle module):

# my-model/model.py
import modelzone as mz

tracker = mz.get_tracker()

class Predictor(mz.Artifact):

    def __init__(self, model: Estimator):
        self.model = model

    def predict(self, ...):
        ...

def train():
    X, y = ...
    lin_reg = LinearRegression()
    lin_reg.fit(X, y)
    predictor = Predictor(lin_reg)
    tracker.log_artifact("my-artifact", predictor)

When installing this package elsewhere, you can now get back the artifact as follows:

from mypackage import Predictor

predictor = Predictor.load(name="my-artifact")

Logging

ModelZone SDK allows for logging various items to your experiment run.

Metrics

You can log a single metric as follows

tracker.log_metric("MAE", 1.23)

You can also log multiple related metrics (e.g. the same metric but with varying context):

tracker.log_metric("MAE", 1.23, dimensions={"country": "DK"})
tracker.log_metric("MAE", 4.56, dimensions={"country": "SE"})

These will be visualized a Plotly table when tracking to Azure ML:

alt text

Figures

You can log a single figure as follows:

tracker.log_figure(
    name="Errors",
    figure=px.histogram(x=[1, 2, 2, 3, 3, 3]),
)

You can also log multiple related figures (e.g. the same figure but with varying context):

tracker.log_figure(
    name="Errors",
    figure=px.histogram(x=[1, 2, 2, 3, 3, 3]),
    dimensions={"country": "DK"}
)
tracker.log_figure(
    name="Errors",
    figure=px.histogram(x=[4, 4, 5, 5, 5, 6]),
    dimensions={"country": "SE"}
)

These will be visualized a Plotly figure with dropdown selection when tracking to Azure ML:

alt text

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

modelzone_sdk-3.0.2.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

modelzone_sdk-3.0.2-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file modelzone_sdk-3.0.2.tar.gz.

File metadata

  • Download URL: modelzone_sdk-3.0.2.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.13 Linux/6.17.0-1010-azure

File hashes

Hashes for modelzone_sdk-3.0.2.tar.gz
Algorithm Hash digest
SHA256 fb8ff65977ab2b2f94b30a980a7d76091db733cba996e255d1c583d8c4854778
MD5 5deef54767ddc31b0a7314fd1ad42df6
BLAKE2b-256 042b504a3a9391f7c2b557c0896e9153776ec72bde4b0837a629ddb002ea521e

See more details on using hashes here.

File details

Details for the file modelzone_sdk-3.0.2-py3-none-any.whl.

File metadata

  • Download URL: modelzone_sdk-3.0.2-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.13 Linux/6.17.0-1010-azure

File hashes

Hashes for modelzone_sdk-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 18e6f0fcf0d0353d9c7a6f1266260c5216cbc2bd863cd5cb0c61cf884cc81806
MD5 d3a975b5f90ba84972e354a45e3ac7de
BLAKE2b-256 d632a9cd23b6c815b07b6f3074995a1d69443c2f500d63ede08a6c635b39ca27

See more details on using hashes here.

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