Search code examples
google-cloud-mlgoogle-cloud-ml-engine

cloud ml predict FAILED_PRECONDITION and value for field [projectsId]


The predict command I have been using for quite some time began encountering an error this weekend:

$ gcloud beta ml predict --model my_model --json-instances my_instance.json

WARNING: The `gcloud beta ml` commands have been renamed and will soon be removed. Please use `gcloud ml-engine` instead.
ERROR: (gcloud.beta.ml.predict) value for field [projectsId] for in collection [ml.projects.models] is required but was not provided

I do not understand how to fix the error.

To investigate whether the error is associated with the soon to be removed 'cloud beta ml' command, I replaced it with 'gcloud ml-engine' but encountered this error:

$ gcloud ml-engine predict --model my_model --json-instances my_instance.json
ERROR: (gcloud.ml-engine.predict) HTTP request failed. Response: {
  "error": {
    "code": 400,
    "message": "Precondition check failed.",
    "status": "FAILED_PRECONDITION"
  }
}

I do not understand how to fix this second error. Presumably, its root cause is the same as the first error.

How can I get more detail about fixing this error(s)?

Note: this question appears similar this other question asked by @jbird, but is not the same.


Solution

  • The gcloud tool has been updated so that the ml-engine set of commands is the officially supported way to interact with the service. The gcloud beta ml codepath is out-of-date. The following should work:

    gcloud beta ml-engine predict --model my_model --json-instances my_instance.json
    

    (Note the presence of the keyword beta).

    The reason for the 400 error when using gcloud ml-engine predict (note the absence of the keyword beta) is because your model is not a SavedModel. In that set of commands (non-beta), we only support SavedModel.

    You can continue to use your existing models via the old endpoint (gcloud beta ...), but we expect to deprecate that functionality soon, so we recommend exporting new models as SavedModels and deploying them via gcloud ml-engine.