Skip to content

๐Ÿ‘Š Build MLOps system step by step ๐Ÿ‘Š

Notifications You must be signed in to change notification settings

dramancompany/MLOps-solutions

ย 
ย 

Repository files navigation

MLOps project

๐Ÿš€ ํ”„๋กœ์ ํŠธ ๋ชฉํ‘œ ๐Ÿš€

์ง€์†๊ฐ€๋Šฅํ•œ AI ์„œ๋น„์Šค๋ฅผ ์œ„ํ•œ MLOps System ๊ตฌ์„ฑ

๋™์šฑ์ด ๋ฐ”๋ณด



1. ํ”„๋กœ์ ํŠธ ์†Œ๊ฐœ

์ €ํฌ ํ”„๋กœ์ ํŠธ๋Š” ์—ฌ๋Ÿฌ Phase๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ ๋‹จ๋ฝ์—์„œ ๊ฐ Phase์— ๋Œ€ํ•˜์—ฌ ๊ฐ„๋žตํžˆ ์„ค๋ช…ํ•˜์˜€๊ณ , ๊ฐ ๋‹จ๊ณ„์—์„œ ๊ตฌํ˜„ํ•œ ๊ตฌ์ฒด์ ์ธ ๋‚ด์šฉ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์„ค๋ช…์€ ์•„๋ž˜์— ๋”ฐ๋กœ ๊ธฐ์ˆ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.


Phase 2

  • Phase2์—์„œ๋Š” MLOps level 1์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • Git Action๊ณผ Kubernetes๋ฅผ ์ด์šฉํ•˜์—ฌ CD/CT๋ฅผ ๋„์ž…ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • hyperparameter tuning process๋ฅผ NNI์—์„œ ray๋ฅผ ์ด์šฉํ•ด ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋ณ€๊ฒฝํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์ด๋กœ์ธํ•˜์—ฌ ํ•„์š”ํ•˜์ง€ ์•Š๊ฒŒ๋œ ์ฝ”๋“œ๋“ค์ด ์ƒ๊ฒจ๋‚ฌ๊ณ  ๋ชจ๋‘ deprecated๋กœ ์ด๋™ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • Workflow๊ด€๋ฆฌ๋„๊ตฌ๋กœ prefect๋ฅผ ๋„์ž…ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • predict API๋ฅผ ์ฒ˜์Œ ํ˜ธ์ถœํ•˜์˜€์„ ๋•Œ ๋ชจ๋ธ์„ ๋กœ๋”ฉํ•˜๋Š” ์‹œ๊ฐ„์ด ๊ธธ์–ด์ ธ ํ•œ๋ฒˆ ํ˜ธ์ถœ๋œ ๋ชจ๋ธ์€ ์ผ์ •์‹œ๊ฐ„ ์บ์‹ฑํ•ด๋‘๋„๋ก ๋ณ€๊ฒฝํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • ํด๋Ÿฌ์Šคํ„ฐ ๋ชจ๋‹ˆํ„ฐ๋ง์„ ์œ„ํ•ด prometheus์™€ grafana๋ฅผ ๋„์ž…ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • 2021.10.06 ~ 2021.11.13 ๊ธฐ๊ฐ„๋™์•ˆ ์ง„ํ–‰๋˜์—ˆ์œผ๋ฉฐ ํ˜„์žฌ ๊ฐœ๋ฐœ์ข…๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

Phase 1

  • Phase 1์—์„œ๋Š” MLOps level 0๋ฅผ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • NNI๋ฅผ ์ด์šฉํ•˜์—ฌ hyperparameter tuning์„ ์ง„ํ–‰ํ•˜๋ฉฐ ํ•™์Šต๋œ ๋ชจ๋ธ์— ๋Œ€ํ•œ predict API์™€ ๋ชจ๋ธํ•™์Šต ํŒŒ์ดํ”„๋ผ์ธ์„ ์‹คํ–‰์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” train API๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
  • 2021.08.28 ~ 2021.10.06 ๊ธฐ๊ฐ„๋™์•ˆ ์ง„ํ–‰๋˜์—ˆ์œผ๋ฉฐ ํ˜„์žฌ ๊ฐœ๋ฐœ์ข…๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.


2. ํ”„๋กœ์ ํŠธ ์‹คํ–‰ํ•ด๋ณด๊ธฐ

Phase2 ํ”„๋กœ์ ํŠธ ์‹คํ–‰ํ•ด๋ณด๊ธฐ
Phase1 ํ”„๋กœ์ ํŠธ ์‹คํ–‰ํ•ด๋ณด๊ธฐ



3. Phase2(2021.10.06 ~ 2021.11.13)

3.1. Phase2 ์ฃผ์š”๊ธฐ๋Šฅ

Phase2 ๋‹จ๊ณ„์—์„œ๋Š” MLOps level 1์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•˜์—ฌ ๋…ธ๋ ฅํ•˜์˜€์Šต๋‹ˆ๋‹ค.


3.1.1. ์ „์ฒด ํ๋ฆ„๋„


3.1.2. ์‹คํ—˜๊ด€๋ฆฌ ๋ฐ ๋ชจ๋ธํ•™์Šต

Model artifacts

  • MLflow๋ฅผ ์ด์šฉํ•˜์—ฌ Google Cloud Storage์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

์„ฑ๋Šฅํ‰๊ฐ€์ง€ํ‘œ, ์ ์ˆ˜, ๊ฐ ์‹คํ—˜์—์„œ ์‚ฌ์šฉ๋œ ํ•˜์ดํผํŒŒ๋ผ๋ฏธํ„ฐ

  • MLflow๋ฅผ ์ด์šฉํ•˜์—ฌ PostgreSQL์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

AutoML

  • Ray tune์„ ์ด์šฉํ•˜์—ฌ ํ•˜์ดํผํŒŒ๋ผ๋ฏธํ„ฐ ์„œ์นญ์„ ํ•ฉ๋‹ˆ๋‹ค.

workflow management

  • ์ฒ˜์Œ์—” ํฌ๋ก ํƒญ์„ ๊ณ ๋ คํ•˜์˜€์ง€๋งŒ ์ตœ์ข…์ ์œผ๋กœ Prefect๋ฅผ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • web UI๋ฅผ ์ œ๊ณตํ•˜์—ฌ ์ˆ˜๋™์œผ๋กœ workflow๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ์‰ฝ๊ฒŒ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์ฃผ๊ธฐ์ ์ธ ์‹คํ–‰์ด ํ•„์š”ํ•œ workflow๋“ค์„ ๋ฆฌ๋ˆ…์Šค์˜ ํฌ๋ก ํƒญ๊ณผ ๋™์ผํ•œ ๋ฌธ๋ฒ•์œผ๋กœ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    ex) 10 6 * * 1 โ†’ ๋งค์ฃผ ์›”์š”์ผ 6์‹œ 10๋ถ„์— workflow ์‹คํ–‰

cluster monitoring

  • GCP์—์„œ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•  ๋‹น์‹œ ํด๋Ÿฌ์Šคํ„ฐ์˜ ๊ฐ€์šฉ์ž์› ๋ชจ๋‹ˆํ„ฐ๋ง์„ ์œ„ํ•˜์—ฌ Prometheus์™€ Grafana๋ฅผ ๋„์ž…ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • ๊ทธ๋ผํŒŒ๋‚˜์—์„œ ์ œ๊ณต์ค‘์ธ 13077, 315 ๋Œ€์‹œ๋ณด๋“œ๋ฅผ ์ด์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

3.1.3. Inference API

  • MLํŒŒ์ดํ”„๋ผ์ธ์— ์˜ํ•ด ์ƒ์„ฑ๋œ ๋ชจ๋ธ์„ ์ด์šฉํ•œ inference ๊ฒฐ๊ณผ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
  • API server๋Š” inference ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด ํ•ด๋‹น ๋ชจ๋ธ์ด ์บ์‹ฑ๋˜์–ด์žˆ๋Š”์ง€ ํ™•์ธํ•œ ํ›„ ์—†์œผ๋ฉด MLflow server์™€ ํ†ต์‹ ํ•˜์—ฌ ๋ชจ๋ธ์„ ๋กœ๋“œํ•œ ํ›„ ์š”์ฒญ์‚ฌํ•ญ์„ ์ฒ˜๋ฆฌํ•˜์—ฌ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
  • Fast API๋ฅผ ์ด์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

3.2. Phase2 ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ…

  • Phase1์—์„œ๋Š” NNI๋ฅผ ์‚ฌ์šฉํ•˜์˜€์ง€๋งŒ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ด์œ ๋กœ Ray Tune์œผ๋กœ ๋ณ€๊ฒฝํ•˜์˜€์Šต๋‹ˆ๋‹ค. ํ•ด๊ฒฐํ•œ ๋ฐฉ๋ฒ•
  • GCP๋กœ ์„œ๋ฒ„๋ฅผ ์ด์ „ํ•œ ํ›„ MLflow์—์„œ ๋ชจ๋ธ์„ ๋กœ๋“œํ•˜๋Š” ์‹œ๊ฐ„์ด ์•ฝ 10์ดˆ๋กœ ๋งค์šฐ ๋Šฆ์–ด์กŒ์Šต๋‹ˆ๋‹ค. ํ•ด๊ฒฐํ•œ ๋ฐฉ๋ฒ•


4. Phase1(2021.08.28 ~ 2021.10.06)

4.1. Phase1 ์ฃผ์š”๊ธฐ๋Šฅ

  • Phase1์—์„œ๋Š” MLOps level 0๋ฅผ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•˜์—ฌ ๋…ธ๋ ฅํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • train์€ experiments ํด๋”์— ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
    • ๋ณธ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ์–ด๋Š์ •๋„์˜ ์ž๋™ํ™”๋œ ๋ชจ์Šต์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด train์„ apiํ˜•ํƒœ๋กœ ์š”์ฒญํ•  ์ˆ˜ ์žˆ๊ฒŒ ๊ตฌ์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.
    • train ์š”์ฒญ์—๋”ฐ๋ผ subprocess๋กœ NNi๋ฅผ ์ด์šฉํ•œ hyper parameter tuning์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
    • ๊ฐ ์‹คํ—˜๊ฒฐ๊ณผ best๋ชจ๋ธ์„ ํ˜„์žฌ ์ €์žฅ๋œ ๋ชจ๋ธ ์„ฑ๋Šฅ๊ณผ ๋น„๊ตํ•˜์—ฌ db์— ์ง๋ ฌํ™”์‹œ์ผœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
  • predict๋Š” app/api/router/predict.py ์— ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
    • prediction์š”์ฒญ์— ๋”ฐ๋ผ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
    • temp์˜ˆ์ธก์˜ ๊ฒฝ์šฐ ์„œ๋ฒ„ ์‹œ์ž‘์‹œ ๋ชจ๋ธ์„ ๋กœ๋“œํ•˜์—ฌ ๋ชจ๋ธ์„ ๋งค๋ฒˆ ์ฝ์–ด์˜ค์ง€ ์•Š๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.
    • insurance์˜ˆ์ธก์˜ ๊ฒฝ์šฐ db์—์„œ ๋งค๋ฒˆ ๋ชจ๋ธ์„ ์ฝ์–ด์™€ ์˜ˆ์ธก์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  • logger
    • ์š”์ฒญ, ์‹คํ—˜์ง„ํ–‰ ๋“ฑ์„ log๋กœ ๋‚จ๊น๋‹ˆ๋‹ค.

4.2. Phase1 ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ…

About

๐Ÿ‘Š Build MLOps system step by step ๐Ÿ‘Š

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.5%
  • Shell 0.5%