Search code examples
pythongoogle-cloud-platformgcp-ai-platform-training

which is the best option call trained machine learning model in google cloud?


I have a trained machine learning model in python to obtain a regression output, this model is trained with scikit-learn

I want to insert this predictions into firestore, I am going to do it with a cloud function scheduling it every day with cloud scheduler.

My question is where I have to store this trained machine learning model?

  • Can I store it into google storage and call it in my cloud function to obtain predictions?
  • Or I should store it into AI platform?

  • If the answer is into AI platform, why? what advantages I have if I store it into AI platform? can I train the model with new data from there?

I have been reading that this is possible but I don't know why is better and how to it


Solution

  • There is several answer to your question.

    Do you want to build a monolith or 2 microservices:

    • Monolith, I mean the same service (Functions or container) is triggered by the scheduler, load the model, perform the prediction and save it to firestore
    • Microservice:
      • 1 service is triggered by the scheduler, request a prediction and store the result into Firestore
      • 1 service load the model and answer to prediction query.

    In monolith case, AI-Platform is not recommended. In microservice, you can host your prediction service on AI Platform, and the other on Cloud Functions

    With tensorflow I also proposed another solution for hosting the model: in Cloud Run. I wrote an article on this. I don't know enough SciKit for telling you is the same thing is possible, but it's a good alternative.

    About where to store your trained model? Definitively on Cloud Storage. And even if you build a Cloud Run service with a container like described in my article, where I download the model and load it into the container (and thus the model is not downloaded from Storage at runtime, only at build time), Cloud Storage is the best place for immutable objects.

    Finally, your last question about AI Platform. A same name, several services. You can host your model and perform Online Prediction, and you can train your model. It's not the same internal service, not the same usage, not the same API. There is no difference/advantage when you train new model, if you host your online prediction on AI Platform or not