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¶
Functions¶
add_tag ¶
add_tag(version: str, tag: str) -> None
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) -> None
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 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, it will download to a temporary directory.
expand(bool, default:True) –if True (the default), model files will be saved to the given folder. If False, it has no difference from True (DEPRECATED).
find_versions ¶
find_versions(
version_prefix: str = "",
status: Optional[str] = None,
tag: Optional[str] = None,
) -> List[str]
Return a list of matching versions for the model, sorted in descending order (the latest version is the 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(Optional[str], default:None) –If specified, return only versions with the given status.
tag(Optional[str], default:None) –If specified, return only versions with the given tag.
get_assets ¶
get_assets(version: str) -> List[Dict[str, Any]]
Returns the asset 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) -> Dict[str, Any]
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_registry_model_metadata ¶
get_registry_model_metadata(
version: Optional[str] = None, model_item_id: Optional[str] = None
) -> List[Dict[str, Any]]
Fetches metadata for a specific registry model identified by its ID or version.
Retrieves metadata associated with a registry model from the relevant endpoint using the provided model ID.
Parameters:
model_item_id–The identifier of the registry model item whose metadata is to be retrieved. If missed, then the provided
versionof the registry model will be used to get model item ID.version(Optional[str], default:None) –The version identifier of the model item in the registry. If specified, it is used to retrieve the corresponding model item ID.
Returns:
List[Dict[str, Any]]–A list of dictionaries with metadata items like: [{'key': 'foo', 'value': 'bar'}, ...]
get_registry_model_status_configuration ¶
get_registry_model_status_configuration(
version: Optional[str] = None, model_item_id: Optional[str] = None
) -> Optional[ModelStatusConfiguration]
get_version_history ¶
get_version_history(version: str) -> Dict[str, Any]
Return the history of changes for a given Model version. This method returns a dictionary with a 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 | |
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: str, status: str) -> None
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) -> str
Returns the status for a given version of the model, e.g. "Production"
Parameters:
version(str) –The model version.
tags ¶
tags(version: str) -> List[str]
Returns the tags for a given version of the model.
Parameters:
version(str) –The model version.
update_registry_model_metadata ¶
update_registry_model_metadata(
metadata: Dict[str, Any],
version: Optional[str] = None,
model_item_id: Optional[str] = None,
) -> requests.Response
Updates the metadata of a model in the registry.
This method supports the modification of metadata associated with a model item in the registry, either by specifying the item ID directly or by specifying its version within the registry. The metadata provided will be validated and flattened to ensure compatibility with the backend.
Raises an exception if the backend version does not support the update_registry_model_metadata method.
Parameters:
metadata(Dict[str, Any]) –A dictionary containing the metadata to be updated for the model.
model_item_id(Optional[str], default:None) –The unique identifier of the model item in the registry to update. If not provided, the latest version of the model will be used.
version(Optional[str], default:None) –The version identifier of the model in the registry to update. If specified, it is used to retrieve the corresponding model item ID. Defaults to None.
Returns:
Response–requests.Response: A response object containing the result of the
Response–update operation.
Raises:
CometException–If the backend version does not support this method.
update_registry_model_status_configuration ¶
update_registry_model_status_configuration(
status_configuration: ModelStatusConfiguration,
version: Optional[str] = None,
) -> requests.Response
Updates the status configuration of a model in the registry.
This method allows the user to update a model's item status configuration in the registry, provided the backend version supports this operation. The method also takes care of fetching the model's item ID based on the provided version, if not already set in the status configuration.
Parameters:
status_configuration(ModelStatusConfiguration) –The status configuration object detailing the changes to apply.
version(Optional[str], default:None) –The version number of the model. This is required if
status_configuration.model_item_idis not already set.
Returns:
Response–The response object from the update status configuration request.
Raises:
CometException–If the backend version doesn't support this method.
ValueError–If the
status_configuration.model_item_idis None, and theversionparameter is not provided.