Example #1
0
    def GetModelMetadata(self, request, context):

        # check if model with was requested
        # is available on server with proper version
        logger.debug("MODEL_METADATA, get request: {}".format(request))
        model_name = request.model_spec.name
        requested_version = request.model_spec.version.value
        valid_model_spec, version = check_availability_of_requested_model(
            models=self.models,
            requested_version=requested_version,
            model_name=model_name)

        if not valid_model_spec:
            context.set_code(StatusCode.NOT_FOUND)
            context.set_details(
                WRONG_MODEL_SPEC.format(model_name, requested_version))
            logger.debug("MODEL_METADATA, invalid model spec from request")
            return get_model_metadata_pb2.GetModelMetadataResponse()
        target_engine = self.models[model_name].engines[version]
        target_engine.in_use.acquire()
        metadata_signature_requested = request.metadata_field[0]
        if 'signature_def' != metadata_signature_requested:
            context.set_code(StatusCode.INVALID_ARGUMENT)
            context.set_details(
                INVALID_METADATA_FIELD.format(metadata_signature_requested))
            logger.debug("MODEL_METADATA, invalid signature def")
            target_engine.in_use.release()
            return get_model_metadata_pb2.GetModelMetadataResponse()

        inputs = target_engine.net.inputs
        outputs = target_engine.net.outputs

        signature_def = prepare_get_metadata_output(
            inputs=inputs,
            outputs=outputs,
            model_keys=target_engine.model_keys)
        response = get_model_metadata_pb2.GetModelMetadataResponse()

        model_data_map = get_model_metadata_pb2.SignatureDefMap()
        model_data_map.signature_def['serving_default'].CopyFrom(signature_def)
        response.metadata['signature_def'].Pack(model_data_map)
        response.model_spec.name = model_name
        response.model_spec.version.value = version
        logger.debug("MODEL_METADATA created a response for {} - {}".format(
            model_name, version))
        target_engine.in_use.release()
        return response
Example #2
0
 def check_model_server():
     response = get_model_metadata(MODEL_REQUEST)
     metadata = ParseDict(response,
                          model_metadata.GetModelMetadataResponse(),
                          ignore_unknown_fields=True)
     model_name = metadata.model_spec.name
     model_version = metadata.model_spec.version.value
     if model_name == os.environ['MODEL'] and model_version > 0:
         return True, '[{}] model server ok'.format(model_name)
     else:
         return False, '[{}] model server unavailable'.format(model_name)
Example #3
0
    def on_get(self, req, resp, model_name, requested_version=0):
        logger.debug("MODEL_METADATA, get request: {}, {}".format(
            model_name, requested_version))
        valid_model_spec, version = check_availability_of_requested_model(
            models=self.models,
            requested_version=requested_version,
            model_name=model_name)

        if not valid_model_spec:
            resp.status = falcon.HTTP_NOT_FOUND
            logger.debug("MODEL_METADATA, invalid model spec from request")
            err_out_json = {
                'error': WRONG_MODEL_SPEC.format(model_name, requested_version)
            }
            resp.body = json.dumps(err_out_json)
            return

        target_engine = self.models[model_name].engines[version]
        target_engine.in_use.acquire()

        inputs = target_engine.net.inputs
        outputs = target_engine.net.outputs

        signature_def = prepare_get_metadata_output(
            inputs=inputs,
            outputs=outputs,
            model_keys=target_engine.model_keys)
        response = get_model_metadata_pb2.GetModelMetadataResponse()

        model_data_map = get_model_metadata_pb2.SignatureDefMap()
        model_data_map.signature_def['serving_default'].CopyFrom(signature_def)
        response.metadata['signature_def'].Pack(model_data_map)
        response.model_spec.name = model_name
        response.model_spec.version.value = version
        logger.debug("MODEL_METADATA created a response for {} - {}".format(
            model_name, version))
        target_engine.in_use.release()
        resp.status = falcon.HTTP_200
        resp.body = MessageToJson(response)
def get_model_metadata_response_rest(rest_url):
    result = requests.get(rest_url)
    output_json = result.text
    metadata_pb = get_model_metadata_pb2.GetModelMetadataResponse()
    response = Parse(output_json, metadata_pb, ignore_unknown_fields=False)
    return response
Example #5
0
 def __init__(self, model_spec=None, metadata=None, **kwargs):
     super().__init__(get_model_metadata_pb2.GetModelMetadataResponse(),
                      model_spec=model_spec,
                      metadata=metadata,
                      **kwargs)