publish()

audmodel.publish(root, name, params, version, *, repository, alias=None, author=None, compression=1, date=None, meta=None, subgroup=None, tmp_root=None, verbose=False)[source]

Zip model and publish as a new artifact.

Before publishing a model, pick meaningful values for name, subgroup, params. The following table explains what the arguments should encode and shows examples.

Encodes

Examples

name

  • package used to train/create the model

  • onnx

  • sklearn

  • torch

subgroup

  • project

  • task the model was trained for

  • model architecture

  • ser.dimensions.wav2vec2

  • age.cnn

params

  • model

  • data

  • feature set

  • sampling rate

  • { ‘model’: ‘facebook/wav2vec2-large’, ‘data’: ‘msppodcast’, ‘sampling_rate’: 16000 }

  • { ‘model’: ‘cnn10’, ‘data’: [‘agender’, ‘emodb’], ‘feature’: ‘log-melspec’, ‘sampling_rate’: 8000 }

The meta argument encodes additional information. In contrast to name, subgroup, params it can be changed later. It should be used to extend information of the params entries using the same keys. In addition, it can store example output, and benchmark results. For example, a meta entry corresponding to the first params example from the table might contain:

{
    'model': {'facebook/wav2vec2-large': {'layers': 24}},
    'data': {'msppodcast': {'version': '2.6.0'}},
}

The model archive is created before any file is published. The header is published last, as it registers the model in the repository. If another process publishes the same model while this publication is in progress, the shared files are intentionally not removed, and a RuntimeError is raised. For all other publication failures, or if publication is interrupted by the user (Ctrl+C) or by SIGTERM, all files that have been published so far are removed from the backend again. If the process is killed (SIGKILL), the connection is lost, or the machine crashes, the files cannot be removed, but as the header is missing, the model is not registered. Publishing the same model again replaces the remaining files.

Parameters:
  • root (str) – folder with model files

  • name (str) – model name

  • params (dict[str, object]) – dictionary with parameters

  • version (str) – version string

  • repository (Repository) – repository where the model will be published

  • alias (str | None) – optional alias name for the model. If provided, the model can be accessed using this alias in addition to its UID

  • author (str | None) – author name(s), defaults to user name

  • compression (int) – compression level of the model archive. 0 stores the model files without compression, 1-9 selects a deflate level. Deflate is single threaded, and dominates the publication time of large models. Higher levels than 1 hardly compress better on model weights, but take at least twice as long. Select 0, if you want to publish as fast as possible

  • date (date | None) – date, defaults to current timestamp

  • meta (dict[str, object] | None) – dictionary with meta information

  • subgroup (str | None) – subgroup under which the model is stored on backend. . are replaced by / on the backend

  • tmp_root (str | None) – folder under which the temporary archive of the model is created before uploading. The folder is created if it does not exist, and is kept afterwards; only the temporary archive inside it is removed when publishing finishes. If None, the system default temporary folder is used

  • verbose (bool) – show debug messages

Return type:

str

Returns:

unique model ID

Raises:
  • ValueError – if repository is None

  • audbackend.BackendError – if connection to repository on backend cannot be established

  • RuntimeError – if a model with same UID exists already

  • RuntimeError – if a model with same UID was published by another process in the meantime. In this case, files of the other publication might have been replaced by the ones of this process

  • RuntimeError – if an unexpected error occurs during publishing

  • RuntimeError – if meta or params cannot be serialized to a YAML file

  • ValueError – if subgroup is set to '_uid'

  • FileNotFoundError – if root folder cannot be found

  • ValueError – if alias can be confused with an UID, or it does contain chars other than [A-Za-z0-9._-]+

  • ValueError – if compression is not between 0 and 9

  • ValueError – if version is not a semantic version 'X.Y.Z.', where X, Y, Z are integers, optionally followed by a suffix starting with '-', e.g. '1.0.0' or '1.0.0-prod'. Versions may only contain letters, digits, '.', '_', and '-', and have to start with a digit

  • KeyboardInterrupt – if publishing is interrupted by the user (Ctrl+C) or by SIGTERM

Examples

>>> # Assuming your model files are stored under `model_root`
>>> # and your repository is given by `repository`
>>> # (which you usually don't specify, but use its default value)
>>> import datetime
>>> name = "torch"
>>> subgroup = "audmodel.dummy.cnn"
>>> version = "4.0.0"
>>> author = "Calvin and Hobbes"
>>> data = datetime.date(1985, 11, 18)
>>> params = {
...     "model": "cnn10",
...     "data": "emodb",
...     "feature": "melspec",
...     "sampling_rate": 16000,
... }
>>> meta = {
...     "model": {
...         "cnn10": {
...             "learning-rate": 1e-4,
...             "optimizer": "sgd",
...         },
...     },
...     "data": {
...         "emodb": {
...             "version": "1.2.0",
...         },
...     },
...     "feature": {
...         "melspec": {
...             "win_dur": "32ms",
...             "hop_dur": "10ms",
...             "num_fft": 512,
...             "mel_bins": 64,
...         },
...     },
... }
>>> audmodel.publish(
...     model_root,
...     name,
...     params,
...     version,
...     author=author,
...     date=date,
...     meta=meta,
...     subgroup=subgroup,
...     repository=repository,
... )
'd4e9c65b-4.0.0'