Packaging and containerization

End-to-End Machine Learning

Joshua Stapleton

Machine Learning Engineer

Deployment and containerization

Deployment

  • Packing model + dependencies into units
  • For running in different environment
  • De-facto framework for containerization and deployment is Docker

Deployment phase of machine learning lifecycle

End-to-End Machine Learning

Docker

  • Platform for simplifying development using containers

Containers:

  • Package application into standalone assets
  • Containers designed as platform-agnostic
  • Get Docker

 

DataCamp Docker Course

Docker logo

End-to-End Machine Learning

Docker usage part 1

Dockerfile: instructions for building container

# Use an official Python runtime as a parent image
FROM Python:3.7

# Set the working directory in the container to /app WORKDIR /ML_pipeline
# Copy the current directory contents into the container at /app ADD . /ML_pipeline
# Install any needed packages specified in requirements.txt RUN pip install --no-cache-dir -r requirements.txt
End-to-End Machine Learning

Docker usage part 2

# ... continued
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["Python", "ML_pipeline.py"]

Build the defined image:

docker build -t heart_disease_model .
End-to-End Machine Learning

Tagging containers

Tagging:

docker tag heart_disease_model:latest heart_disease_model:1.0
  • Makes images / containers easier to identify and manage.
  • Helps in maintaining a detailed and robust model registry.
  • After tagging, we are ready to deploy!

Deployment visualized as an arrow

End-to-End Machine Learning

Best practices

While Docker makes packaging models easy...

  • Be security-minded
  • Don't include sensitive data
  • Use trusted images (from verified developers)

If you application does have sensitive information...

  • Use environment variables
  • Eg: for connection strings/passwords

Security lock

End-to-End Machine Learning

Let's practice!

End-to-End Machine Learning

Preparing Video For Download...