Skip to main content

ml-adapter base classes.

Project description

waylay-ml-adapter-base

Provides the ml_adapter.base module for the Waylay ML Adapter solution.

To use an ML Adapter in a Waylay plugin or webscript, use the adapter relevant to your machine learning framework:

This waylay-ml-adapter-base module provides the framework for these adapters. Only if you would need to create an adapter utility for another framework, you would install this module separately:

pip install waylay-ml-adapter-base

Exported classes

This module exports the following classes:

ml_adapter.base.ModelAdapter

Model Adapter base.

Provides the basic contract for exposing a model to a waylay plugin or webscript.

  • delegates to a marshaller to map the remote, json-compatible python data structures from and to the native tensor data structures for the ML framework.
  • delegates to a invoker to find the model method to be called
  • the call method maps remote requests and invokes the model method
  • the call_remote method tests the round trip serialization, encoding native data request to remotable and back before invoking call

ml_adapter.base.TensorModelAdapter

Model adapter that uses (dicts of) tensors as inputs and outputs.

Requests are mapped to the model invocation using named parameters, falling back to mapping the "main" entry to the first positional parameter.

ml_adapter.base.WithAssets

Mixin for a configuration backed by assets.

Manages assets of the the plugin or webscript.

Used read-only within a deployed adapter to e.g. load the model definition.

Used read/write within the ml_tool to edit the assets of a plugin or webscript.

ml_adapter.base.WithManifest

Mixin for a configuration that has a waylay function manifest file and script.

Adds methods to a WithAssets adapter to manage the function manifest of waylay plugin or webscript.

  • manifest returns the manifest asset of the function archive at plug.json or webscript.json.
  • as_webscript() initializes the manifest and script for a webscript that uses an ML Adapter.
  • as_plug() initializes the manifest and script for a rule plugin that uses an ML Adapter.

ml_adapter.base.WithOpenapi

Mixin for a configuration that has an openapi description.

Adds methods to a WithAssets adapter to manage the openapi description of waylay plugin or webscript.

  • openapi returns an asset of type OpenApiAsset (normally at openapi.json)

ml_adapter.base.WithPython

Handles assets specific to python-based functions.

  • requirements handles the dependency file (at requirements.txt)
  • lib handles the libraries that are uploaded with the function archive itself. (at lib/*.tar.gz)
  • main_script handles the main script of the function (main.py)
  • scripts handles other utility scripts of the function (*.py)

ml_adapter.base.WithModel

Holder of model assets.

Adds methods to a WithAssets adapter to manage the model instance. A model can either be:

  • given as model in the constructor of the adapter
  • loaded from model_path in the assets
  • loades from model_path using a model_class

The MODEL_ASSET_CLASSES configured on the adapter define the methods to load a model. Defaults are

  • DillModelAsset
  • JoblibModelAsset
  • SelfSerializingModelAsset

ml_adapter.base.SelfSerializingModelAsset

Model asset with own serialization methods.

Reads/writes the model from model.sav using the save and load methods defined on the model_class.

ml_adapter.base.DillModelAsset

Model asset for dill-serialized models.

Reads/writes the model from paths like model.dill, model.pkl, model.pickle using dill serialisation.

ml_adapter.base.JoblibModelAsset

Model asset with joblib serialization.

Reads/writes the model from model.joblib or model.joblib.gz using joblib serialisation.

ml_adapter.base.Marshaller

Abstract base class to marshall inference requests and responses.

Methods used to invoke the model in a plugin or webscript:

  • map_request() maps remote requests (generic type RREQ) to native requests (generic type MREQ)
  • map_response() maps native responses (generic type MRES) to remote a response (generic type RRES)

Methods used to test roundtrip encoding in a client:

  • encode_request() encodes a native request to a remote request that can be sent to a waylay function.
  • decode_response() decodes a remote response from a function to native a response.

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

waylay_ml_adapter_base-0.0.5.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

waylay_ml_adapter_base-0.0.5-py3-none-any.whl (33.9 kB view details)

Uploaded Python 3

File details

Details for the file waylay_ml_adapter_base-0.0.5.tar.gz.

File metadata

File hashes

Hashes for waylay_ml_adapter_base-0.0.5.tar.gz
Algorithm Hash digest
SHA256 6907b5c41981634d91d336ba4f5d90bd2d7f989afafe731916be02da0ec32bb1
MD5 e96086a681df037d47c046c5e4712890
BLAKE2b-256 7be963764f7db72bb42c34021ce0773b3fb6b9fb278048476d408b48f730a318

See more details on using hashes here.

File details

Details for the file waylay_ml_adapter_base-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for waylay_ml_adapter_base-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8c90e7c6684054e51b1f3b384027121b7d18c4692b4445408f09c95e1020d037
MD5 a83eac1fd89b613d3e89205d4e091e10
BLAKE2b-256 585055e61faa10151df7cfe0e5043a05d60ba7d42370544b0b2b2c0993f8958a

See more details on using hashes here.

Supported by

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