def _MarkPushed(self, model_push: types.Artifact, pushed_destination: Text, pushed_version: Optional[Text] = None) -> None: model_push.set_int_custom_property('pushed', 1) model_push.set_string_custom_property( _PUSHED_DESTINATION_KEY, pushed_destination) if pushed_version is not None: model_push.set_string_custom_property(_PUSHED_VERSION_KEY, pushed_version)
def _attach_artifact_properties(spec: pipeline_pb2.OutputSpec.ArtifactSpec, artifact: types.Artifact): """Attaches properties of an artifact using ArtifactSpec.""" for key, value in spec.additional_properties.items(): if not value.HasField('field_value'): raise RuntimeError('Property value is not a field_value for %s' % key) setattr(artifact, key, data_types_utils.get_metadata_value(value.field_value)) for key, value in spec.additional_custom_properties.items(): if not value.HasField('field_value'): raise RuntimeError('Property value is not a field_value for %s' % key) value_type = value.field_value.WhichOneof('value') if value_type == 'int_value': artifact.set_int_custom_property(key, value.field_value.int_value) elif value_type == 'string_value': artifact.set_string_custom_property(key, value.field_value.string_value) elif value_type == 'double_value': artifact.set_float_custom_property(key, value.field_value.double_value) else: raise RuntimeError(f'Unexpected value_type: {value_type}')
def _CreateWarmupModel(self, blessing: types.Artifact, model_path: str, warmup_requests: List[iv_types.Request]): output_model_path = path_utils.stamped_model_path(blessing.uri) io_utils.copy_dir(src=model_path, dst=output_model_path) io_utils.write_tfrecord_file( path_utils.warmup_file_path(output_model_path), *[_convert_to_prediction_log(r) for r in warmup_requests]) blessing.set_int_custom_property(_MODEL_FLAG_KEY, 1)
def _set_artifact_properties(artifact: types.Artifact, properties: Optional[Dict[str, Any]], custom_properties: Optional[Dict[str, Any]]): """Sets properties and custom_properties to the given artifact.""" if properties is not None: for key, value in properties.items(): setattr(artifact, key, value) if custom_properties is not None: for key, value in custom_properties.items(): if isinstance(value, int): artifact.set_int_custom_property(key, value) elif isinstance(value, (str, bytes)): artifact.set_string_custom_property(key, value) else: raise NotImplementedError( f'Unexpected custom_property value type:{type(value)}')
def _MarkNotPushed(self, model_push: types.Artifact): model_push.set_int_custom_property('pushed', 0)
def _mark_not_blessed(blessing: types.Artifact) -> None: logging.info('Model failed infra validation.') io_utils.write_string_file(os.path.join(blessing.uri, NOT_BLESSED), '') blessing.set_int_custom_property('blessed', 0)
def _mark_blessed(blessing: types.Artifact) -> None: logging.info('Model passed infra validation.') io_utils.write_string_file( os.path.join(blessing.uri, _BLESSED_FILENAME), '') blessing.set_int_custom_property(_BLESSED_KEY, 1)
def _MarkNotBlessed(self, blessing: types.Artifact) -> None: if not self._validation_failed: self._validation_failed = True io_utils.write_string_file(os.path.join(blessing.uri, NOT_BLESSED), '') blessing.set_int_custom_property('blessed', 0)
def _MarkBlessedIfSucceeded(self, blessing: types.Artifact) -> None: if not self._validation_failed: logging.info( 'Model passed infra validation; marking model as blessed.') io_utils.write_string_file(os.path.join(blessing.uri, BLESSED), '') blessing.set_int_custom_property('blessed', 1)