2022. 4. 14. 22:17ใ๐ Data Engineering/MLOps
์ต๊ทผ MLOps๋ ๋จ์ด๊ฐ ๋ง์ด ๋ฑ์ฅํ๋ค.
MLOps : ํ๋ก๋์ ํ๊ฒฝ์์ ๊ธฐ๊ณํ์ต์ ์์ ์ ์ผ๋ก ์ํํ๊ธฐ ์ํ ์ผ๋ จ์ ๊ณผ์
MLOps = DevOps + Machine Learning
๋ฐ์ดํฐ ์ ์ฒ๋ฆฌ, ๋ถ์, ๋ชจ๋ธ๋ง์ ์ฃผ๋ก ๊ณต๋ถํด์์ง๋ง, ์ต๊ทผ ๋ค์ด ์ด๋ฐ ์์คํ ์ ํ์์ฑ์ ๋๊ผ๋ค.
๋งค ๋ถ์ ์๊ฐ๋ง๋ค ์ ์ฒ๋ฆฌ-EDA-FE-Modeling-๊ฒ์ฆ ๊ณผ์ ์ ๊ฑฐ์น๋ฉด ์๊ฐ์ด ๋ง์ด ๋ ๋ค.
๋ชจ๋ธ์ ์ ์ฅํ๊ณ , ๋ค์ ์๋นํ๋ ๊ณผ์ ๋ ๊ฐํธํ๋ ํ์๊ฐ ์๋ค.
๊ทธ๋ฐ ์๊ฐ์ ํ๋ฆ์์ MLflow๋ฅผ ๊ณต๋ถํ๊ฒ ๋์์ผ๋ฉฐ, ๊ณต๋ถํ ๊ฒ๋ค์ ๋ธ๋ก๊ทธ๋ก ์ ๋ฆฌํด๋ณด๊ณ ์ ํ๋ค.
[์ฐธ๊ณ ์๋ฃ]
https://github.com/mlflow/mlflow/
GitHub - mlflow/mlflow: Open source platform for the machine learning lifecycle
Open source platform for the machine learning lifecycle - GitHub - mlflow/mlflow: Open source platform for the machine learning lifecycle
github.com
https://mlflow.org/docs/latest/quickstart.html
Quickstart — MLflow 1.25.1 documentation
Downloading the Quickstart Download the quickstart code by cloning MLflow via git clone https://github.com/mlflow/mlflow, and cd into the examples subdirectory of the repository. We’ll use this working directory for running the quickstart. We avoid runni
mlflow.org
1. MLflow ๊ฐ๋
A Machine Learning Lifecycle Platform
๋จธ์ ๋ฌ๋์ ์คํํ๊ณ , ๋ฐฐํฌํ๋ ๊ฒ์ ์ฝ๊ฒ ๊ด๋ฆฌํ ์ ์๋ ์คํ์์ค
* GUI, CLI๋ฅผ ์ง์
MLflow Main Function
1) Tracking (ํธ๋ํน)
์คํ ํ, ํ๋ผ๋ฏธํฐ์ ๊ฒฐ๊ณผ๋ฅผ ๋น๊ตํ๊ธฐ ์ํด ์คํ ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํ๋ค.
2) Projects
๋จธ์ ๋ฌ๋ ์ฝ๋๋ฅผ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ๊ณ ์ฌํ ๊ฐ๋ฅํ ํํ๋ก ๋ง๋ ๋ค.
3) Models
๋ชจ๋ธ์ ๊ด๋ฆฌํ๊ณ , ๋ฐฐํฌ, Serving, ์ถ๋ก ํฉ๋๋ค.
4) Model Registry
MLflow ๋ชจ๋ธ์ ์ ์ฒด ๋ผ์ดํ์ฌ์ดํด์ ๊ด๋ฆฌํ๊ธฐ ์ํ Centralized model store, UI.
MLflow์ ์ ๊ณผ์ ์ ์ฝ๊ฒ ์ปจํธ๋กค ํ ์ ์๋ ๋ฐฉ๋ฒ์ ๋จ๊ฒผ๋ค.
REST API, CLI๋ฅผ ํตํด ๋ชจ๋ ๊ธฐ๋ฅ์ ์ ๊ทผํ ์ ์๋ค. API๋ Python, R, Java ์กด์ฌํ๋ค.
๋๊ฒ ๋จธ์ ๋ฌ๋์ ๋๋ ค๋ณธ ์ฌ๋์ด๋ผ๋ฉด ์ ๊ฒ์ด๋ค. ์๋ฌด๋ฆฌ ํ์ดํ๋ผ์ธ์ ์ ๊ตฌ์ถํด๋๊ณ ์คํ์ ํด๋, ๋ชจ๋ธ๊ณผ ํ๋ผ๋ฏธ๋ ์๊ฐ ๋ง์์ง๋ฉด ๋ฒ๊ฑฐ๋ก์์ง๋ค. ๊ฒ๋ค๊ฐ ๋ชจ๋ธ์ ์์ธกํ ํ, ๋ฒ๋ ค์ง๋ค์ํผ ํ๋ค. ๋ชจ๋ธ์ ์ผ์ผ์ด save ํด์ ๋ชจ์๋๋ ๊ฒ๋ ๊ณจ์น ์ํ๋ค. ์ด๋ฐ ์ผ์ MLflow๊ฐ ์์ํ๊ฒ ํด ์ค๋ค๊ณ ๋ณด๋ฉด ๋๋ค.
๊ทธ๋ผ ์์ํด๋ณด์.
2. MLflow ์์ & ํด๋ก
๋จผ์ mlflow๋ฅผ ๋ค์ด๋ก๋ํ์.
pip install mlflow
์ค์ต์ ์ํด, MLflow github๋ฅผ clone ํ์.
git clone https://github.com/mlflow/mlflow
cd mlflow/examples/quickstart
mlflow_tracking.py๋ฅผ ๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.
import os
from random import random, randint
from mlflow import log_metric, log_param, log_artifacts
if __name__ == "__main__":
print("Running mlflow_tracking.py")
log_param("param1", randint(0, 100))
log_metric("foo", random())
log_metric("foo", random() + 1)
log_metric("foo", random() + 2)
if not os.path.exists("outputs"):
os.makedirs("outputs")
with open("outputs/test.txt", "w") as f:
f.write("hello world!")
log_artifacts("outputs")
์ฌ๊ธฐ์ ํ์ธํ ๊ฒ์ ์ด๋ป๊ฒ MLflow์ ์ํตํ๋ ๊ฐ์ด๋ค.
1) log_param()
ํ๋ผ๋ฏธํฐ ๋ก๊ทธ๋ฅผ MLflow db๋ก ์ ์ฅํ๋ ํจ์๋ค.
2) log_metric()
๋ชจ๋ธ ํ๊ฐ Score๋ฅผ MLflow db๋ก ์ ์ฅํ๋ ํจ์๋ค.
3) log_artifacts()
๋ชจ๋ธ ๋ฑ ๋จธ์ ๋ฌ๋ ๊ฒฐ๊ณผ๋ฌผ์ MLflow db๋ก ์ ์ฅํ๋ ํจ์๋ค.
mlflow_tracking.py๋ฅผ ์คํ์์ผ๋ณด์.
python mlflow_tracking.py
> Running mlflow_tracking.py
๋ชฉ๋ก์ ๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ์ด ๋ฌ๋ค.
1) mlruns : ๊ธฐ๋ณธ์ ์ผ๋ก mlflow์ ์คํ๋ค์ ์ ์ฅํ๋ ํด๋์ด๋ค.
2) ์ซ์ 0 : Default experiment. mlflow๋ ์ฌ์ฉ์๊ฐ ์คํ ์์์ ์ํ๋ ์คํ์ ํ ์ ์๋๋ก ํ๋ค. ๋ฐ๋ผ์ ์ฌ์ฉ์๋ ์ํ๋ ์คํ ํด๋๋ฅผ ๋ง๋ค์ด, ๊ทธ ์์์ ํน์ ์คํ์ ์งํํ ์ ์๋๋ค. ์คํ ํด๋ ๋ง๋๋ ๋ฐฉ๋ฒ์ ํ์ ์ค๋ช ํ๊ฒ ๋ค.
3) ์ผ๋ จ๋ฒํธ : ์คํ์ ํจ์ผ๋ก์จ ์ ์ฅ๋ ๋ชจ๋ธ ๊ธฐ๋ก์ด๋ค. ํ๋ํ๋๊ฐ ๋ค๋ฅธ ์คํ ๋ชจ๋ธ์ด๋ค.
์คํ์ ํ ํ, params, artifacts, metrics ํด๋์ ๊ฐ๊ฐ์ ๋ฐ์ดํฐ๊ฐ ์ ์ฅ๋๋ค.
์น ๋์๋ณด๋
์น์ ํตํด MLflow์ ์ ์ฒด์ ์ธ ์ํฉ์ ์ง๊ดํ ์ ์๋ค.
mlflow ui
ํน์ ์คํ์ ๋๋ฅด๋ฉด ํ๋ผ๋ฏธํฐ์ ๋ฉํธ๋ฆญ์ค, artifacts๋ฅผ ์์ธํ ํ์ธํ ์ ์๋ค.
์ด๋ฒ ํฌ์คํ ์ ์ฌ๊ธฐ๊น์ง. ์ฝ์๋ค.
'๐ Data Engineering > MLOps' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[MLOps] MLflow Tracking (0) | 2022.04.16 |
---|