Skip to content

Model

Model is an API object implementing various methods to manipulate models in the model registry.

Model.init

__init__(workspace: str, model_name: str, *, api_key: Optional[str] = None)

Creates a new Model object that can be used to manipulate a model in the model registry.

Args:

  • workspace: Name of the workspace to which the model belongs
  • model_name: Name of the model stored in the model registry
  • api_key: Optional. Your API key obtained from comet.com If not specified, api_key will be obtained from the comet configuration or environment variables.

Model.add_tag

add_tag(version: str, tag: str)

Add a tag to a given version of the model

Args:

  • version: the model version
  • tag: the tag to add

Model.delete_tag

delete_tag(version: str, tag: str)

Deletes a tag from a given version of the model

Args:

  • version: the model version
  • tag: the tag to delete

Model.download

download(version: str, output_folder: Optional[Union[pathlib.Path,
    str]] = None, expand: bool = True) -> None

Download the files for a given version of the model. This method downloads assets and remote assets that were synced from a compatible cloud object storage (AWS S3 or GCP GCS). Other remote assets are not downloaded and you can access their uri with the get_assets method.

Args:

  • version: the model version
  • output_folder: files will be saved in this folder. If not provided, will download to a temporary directory.
  • expand DEPRECATED - if True (the default), model files will be saved to the given folder. If False, it has no difference from True.

Model.find_versions

find_versions(version_prefix="", status=None, tag=None)

Return a list of matching versions for the model, sorted in descending order (latest version is first).

Args:

  • version_prefix: optional. If specified, return only those versions that start with version_prefix, e.g. "3" may find "3.2" but not "4.0", and "2.1" will find "2.1.0" and "2.1.1" but not "2.0.0" or "2.2.3".
  • status: optional. If specified, return only versions with the given status.
  • tag: optional. If specified, return only versions with the given tag.

Model.get_assets

get_assets(version: str) -> List[dict]

Returns the assets list for the given version. Remote assets have the key remote set to True.

Args:

  • version: the model version
>>> from comet_ml.api import API
>>> api = API()
>>> model = api.get_model("my-workspace", "my-model-name")
>>> model.get_assets()
[
    {
        'fileName': 'file',
        'fileSize': 0,
        'runContext': None,
        'step': None,
        'remote': True,
        'link': 's3://bucket/dir/file',
        'compressedAssetLink': 's3://bucket/dir/file',
        's3Link': None,
        'createdAt': 1700131519059,
        'dir': 'models/my-model',
        'canView': False,
        'audio': False,
        'video': False,
        'histogram': False,
        'image': False,
        'type': 'model-element',
        'metadata': '',
        'assetId': '6ce04b4331bd4f7d9eb56a0d876ead72',
        'tags': [],
        'curlDownload': 'curl "..." > file',
        'experimentKey': '...'
    },
    {
        'fileName': 'model_metadata.json',
        'fileSize': 49,
        'runContext': None,
        'step': None,
        'remote': False,
        'link': '...',
        'compressedAssetLink': '...',
        's3Link': '...',
        'createdAt': 1700131496454,
        'dir': 'models/my-model',
        'canView': False,
        'audio': False,
        'video': False,
        'histogram': False,
        'image': False,
        'type': 'model-element',
        'metadata': None,
        'assetId': 'd4fcc9ef32394ea0956c1725c0c98604',
        'tags': [],
        'curlDownload': 'curl "..." -H"Authorization: <Your Api Key>" > model_metadata.json',
        'experimentKey': '...'
    }
]

Model.get_details

get_details(version: str)

Returns a dict with various details about the given model version.

The exact details returned may vary by backend version, but they include e.g. experimentKey, comment, createdAt timestamp, updatedAt timestamp.

Args:

  • version: the model version

Model.get_version_history

get_version_history(version: str)

Return the history of changes for a given Model version. This method returns a dictionary of list of changes per day, see below for an example:

Args:

  • version: the model version
>>> from comet_ml.api import API
>>> api = API()
>>> model = api.get_model("my-workspace", "my-sklearn-model")
>>> model.get_version_history("2.31.0")
{'November 16, 2023': [{'actionType': 'MODEL_VERSION_STATUS_REQUEST_APPROVED',
                'comment': '',
                'newValue': {'changedBy': 'lothiraldan',
                             'registryModelStatus': 'Development'},
                'previousValue': {'changedBy': 'user',
                                  'registryModelStatus': 'None'},
                'registryModelId': 'bg0HklLmLbokkv8VIA5MzR40F',
                'registryModelItemActualPathParams': None,
                'registryModelItemId': '7dylnoIk8sX5sCojyBRnMNFYv',
                'registryModelItemVersion': '2.31.0',
                'registryModelName': 'my-sklearn-model',
                'userAvatarLink': 'https://github.com/user.png?size=30',
                'userName': 'user'},
               {'actionType': 'MODEL_VERSION_STATUS_CHANGED',
                'comment': '',
                'newValue': {'changedBy': 'user',
                             'registryModelStatus': 'Development'},
                'previousValue': {'changedBy': 'user',
                                  'registryModelStatus': 'None'},
                'registryModelId': 'bg0HklLmLbokkv8VIA5MzR40F',
                'registryModelItemActualPathParams': None,
                'registryModelItemId': '7dylnoIk8sX5sCojyBRnMNFYv',
                'registryModelItemVersion': '2.31.0',
                'registryModelName': 'my-sklearn-model',
                'userAvatarLink': 'https://github.com/user.png?size=30',
                'userName': 'user'},
               {'actionType': 'MODEL_VERSION_STATUS_REQUEST_CHANGE',
                'comment': '',
                'newValue': {'registryModelStatus': 'Development'},
                'previousValue': {'registryModelStatus': 'None'},
                'registryModelId': 'bg0HklLmLbokkv8VIA5MzR40F',
                'registryModelItemActualPathParams': None,
                'registryModelItemId': '7dylnoIk8sX5sCojyBRnMNFYv',
                'registryModelItemVersion': '2.31.0',
                'registryModelName': 'my-sklearn-model',
                'userAvatarLink': 'https://github.com/user.png?size=30',
                'userName': 'user'}],
 'June 6, 2023': [{'actionType': 'MODEL_VERSION_DOWNLOADED',
           'comment': None,
           'newValue': {},
           'previousValue': {},
           'registryModelId': 'bg0HklLmLbokkv8VIA5MzR40F',
           'registryModelItemActualPathParams': None,
           'registryModelItemId': '7dylnoIk8sX5sCojyBRnMNFYv',
           'registryModelItemVersion': '2.31.0',
           'registryModelName': 'my-sklearn-model',
           'userAvatarLink': 'https://github.com/user.png?size=30',
           'userName': 'user'},
          {'actionType': 'MODEL_VERSION_CREATED',
           'comment': None,
           'newValue': {},
           'previousValue': {},
           'registryModelId': 'bg0HklLmLbokkv8VIA5MzR40F',
           'registryModelItemActualPathParams': None,
           'registryModelItemId': '7dylnoIk8sX5sCojyBRnMNFYv',
           'registryModelItemVersion': '2.31.0',
           'registryModelName': 'my-sklearn-model',
           'userAvatarLink': 'https://github.com/user.png?size=30',
           'userName': 'user'}]}

Model.name

name()

Returns the model name

Model.set_status

set_status(version, status)

Set the status of a given version of the model

Args:

  • version: the model version
  • status: one of the allowed status values, e.g. "Production"

See also: the model_registry_allowed_status_values on the API class.

Model.status

status(version: str)

Returns the status for a given version of the model, e.g. "Production"

Args:

  • version: the model version

Model.tags

tags(version: str)

Returns the tags for a given version of the model.

Args:

  • version: the model version
Mar. 27, 2024