In the last article, we discussed deployment and production environment such that it consisted of two primary programs, the application itself and the model by communicating with each other using an interface we know as the endpoint. Today, we’ll learn about the Containers and how Machine Learning Applications can benefit from them. We’ll learn briefly about Model, Application, and then dive into Containers and specifically Docker and explore its structure and its advantages.
Model
To understand the Model, let us take an instance of a simple Python model which is to be created, trained, and validated in the modeling component part of the machine learning workflow discussed in Machine Learning Workflow And Its Methods Of Deployment.
Application
Application is basically a software or web application that provides users who use the application to benefits from the model by retrieving predictions.
Computing environments are integral to run and be available for the usage of the model and application. As per the industry practice in present times, containers are used to create and maintain computing environments. Using the script, containers are created which constitute the instructions that are required for the various libraries, software packages, and various other computing attributes that are needed for software applications to run, here in our case models and applications.
Containers
Containers can be defined as a unit of software that is executable where the application codes are packaged with the needed dependencies and libraries such that it can be run where ever needed from cloud to on-premises services.
Computational environments required for the deployment in Model and application of machine learning are created using container technologies. Docker is an example of a widely used container software. It is today synonymous with containers itself for how widely the market has accepted it.
Docker
Docker is a platform that supports to development, ship, and run of applications by delivering software in packages that are known as containers.
Understanding Containers
To understand anything using an analogy to pre-existing knowledge is fundamental. Using this approach let's understand containers here in comparison to shipping containers. The shipping containers contain multitudes of variations of products ranging from cars to food to furniture and so much more. The very structure of these shipping containers makes it possible to load, unload, transport all of these products across the globe within a container no matter how diverse these products are. Similarly, the Docker containers in our context also have the capability to contain multitudes of different types of software and the structure of the Docker container provides the feasibility with a set of common tools to create, save, use and delete the containers. Regardless of the types of software that these containers contain, the common toolset can work for any container.
Understanding the Structure of the Container
The image above gives an insight into the structure of a container. The computational infrastructure which is the underlying physical resource can range from any local computer to, on-premises data center to the data center of the cloud provider. On top of that layer, the operating system which runs on that computational infrastructure can be any operating system similar to the ones we use on our local machines. The Container Engine runs the Docker software which resides on top of the OS that enables the creation, saving, usage, and deletion of the containers. The top two layers consist of the major components of the containers. The first layer constitutes binaries and libraries to launch run and maintain the other layers which are known as the application layer that runs the application.
Three different applications, Application 1, Application 2, and Application 3 are shown to be running on the three containers. Some of the pros of this architecture of the containers can be specified as follows:
- The computational resources usage becomes extremely efficient as the container only requires the software that is needed to run the application and also provides rapid application deployment.
- Security risks are mitigated as the application is isolated and thus, the system becomes more secure.
- Across all the applications which get deployed on the container, these applications will have swift access to be created, replicated, deleted with easier maintenance provision.
- The containers themselves can be replicated, saved, and shared across in a more simplistic and secure manner.
As we have discussed above, a container can be created easily with a container script file. It is very easy to share this text script file with other team members and collaborators and also provides a simple method in order to replicate the containers. These container scripts are basically simple instructions (algorithms) which is used for the creation of the container. In the case of Docker, these container scripts are known as dockerfiles.
As explained with a visual image below, the container engine is shown to use a container script in order to create a container that runs the application within it. Such container script files provide a simplistic method to replicate and share containers by storing them in the repositories. Docker Hub is known as the official repository for sharing and storage of the dockerfiles. Dockerfiles can be used for an instance when we want to create a docker container that has PyTorch and Python 3.8 installed for our Machine Learning Application.
Across the software engineering teams, we often hear this term - “It works in my machine”. Creating models for machine learning applications that run our local machines aren’t must of a hassle. But the issue arises when it needs to work on the production system, across all different servers spread across the globe in a way that can auto-scale its functions is an extremely challenging feat. Thus, for such demanding needs, Containers are quintessential to create and run applications without any possible performance issues.
Conclusion
Thus, in this article, we learned about models, applications and took a dive deep into containers for the benefit of machine learning applications. We discussed docker and explored the structure of containers with its advantages. We also understood the way containers are created, deleted, and maintained.