Skip to content

comet_ml.Model ¶

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

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

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

Parameters:

  • workspace (str) –

    Name of the workspace to which the model belongs

  • model_name (str) –

    Name of the model stored in the model registry

  • api_key (Optional[str], default: None ) –

    Your API key obtained from comet.com. If not specified, api_key will be obtained from the comet configuration or environment variables.

Attributes¶

name property ¶

name

Returns the model name

Functions¶

add_tag ¶

add_tag(version: str, tag: str)

Add a tag to a given version of the model

Parameters:

  • version (str) –

    the model version

  • tag (str) –

    the tag to add

delete_tag ¶

delete_tag(version: str, tag: str)

Deletes a tag from a given version of the model

Parameters:

  • version (str) –

    the model version

  • tag (str) –

    the tag to delete

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 comet_ml.Model.get_assets method.

Parameters:

  • version (str) –

    the model version

  • output_folder (Optional[Union[Path, str]], default: None ) –

    files will be saved in this folder. If not provided, will download to a temporary directory.

  • expand (DEPRECATED, default: True ) –

    if True (the default), model files will be saved to the given folder. If False, it has no difference from True.

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).

Parameters:

  • version_prefix (str, default: '' ) –

    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 (str, default: None ) –

    If specified, return only versions with the given status.

  • tag (str, default: None ) –

    If specified, return only versions with the given tag.

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.

Parameters:

  • version (str) –

    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': '...'
    }
]

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.

Parameters:

  • version (str) –

    the model version

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:

Parameters:

  • version (str) –

    the model version

Example

Running the code sample:

1
2
3
4
5
6
import comet_ml

comet_ml.login()
api = comet_ml.API()
model = api.get_model("my-workspace", "my-sklearn-model")
model.get_version_history("2.31.0")

will return the dictionary:

{
    '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'}]}

set_status ¶

set_status(version, status)

Set the status of a given version of the model

Parameters:

  • version (str) –

    the model version

  • status (str) –

    one of the allowed status values, e.g. "Production"

See also: The comet_ml.API.model_registry_allowed_status_values on the API class.

status ¶

status(version: str)

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

Parameters:

  • version (str) –

    The model version.

tags ¶

tags(version: str)

Returns the tags for a given version of the model.

Parameters:

  • version (str) –

    The model version.

Jul. 25, 2024