fromtypingimportListfromgoogle.cloudimportaiplatformdefupload_new_aliased_model_version_sample(parent_name:str,artifact_uri:str,serving_container_image:str,is_default_version:bool,version_aliases:List[str],version_description:str,project:str,location:str,):
"""
UploadsanewaliasedversionofamodelwithID 'model_id'.Args:parent_name:Theparentresourcenameofanexistingmodel.artifact_uri:TheURIofthemodelartifacttoupload.serving_container_image:Thenameoftheservingcontainerimagetouse.is_default_version:Whetherthisversionisthedefaultversionofthemodel.version_aliases:Thealiasesofthemodelversion.version_description:Thedescriptionofthemodelversion.project:TheprojectID.location:Theregionname.Returns:Thenewversionofthemodel.
"""
# Initialize the client.aiplatform.init(project=project,location=location)# Upload a new aliased version of the Model resource with the ID 'model_id'. The parent_name of Model resource can be also# 'projects/<your-project-id>/locations/<your-region>/models/<your-model-id>'
model=aiplatform.Model.upload(artifact_uri=artifact_uri,serving_container_image=serving_container_image,parent_name=parent_name,is_default_version=is_default_version,version_aliases=version_aliases,version_description=version_description,)returnmodel
删除模型别名
删除分配了默认别名的模型版本时,别名会自动分配给下一个最新版本。
控制台
在 Google Cloud 控制台中,进入 Vertex AI Model Registry 页面。
fromtypingimportListfromgoogle.cloudimportaiplatformdefdelete_aliases_model_version_sample(model_id:str,version_aliases:List[str],version_id:str,project:str,location:str,):
"""
Deletealiasestoamodelversion.Args:model_id:TheIDofthemodel.version_aliases:Theversionaliasestoassign.version_id:TheversionIDofthemodeltoassignthealiasesto.project:TheprojectID.location:Theregionname.ReturnsNone.
"""
# Initialize the client.aiplatform.init(project=project,location=location)# Initialize the Model Registry resource with the ID 'model_id'.The parent_name of Model resource can be also# 'projects/<your-project-id>/locations/<your-region>/models/<your-model-id>'
model_registry=aiplatform.models.ModelRegistry(model=model_id)# Remove the version aliases to the model version with the version 'version'.model_registry.remove_version_aliases(target_aliases=version_aliases,version=version_id)