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
namepackage used to train/create the model
onnx
sklearn
torch
subgroupproject
task the model was trained for
model architecture
ser.dimensions.wav2vec2
age.cnn
paramsmodel
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
metaargument encodes additional information. In contrast toname,subgroup,paramsit can be changed later. It should be used to extend information of theparamsentries using the same keys. In addition, it can store example output, and benchmark results. For example, ametaentry corresponding to the firstparamsexample 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
RuntimeErroris 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 filesname (
str) – model nameversion (
str) – version stringrepository (
Repository) – repository where the model will be publishedalias (
str|None) – optional alias name for the model. If provided, the model can be accessed using this alias in addition to its UIDcompression (
int) – compression level of the model archive.0stores the model files without compression,1-9selects a deflate level. Deflate is single threaded, and dominates the publication time of large models. Higher levels than1hardly compress better on model weights, but take at least twice as long. Select0, if you want to publish as fast as possiblemeta (
dict[str,object] |None) – dictionary with meta informationsubgroup (
str|None) – subgroup under which the model is stored on backend..are replaced by/on the backendtmp_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. IfNone, the system default temporary folder is usedverbose (
bool) – show debug messages
- Return type:
- Returns:
unique model ID
- Raises:
ValueError – if
repositoryisNoneaudbackend.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
metaorparamscannot be serialized to a YAML fileValueError – if subgroup is set to
'_uid'FileNotFoundError – if
rootfolder cannot be foundValueError – if
aliascan be confused with an UID, or it does contain chars other than[A-Za-z0-9._-]+ValueError – if
compressionis not between 0 and 9ValueError – if
versionis 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 digitKeyboardInterrupt – 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'