KFP pipeline job executes successfully, but upon hitting the endpoint, am getting an empty predictions array ([]). I suspect the issue is in the model upload, where the model is not registered correctly somehow. Any tips are appreciated.
Code to upload model deploy task:
#Import a model programmatically
model_upload = aiplatform.Model.upload(
display_name = DISPLAY_NAME,
serving_container_image_uri = serving_container_image_uri,
serving_container_health_route="/health_check",
serving_container_predict_route="/predict",
serving_container_ports=[8080],
serving_container_environment_variables={
"MODEL_NAME": MODEL_NAME,
},
)
Code to get predictions:
response = endpoint.predict({"user_id": 150})
# response = endpoint.predict({"instances":{"user_id": 150}})
response
Response:
Prediction(predictions=[], deployed_model_id='4656867150235959296', explanations=None)
TLDR:
Check your handler output is returning a correctly formatted string without extra slashes (
\) in the response which meets the requirements.Or use
raw predictinstead ofpredictcall. (guide)Debugging steps:
I also had this issue where I was using the Vertex AI custom serving container approach and calling
endpoint.predict(instances=[{...}]).predictionswas only returning an empty list:[].Even though, when using
raw predictfrom the Python SDK or via REST endpoint, it returned a valid response for thedataJSON key:Python SDK response:
REST API response:
However, in both cases you can see that there were extra slashes (
\) in the responses. This means that it was a formatting issue.Solution:
It turned out that in the post-processing step of my handler, I had done the following:
Changing it to the following fixed the problem for me:
And then calling
endpoint.predict(instances=[{...}]).predictionsreturned the following list for me:After the fix, the responses from
raw predictno longer contained the extra slashes (\).