การบรรจุและการจัดคอนเทนเนอร์

Machine Learning แบบ End-to-End

Joshua Stapleton

Machine Learning Engineer

การ Deploy และการจัดคอนเทนเนอร์

การ Deploy

  • บรรจุโมเดลพร้อม dependencies ไว้ในหน่วยเดียว
  • เพื่อรันในสภาพแวดล้อมที่แตกต่างกัน
  • เฟรมเวิร์กมาตรฐานสำหรับการจัดคอนเทนเนอร์และ deploy คือ Docker

ขั้นตอน Deploy ในวงจรชีวิต machine learning

Machine Learning แบบ End-to-End

Docker

  • แพลตฟอร์มสำหรับลดความซับซ้อนในการพัฒนาด้วยคอนเทนเนอร์

คอนเทนเนอร์:

  • บรรจุแอปพลิเคชันเป็น asset แบบ standalone
  • ออกแบบให้ทำงานได้บนทุกแพลตฟอร์ม
  • Get Docker

 

DataCamp Docker Course

โลโก้ Docker

Machine Learning แบบ End-to-End

การใช้งาน Docker ส่วนที่ 1

Dockerfile: คำสั่งสำหรับสร้างคอนเทนเนอร์

# 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
Machine Learning แบบ End-to-End

การใช้งาน Docker ส่วนที่ 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"]

สร้าง image ที่กำหนดไว้:

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

การ Tag คอนเทนเนอร์

การ Tag:

docker tag heart_disease_model:latest heart_disease_model:1.0
  • ช่วยให้ระบุและจัดการ image/คอนเทนเนอร์ได้ง่ายขึ้น
  • ช่วยรักษา model registry ที่ครบถ้วนและแข็งแกร่ง
  • หลัง tag แล้ว พร้อม deploy ได้เลย!

ภาพแสดงการ Deploy เป็นลูกศร

Machine Learning แบบ End-to-End

แนวปฏิบัติที่ดี

แม้ Docker จะทำให้การบรรจุโมเดลง่ายขึ้น...

  • คำนึงถึงความปลอดภัยเสมอ
  • ห้ามรวมข้อมูลที่ละเอียดอ่อน
  • ใช้ image จากแหล่งที่เชื่อถือได้ (นักพัฒนาที่ผ่านการยืนยัน)

หากแอปพลิเคชันมีข้อมูลที่ละเอียดอ่อน...

  • ใช้ environment variables
  • เช่น: สำหรับ connection string หรือรหัสผ่าน

แม่กุญแจความปลอดภัย

Machine Learning แบบ End-to-End

มาฝึกกันเถอะ!

Machine Learning แบบ End-to-End

Preparing Video For Download...