Ejemplo n.º 1
0
def _log_model():
    request_message = _get_request_message(LogModel())
    try:
        model = json.loads(request_message.model_json)
    except:  # NB: can not be more specific here due to python2 compatibility
        raise MlflowException(
            "Malformed model info. \n {} \n is not a valid JSON.".format(
                request_message.model_json),
            error_code=INVALID_PARAMETER_VALUE,
        )

    missing_fields = set(
        ("artifact_path", "flavors", "utc_time_created", "run_id")) - set(
            model.keys())
    if missing_fields:
        raise MlflowException(
            "Model json is missing mandatory fields: {}".format(
                missing_fields),
            error_code=INVALID_PARAMETER_VALUE,
        )
    _get_tracking_store().record_logged_model(
        run_id=request_message.run_id, mlflow_model=Model.from_dict(model))
    response_message = LogModel.Response()
    response = Response(mimetype="application/json")
    response.set_data(message_to_json(response_message))
    return response
Ejemplo n.º 2
0
def test_model_uuid():
    m = Model()
    assert m.model_uuid is not None
    assert _is_valid_uuid(m.model_uuid)

    m2 = Model()
    assert m.model_uuid != m2.model_uuid

    m_dict = m.to_dict()
    assert m_dict["model_uuid"] == m.model_uuid
    m3 = Model.from_dict(m_dict)
    assert m3.model_uuid == m.model_uuid

    m_dict.pop("model_uuid")
    m4 = Model.from_dict(m_dict)
    assert m4.model_uuid is None