def to_detail_entity(self): latest_version = None for model_version in reversed(self.model_version): if model_version.current_stage != STAGE_DELETED: latest_version = model_version.to_meta_entity() break return RegisteredModelDetail(self.model_name, self.model_type, self.model_desc, latest_version)
def to_detail_entity(self): # SqlRegisteredModel has backref to all "model_version". Filter latest version of registered model. latest_version = None for model_version in reversed(self.model_version): if model_version.current_stage != STAGE_DELETED: latest_version = model_version.to_meta_entity() break return RegisteredModelDetail(self.model_name, self.model_type, self.model_desc, latest_version)
def get_registered_model_detail(self, model_name) -> Optional[RegisteredModelDetail]: """ Get registered model detail filter by model name for Model Center. :param model_name: Name of registered model. This is expected to be unique in the backend store. :return: A single :py:class:`ai_flow.entities.model_registry.RegisteredModelDetail` object. """ request = GetRegisteredModelDetailRequest(model_meta=ModelMetaParam(model_name=stringValue(model_name))) response = self.model_center_stub.getRegisteredModelDetail(request) return RegisteredModelDetail.from_detail_proto(_parse_response(response, ProtoModelDetail()))
def list_registered_models(self) -> List[RegisteredModelDetail]: """ List of all registered models in Model Center backend. :return: List of :py:class:`ai_flow.model_center.entity.RegisteredModel` objects. """ request = ListRegisteredModelsRequest() response = self.model_center_stub.listRegisteredModels(request) registered_model_details = [] for registered_model_detail in _parse_response(response, RegisteredModelMetas()).registered_models: registered_model_details.append(RegisteredModelDetail.from_proto(registered_model_detail)) return registered_model_details
def create_registered_model(self, model_name, model_type, model_desc=None) -> Optional[RegisteredModelDetail]: """ Create a new registered model from given type in Model Center. :param model_name: Name of registered model. This is expected to be unique in the backend store. :param model_type: Type of registered model. :param model_desc: (Optional) Description of registered model. :return: A single object of :py:class:`ai_flow.model_center.entity.RegisteredModelDetail` created in Model Center. """ request = CreateRegisteredModelRequest( registered_model=RegisteredModelParam(model_name=stringValue(model_name), model_type=ModelType.Value(model_type), model_desc=stringValue(model_desc))) response = self.model_center_stub.createRegisteredModel(request) return RegisteredModelDetail.from_proto(_parse_response(response, RegisteredModelMeta()))
def update_registered_model(self, model_name, new_name=None, model_type=None, model_desc=None) -> Optional[RegisteredModelDetail]: """ Update metadata for RegisteredModel entity backend. Either ``model_name`` or ``model_type`` or ``model_desc`` should be non-None. Backend raises exception if a registered model with given name does not exist. :param model_name: Name of registered model. This is expected to be unique in the backend store. :param new_name: (Optional) New proposed name for the registered model. :param model_type: (Optional) Type of registered model. :param model_desc: (Optional) Description of registered model. :return: A single updated :py:class:`ai_flow.model_center.entity.RegisteredModelDetail` object. """ request = UpdateRegisteredModelRequest(model_meta=ModelMetaParam(model_name=stringValue(model_name)), registered_model=RegisteredModelParam(model_name=stringValue(new_name), model_type=ModelType.Value( model_type), model_desc=stringValue( model_desc))) response = self.model_center_stub.updateRegisteredModel(request) return RegisteredModelDetail.from_proto(_parse_response(response, RegisteredModelMeta()))
def to_meta_entity(self): return RegisteredModelDetail(self.model_name, self.model_type, self.model_desc)