-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from State-of-The-MLOps/feature/atmos_train
Feature/atmos train
- Loading branch information
Showing
20 changed files
with
998 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
*.pkl | ||
__pycache__ | ||
tf_model/**/* | ||
log.txt | ||
log.txt | ||
experiments/**/temp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
repos: | ||
|
||
- repo: https://github.com/pre-commit/mirrors-autopep8 | ||
rev: 'v1.5.7' | ||
- repo: https://github.com/psf/black | ||
rev: 20.8b1 | ||
hooks: | ||
- id: autopep8 | ||
- id: black | ||
language_version: python3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
# MLOps | ||
๐ Build MLOps system step by step ๐ | ||
๐ Build MLOps system step by step ๐ | ||
|
||
## ๋ฌธ์ | ||
|
||
- [API DOCS](./docs/api-list.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,111 @@ | ||
# -*- coding: utf-8 -*- | ||
import multiprocessing | ||
import os | ||
import re | ||
import subprocess | ||
|
||
|
||
from fastapi import APIRouter | ||
|
||
from app.utils import write_yml | ||
from app.utils import NniWatcher, ExprimentOwl, base_dir, check_expr_over, get_free_port, write_yml | ||
from logger import L | ||
|
||
|
||
router = APIRouter( | ||
prefix="/train", | ||
tags=["train"], | ||
responses={404: {"description": "Not Found"}} | ||
prefix="/train", tags=["train"], responses={404: {"description": "Not Found"}} | ||
) | ||
|
||
|
||
@router.put("/") | ||
@router.put("/insurance") | ||
def train_insurance( | ||
PORT: int = 8080, | ||
experiment_sec: int = 20, | ||
experiment_name: str = 'exp1', | ||
experimenter: str = 'DongUk', | ||
model_name: str = 'insurance_fee_model', | ||
version: float = 0.1 | ||
experiment_name: str = "exp1", | ||
experimenter: str = "DongUk", | ||
model_name: str = "insurance_fee_model", | ||
version: float = 0.1, | ||
): | ||
""" | ||
insurance์ ๊ด๋ จ๋ ํ์ต์ ์คํํ๊ธฐ ์ํ API์ ๋๋ค. | ||
Args: | ||
PORT (int): PORT to run NNi. Defaults to 8080 | ||
experiment_sec (int): Express the experiment time in seconds Defaults to 20 | ||
experiment_name (str): experiment name Defaults to exp1 | ||
experimeter (str): experimenter (author) Defaults to DongUk | ||
model_name (str): model name Defaults to insurance_fee_model | ||
version (float): version of experiment Defaults to 0.1 | ||
experiment_name (str): ์คํ์ด๋ฆ. ๊ธฐ๋ณธ ๊ฐ: exp1 | ||
experimenter (str): ์คํ์์ ์ด๋ฆ. ๊ธฐ๋ณธ ๊ฐ: DongUk | ||
model_name (str): ๋ชจ๋ธ์ ์ด๋ฆ. ๊ธฐ๋ณธ ๊ฐ: insurance_fee_model | ||
version (float): ์คํ์ ๋ฒ์ . ๊ธฐ๋ณธ ๊ฐ: 0.1 | ||
Returns: | ||
msg: Regardless of success or not, return address values including PORT. | ||
msg: ์คํ ์คํ์ ์ฑ๊ณต๊ณผ ์๊ด์์ด ํฌํธ๋ฒํธ๋ฅผ ํฌํจํ NNI Dashboard์ ์ฃผ์๋ฅผ ๋ฐํํฉ๋๋ค. | ||
Note: | ||
์คํ์ ์ต์ข ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ์ง ์์ต๋๋ค. | ||
""" | ||
PORT = get_free_port() | ||
L.info( | ||
f"Train Args info\n\texperiment_sec: {experiment_sec}\n\texperiment_name: {experiment_name}\n\texperimenter: {experimenter}\n\tmodel_name: {model_name}\n\tversion: {version}") | ||
path = 'experiments/insurance/' | ||
f"Train Args info\n\texperiment_name: {experiment_name}\n\texperimenter: {experimenter}\n\tmodel_name: {model_name}\n\tversion: {version}" | ||
) | ||
path = "experiments/insurance/" | ||
try: | ||
L.info("Start NNi") | ||
write_yml( | ||
path, | ||
experiment_name, | ||
experimenter, | ||
model_name, | ||
version | ||
) | ||
subprocess.Popen( | ||
"nnictl create --port {} --config {}/{}.yml && timeout {} && nnictl stop --port {}".format( | ||
PORT, path, model_name, experiment_sec, PORT), | ||
shell=True, | ||
write_yml(path, experiment_name, experimenter, model_name, version) | ||
nni_create_result = subprocess.getoutput( | ||
"nnictl create --port {} --config {}/{}.yml".format(PORT, path, model_name) | ||
) | ||
sucs_msg = "Successfully started experiment!" | ||
|
||
if sucs_msg in nni_create_result: | ||
p = re.compile(r"The experiment id is ([a-zA-Z0-9]+)\n") | ||
expr_id = p.findall(nni_create_result)[0] | ||
nni_watcher = NniWatcher(expr_id, experiment_name, experimenter, version) | ||
m_process = multiprocessing.Process(target=nni_watcher.excute) | ||
m_process.start() | ||
|
||
L.info(nni_create_result) | ||
return nni_create_result | ||
|
||
except Exception as e: | ||
L.error(e) | ||
return {'error': str(e)} | ||
return {"error": str(e)} | ||
|
||
|
||
@router.put("/atmos") | ||
def train_atmos(expr_name: str): | ||
""" | ||
์จ๋ ์๊ณ์ด๊ณผ ๊ด๋ จ๋ ํ์ต์ ์คํํ๊ธฐ ์ํ API์ ๋๋ค. | ||
Args: | ||
expr_name(str): NNI๊ฐ ์คํํ ์คํ์ ์ด๋ฆ ์ ๋๋ค. ์ด ํ๋ผ๋ฏธํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก project_dir/experiments/[expr_name] ๊ฒฝ๋ก๋ก ์ฐพ์๊ฐ config.yml์ ์ด์ฉํ์ฌ NNI๋ฅผ ์คํํฉ๋๋ค. | ||
return {"msg": f'Check out http://127.0.0.1:{PORT}'} | ||
Returns: | ||
str: NNI์คํ์ด ์คํ๋ ๊ฒฐ๊ณผ๊ฐ์ ๋ฐํํ๊ฑฐ๋ ์คํ๊ณผ์ ์์ ๋ฐ์ํ ์๋ฌ ๋ฉ์ธ์ง๋ฅผ ๋ฐํํฉ๋๋ค. | ||
Note: | ||
์คํ์ ์ต์ข ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ์ง ์์ต๋๋ค. | ||
""" | ||
|
||
nni_port = get_free_port() | ||
expr_path = os.path.join(base_dir, "experiments", expr_name) | ||
|
||
try: | ||
nni_create_result = subprocess.getoutput( | ||
"nnictl create --port {} --config {}/config.yml".format(nni_port, expr_path) | ||
) | ||
sucs_msg = "Successfully started experiment!" | ||
|
||
if sucs_msg in nni_create_result: | ||
p = re.compile(r"The experiment id is ([a-zA-Z0-9]+)\n") | ||
expr_id = p.findall(nni_create_result)[0] | ||
check_expr = ExprimentOwl(expr_id, expr_name, expr_path) | ||
check_expr.add("update_tfmodeldb") | ||
check_expr.add("modelfile_cleaner") | ||
|
||
m_process = multiprocessing.Process( | ||
target=check_expr.execute | ||
) | ||
m_process.start() | ||
|
||
L.info(nni_create_result) | ||
return nni_create_result | ||
|
||
else: | ||
L.error(nni_create_result) | ||
return {"error": nni_create_result} | ||
|
||
except Exception as e: | ||
L.error(e) | ||
return {"error": str(e)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.