ML Model Deployed as Microservice
Dalmas Chituyi
Building and automating data pipelines to aid ML for supply chain agility and customer intimacy.
Machine learning (ML) has revolutionized numerous industries by automating and enhancing processes. However, the real value of ML models comes into play when they are successfully deployed and used for making predictions on new data.
?? ??Think about it, all the types of ML model deployments generalize to In-app deployment or API-based deployments.
Below is a demo of a deployed model as a microservice that maps Prices to Products with a callback function wrapping model output.
Microservices Deployment
In a microservice deployment, the ML model is encapsulated as a separate service that can be independently deployed, scaled, and updated. This service communicates with other services and applications through APIs.
Advantages.
?????? i.????????? Modularity. Changes to the model don’t affect the rest of the application, making it easier to update or replace models.
???? ii.????????? Scalability. Each microservice can be scaled independently based on demand.
An example of Consuming the API:
The endpoint URL: https://pvrapi.onrender.com/predict
Data type = dict
Data format = json
import requests
data = {"quote": 5000, "product": "oil"}
res = requests.post(url, json=data)
print(res.text)
Api Response.
Either “Your quote for this product is Accepted” Or “Your quote for this product is Rejected”
领英推荐
1. Traditional Deployment
Traditional deployment involves integrating the ML model directly into an existing system. The model, once trained, is saved, and then loaded into the application for use.
Advantages.
?????? i.????????? Simplicity. This method is straightforward and doesn’t require extensive knowledge about cloud or distributed systems.
???? ii.????????? Control. Since the model is part of the application, developers have complete control over its usage.
2. Cloud-based Deployment
Cloud-based deployment involves hosting the ML model on a cloud platform like AWS, Google Cloud, or Azure. These platforms provide services to easily deploy and manage ML models.
Advantages.
?????? i.????????? Scalability. Cloud platforms can handle increasing amounts of data and requests without requiring changes to the application.
???? ii.????????? Maintenance. Cloud providers take care of infrastructure maintenance, allowing developers to focus on improving the model and application.
3. On-device Deployment
On-device deployment involves running the ML model directly on a user’s device, such as a smartphone or IoT device. This is often seen in edge computing scenarios.
Advantages.
?????? i.????????? Latency. Predictions are faster as data doesn’t need to be sent to a server.
???? ii.????????? Privacy. User data stays on the device, which can be crucial for privacy-sensitive applications.
4. Hybrid Deployment
Hybrid deployment combines different methods to leverage their advantages based on specific needs. For example, a model could be deployed on-device for quick predictions and on the cloud for more complex predictions.
Advantages.
?????? i.????????? Flexibility. Hybrid deployment provides the flexibility to choose the best method for each situation.
???? ii.????????? Optimization. It allows for optimization of resources, costs, and performance.
In conclusion, the choice of deployment method depends on the specific requirements of the ML application, including the amount of data, request latency, privacy concerns, and infrastructure costs. By understanding the advantages of each method, you can make an informed decision that best suits your needs.??