Skip to content

Commit b01e5ac

Browse files
committed
move download path to under mnt
Signed-off-by: Sunyanan Choochotkaew <[email protected]>
1 parent 91ae466 commit b01e5ac

File tree

15 files changed

+49
-59
lines changed

15 files changed

+49
-59
lines changed

cmd/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
UTC_OFFSET_TIMEDELTA = datetime.datetime.utcnow() - datetime.datetime.now()
1414
data_path = os.getenv("CPE_DATAPATH", data_path)
1515

16-
# set model top path to data path
17-
os.environ['MODEL_PATH'] = data_path
18-
1916
cur_path = os.path.join(os.path.dirname(__file__), '.')
2017
sys.path.append(cur_path)
2118
src_path = os.path.join(os.path.dirname(__file__), '..', 'src')
@@ -749,6 +746,9 @@ def export(args):
749746

750747

751748
if __name__ == "__main__":
749+
# set model top path to data path
750+
os.environ['MODEL_PATH'] = data_path
751+
752752
# Create an ArgumentParser object
753753
parser = argparse.ArgumentParser(description="Kepler model server entrypoint")
754754
parser.add_argument("command", type=str, help="The command to execute.")

manifests/base/patch/patch-estimator-sidecar.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ spec:
3737
readOnly: true
3838
- mountPath: /tmp
3939
name: tmp
40+
- mountPath: /mnt
41+
name: mnt
4042
volumes:
4143
- emptyDir: {}
42-
name: tmp
44+
name: tmp
45+
- emptyDir: {}
46+
name: mnt

manifests/offline-trainer/offline-trainer.yaml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
apiVersion: v1
2-
kind: ConfigMap
3-
metadata:
4-
name: kepler-model-server-cfm
5-
namespace: system
6-
data:
7-
MODEL_PATH: /data/models
8-
---
91
apiVersion: apps/v1
102
kind: Deployment
113
metadata:
@@ -31,7 +23,7 @@ spec:
3123
configMap:
3224
name: kepler-model-server-cfm
3325
- emptyDir: {}
34-
name: model-data
26+
name: mnt
3527
containers:
3628
- name: offline-trainer
3729
image: kepler_model_server
@@ -43,8 +35,8 @@ spec:
4335
- name: cfm
4436
mountPath: /etc/kepler/kepler.config
4537
readOnly: true
46-
- name: model-data
47-
mountPath: /data
38+
- name: mnt
39+
mountPath: /mnt
4840
readOnly: false
4941
command: [ "python3.8" ]
5042
args: ["-u", "src/train/offline_trainer.py" ]

manifests/server/online-train/patch-trainer.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
kind: ConfigMap
33
metadata:
44
name: kepler-model-server-cfm
5-
namespace: system
5+
namespace: kepler
66
data:
77
PROM_SERVER: 'http://prometheus-k8s.monitoring.svc.cluster.local:9090'
88
PROM_QUERY_INTERVAL: '20'
@@ -14,7 +14,7 @@ apiVersion: apps/v1
1414
kind: Deployment
1515
metadata:
1616
name: kepler-model-server
17-
namespace: system
17+
namespace: kepler
1818
spec:
1919
template:
2020
spec:
@@ -27,8 +27,8 @@ spec:
2727
- name: cfm
2828
mountPath: /etc/kepler/kepler.config
2929
readOnly: true
30-
- name: model-data
31-
mountPath: /data
30+
- name: mnt
31+
mountPath: /mnt
3232
readOnly: false
3333
command: [ "python3.8" ]
3434
args: ["-u", "src/train/online_trainer.py" ]

manifests/server/server.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ kind: ConfigMap
33
metadata:
44
name: kepler-model-server-cfm
55
namespace: system
6-
data:
7-
MODEL_PATH: /data/models
86
---
97
apiVersion: apps/v1
108
kind: Deployment
@@ -31,7 +29,7 @@ spec:
3129
configMap:
3230
name: kepler-model-server-cfm
3331
- emptyDir: {}
34-
name: model-data
32+
name: mnt
3533
containers:
3634
- name: server-api
3735
image: kepler_model_server
@@ -43,8 +41,8 @@ spec:
4341
- name: cfm
4442
mountPath: /etc/kepler/kepler.config
4543
readOnly: true
46-
- name: model-data
47-
mountPath: /data
44+
- name: mnt
45+
mountPath: /mnt
4846
readOnly: false
4947
command: [ "python3.8" ]
5048
args: ["-u", "src/server/model_server.py" ]

src/estimate/estimator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, metrics, values, output_type, source, system_features, system
3737
from archived_model import get_achived_model
3838
from model import load_downloaded_model
3939
from loader import get_download_output_path
40-
from config import set_env_from_model_config, SERVE_SOCKET
40+
from config import set_env_from_model_config, SERVE_SOCKET, download_path
4141
from train_types import is_support_output_type
4242

4343
loaded_model = dict()
@@ -56,7 +56,7 @@ def handle_request(data):
5656
output_type = ModelOutputType[power_request.output_type]
5757

5858
if output_type.name not in loaded_model:
59-
output_path = get_download_output_path(power_request.energy_source, output_type)
59+
output_path = get_download_output_path(download_path, power_request.energy_source, output_type)
6060
if not os.path.exists(output_path):
6161
# try connecting to model server
6262
output_path = make_request(power_request)

src/estimate/model/model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
sys.path.append(cur_path)
1212

1313
from loader import load_metadata, get_download_output_path
14+
from config import download_path
1415
from prom_types import TIMESTAMP_COL, valid_container_query
1516

1617
from scikit_model import ScikitModel
@@ -132,5 +133,5 @@ def load_model(model_path):
132133

133134
# download model folder has no subfolder of energy source and feature group because it has been already determined by model request
134135
def load_downloaded_model(energy_source, output_type):
135-
model_path = get_download_output_path(energy_source, output_type)
136+
model_path = get_download_output_path(download_path, energy_source, output_type)
136137
return load_model(model_path)

src/estimate/model_server_connector.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
util_path = os.path.join(os.path.dirname(__file__), '..', 'util')
1010
sys.path.append(util_path)
1111

12-
from config import is_model_server_enabled, get_model_server_req_endpoint, get_model_server_list_endpoint
13-
from loader import get_download_path, get_download_output_path
12+
from config import is_model_server_enabled, get_model_server_req_endpoint, get_model_server_list_endpoint, download_path
13+
from loader import get_download_output_path
1414
from train_types import ModelOutputType
1515

1616
def make_model_request(power_request):
@@ -19,8 +19,8 @@ def make_model_request(power_request):
1919
TMP_FILE = 'tmp.zip'
2020

2121
def unpack(energy_source, output_type, response, replace=True):
22-
output_path = get_download_output_path(energy_source, output_type)
23-
tmp_filepath = os.path.join(get_download_path(), TMP_FILE)
22+
output_path = get_download_output_path(download_path, energy_source, output_type)
23+
tmp_filepath = os.path.join(download_path, TMP_FILE)
2424
if os.path.exists(output_path):
2525
if not replace:
2626
# delete downloaded file

src/server/model_server.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
sys.path.append(util_path)
1414

1515
from util.train_types import get_valid_feature_groups, ModelOutputType, FeatureGroups, FeatureGroup
16-
from util.config import getConfig, model_toppath, ERROR_KEY, MODEL_SERVER_MODEL_REQ_PATH, MODEL_SERVER_MODEL_LIST_PATH, initial_pipeline_url
16+
from util.config import getConfig, model_toppath, ERROR_KEY, MODEL_SERVER_MODEL_REQ_PATH, MODEL_SERVER_MODEL_LIST_PATH, initial_pipeline_url, download_path
1717
from util.loader import parse_filters, is_valid_model, load_json, load_weight, get_model_group_path, get_archived_file, METADATA_FILENAME, CHECKPOINT_FOLDERNAME, get_pipeline_path, any_node_type, is_matched_type
1818

1919
###############################################
@@ -179,15 +179,16 @@ def load_init_pipeline():
179179
# unpack pipeline
180180
try:
181181
TMP_FILE = 'tmp.zip'
182-
with codecs.open(TMP_FILE, 'wb') as f:
182+
tmp_filepath = os.path.join(download_path, TMP_FILE)
183+
with codecs.open(tmp_filepath, 'wb') as f:
183184
f.write(response.content)
184-
shutil.unpack_archive(TMP_FILE, default_pipeline)
185-
except:
186-
print("failed to unpack downloaded pipeline.")
185+
shutil.unpack_archive(tmp_filepath, default_pipeline)
186+
except Exception as e:
187+
print("failed to unpack downloaded pipeline: ", e)
187188
return
188189

189190
# remove downloaded zip
190-
os.remove(TMP_FILE)
191+
os.remove(tmp_filepath)
191192
print("initial pipeline is loaded to {}".format(default_pipeline))
192193

193194
if __name__ == '__main__':

src/util/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
# can be read only (for configmap mount)
2222
CONFIG_PATH = "/etc/kepler/kepler.config"
2323

24+
DOWNLOAD_FOLDERNAME = "download"
25+
MODEL_FOLDERNAME = "models"
26+
2427
DEFAULT_TOTAL_SOURCE = "acpi"
2528
DEFAULT_COMPONENTS_SOURCE = "rapl"
2629
TOTAL_KEY = "TOTAL"
@@ -62,11 +65,8 @@ def getPath(subpath):
6265

6366
initial_pipeline_url = getConfig('INITIAL_PIPELINE_URL', get_pipeline_url())
6467

65-
default_model_path = os.path.join(os.path.dirname(__file__), '..', 'models')
66-
model_toppath = getPath(getConfig('MODEL_PATH', default_model_path))
67-
68-
if not os.path.exists(model_toppath):
69-
os.mkdir(model_toppath)
68+
model_toppath = getConfig('MODEL_PATH', getPath(MODEL_FOLDERNAME))
69+
download_path = getConfig('MODEL_PATH', getPath(DOWNLOAD_FOLDERNAME))
7070

7171
ERROR_KEY = 'mae'
7272
ERROR_KEY = getConfig('ERROR_KEY', ERROR_KEY)

0 commit comments

Comments
 (0)