-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmodel_manager.py
More file actions
94 lines (83 loc) · 2.81 KB
/
model_manager.py
File metadata and controls
94 lines (83 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import argparse
import logging
import traceback
import yaml
logging.getLogger("sagemaker.config").setLevel(logging.WARNING)
logging.getLogger("botocore.credentials").setLevel(logging.WARNING)
import os
from src.sagemaker.create_model import deploy_huggingface_model, deploy_model
from src.sagemaker.fine_tune_model import fine_tune_model
from src.schemas.deployment import Deployment
from src.schemas.model import Model
if __name__ == '__main__':
# Run setup if these files/directories don't already exist
if (not os.path.exists(os.path.expanduser('~/.aws')) or not os.path.exists('.env')):
os.system("bash setup.sh")
parser = argparse.ArgumentParser(
description="Create, deploy, query against models.",
epilog="As an alternative to the commandline, params can be placed in a file, one per line, and specified on the commandline like '%(prog)s @params.conf'.",
fromfile_prefix_chars='@')
parser.add_argument(
"--hf",
help="Deploy a Hugging Face Model.",
type=str
)
parser.add_argument(
"--instance",
help="EC2 instance type to deploy to.",
type=str
)
parser.add_argument(
"--deploy",
help="path to YAML deployment configuration file",
type=str
)
parser.add_argument(
"--train",
help="path to YAML training configuration file",
type=str
)
parser.add_argument(
"-v",
"--verbose",
help="increase output verbosity",
action="store_true")
args = parser.parse_args()
# Setup logging
if args.verbose:
loglevel = logging.DEBUG
else:
loglevel = logging.INFO
if args.hf is not None:
instance_type = args.instance or "ml.m5.xlarge"
predictor = deploy_huggingface_model(args.hf, instance_type)
quit()
if args.deploy is not None:
try:
deployment = None
model = None
with open(args.deploy) as config:
configuration = yaml.safe_load(config)
deployment = configuration['deployment']
# TODO: Support multi-model endpoints
model = configuration['models'][0]
deploy_model(deployment, model)
except:
traceback.print_exc()
print("File not found")
quit()
if args.train is not None:
try:
train = None
model = None
with open(args.train) as config:
configuration = yaml.safe_load(config)
training = configuration['training']
model = configuration['models'][0]
fine_tune_model(training, model)
except:
traceback.print_exc()
print("File not found")
quit()
from src.main import main
main(args, loglevel)