-
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 #10 from State-of-The-MLOps/feature/training_api
Add training API
- Loading branch information
Showing
4 changed files
with
137 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
from app.utils import write_yml | ||
import subprocess | ||
|
||
from fastapi import APIRouter | ||
|
||
|
||
router = APIRouter( | ||
prefix="/train", | ||
tags=["train"], | ||
responses={404: {"description": "Not Found"}} | ||
) | ||
|
||
|
||
@router.put("/") | ||
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 | ||
): | ||
""" | ||
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 | ||
Returns: | ||
msg: Regardless of success or not, return address values including PORT. | ||
""" | ||
path = 'experiments/insurance/' | ||
try: | ||
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, | ||
) | ||
|
||
except Exception as e: | ||
print('error') | ||
print(e) | ||
|
||
return {"msg": f'Check out http://127.0.0.1:{PORT}'} |
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
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