combust / mleap

MLeap: Deploy ML Pipelines to Production
https://combust.github.io/mleap-docs/
Apache License 2.0
1.5k stars 312 forks source link

Mleap Spring Boot Swagger Documentation Seems Incorrect #861

Open habib27 opened 1 year ago

habib27 commented 1 year ago

Hi,

I have been exploring the mleap-spring-boot project. The swagger documentation seems to be off for the transform endpoint.

In the swagger for the endpoint --> /models/{modelName}/transform It mentions that the body is supposed to be the following:

{ "schema": { "fields": [ { "name": "string", "dataType": { "base": "BOOLEAN", "shape": { "base": "SCALAR", "isNullable": true, "tensorShape": [ { "size": 0, "name": "string" } ] } } } ] }, "rows": [ [ {} ] ] }

However, when you use that body there is an error --> "error": "NoSuchElementException: key not found: type",

Seems like a type field is required. Am i missing something? Also what are valid values for type.

Thank you for help, much appreciated.

ltrottier-yelp commented 1 year ago

Hello @habib27,

Are you following the tutorial here ?

To transform a frame, you need to format it as mleap expects it. Here is an example for airbnb leap frame:

{
    "schema": {
      "fields": [{
        "name": "state",
        "type": "string"
      }, {
        "name": "bathrooms",
        "type": "double"
      }, {
        "name": "square_feet",
        "type": "double"
      }, {
        "name": "bedrooms",
        "type": "double"
      }, {
        "name": "security_deposit",
        "type": "double"
      }, {
        "name": "cleaning_fee",
        "type": "double"
      }, {
        "name": "extra_people",
        "type": "double"
      }, {
        "name": "number_of_reviews",
        "type": "double"
      }, {
        "name": "review_scores_rating",
        "type": "double"
      }, {
        "name": "room_type",
        "type": "string"
      }, {
        "name": "host_is_superhost",
        "type": "string"
      }, {
        "name": "cancellation_policy",
        "type": "string"
      }, {
        "name": "instant_bookable",
        "type": "string"
      }]
    },
    "rows": [["NY", 2.0, 1250.0, 3.0, 50.0, 30.0, 2.0, 56.0, 90.0, "Entire home/apt", "1.0", "strict", "1.0"]]
  }

Reference for leap frame: https://github.com/combust/mleap/blob/master/mleap-executor-testkit/src/main/resources/leap_frame/frame.airbnb.json

Then, to query the model simply do:

body=$(cat frame.airbnb.json)
curl --header "Content-Type: application/json" \
  --header "timeout: 1000" \
  --request POST \
  --data "$body" http://localhost:8080/models/AirBnBLR/transform
habib27 commented 1 year ago

Hey @ltrottier-yelp ,

Thank you for the reply.

Yes I followed that tutorial. The link to the airbnb frame does not work for me, says all access is disabled. But that payload I was able to find somewhere and use and it does work.

However, the issue is you see that type field that is being used there in the example, it's not in the swagger and I don't know what are the possible values for it. For example if I have a model where the value is double but the base is "Tensor", what type do I pass in to make it work?

I get this error :

"status": "STATUS_ERROR", "error": "IllegalArgumentException: Cannot cast ScalarType(double,true) to TensorType(double,Some(WrappedArray(75)),true)

Is there anywhere I can find what the valid values are for this type field?

ltrottier-yelp commented 1 year ago

I'm taking a look at the swagger file, because it looks outdated. I'll try to update it soon.

The frame that you pass to the server is the same as a leap frame that you create in scala. It is simply its json representation. So you have two choices:

  1. Create it via scala code and save it to json using the provided json FrameWriter. See here for a tutorial.

  2. Create it yourself. Since the swagger is outdated, for now you can look at this file: https://github.com/combust/mleap/blob/fad50bfbc435bc8f03f1bd50b01ed1171d7dd8cd/mleap-runtime/src/main/scala/ml/combust/mleap/json/JsonSupport.scala#L105 . This is where we define the parsing rules for json to create the leap frame. So for a tensor of type double, you need to define the type, base and dimensions.

habib27 commented 1 year ago

Hey @ltrottier-yelp ,

Thank you very much for your help and prompt response. I appreciate it.