From f9027737169755b66c477b1b51bc8111f5d7dce5 Mon Sep 17 00:00:00 2001 From: Sunyanan Choochotkaew Date: Mon, 26 Aug 2024 13:39:13 +0900 Subject: [PATCH] chore: change spec to machine_spec in server /model Signed-off-by: Sunyanan Choochotkaew --- .../estimate/model_server_connector.py | 2 +- src/kepler_model/server/model_server.py | 14 +++++++------- tests/model_select_test.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/kepler_model/estimate/model_server_connector.py b/src/kepler_model/estimate/model_server_connector.py index 78b9cb96..cab6664f 100644 --- a/src/kepler_model/estimate/model_server_connector.py +++ b/src/kepler_model/estimate/model_server_connector.py @@ -23,7 +23,7 @@ def make_model_request(power_request, machine_spec=None): "filter": power_request.filter, "trainer_name": power_request.trainer_name} if machine_spec is not None: - model_request["spec"] = machine_spec + model_request["machine_spec"] = machine_spec return model_request diff --git a/src/kepler_model/server/model_server.py b/src/kepler_model/server/model_server.py index 6a1e845b..76963e9f 100644 --- a/src/kepler_model/server/model_server.py +++ b/src/kepler_model/server/model_server.py @@ -53,7 +53,7 @@ class ModelRequest: - def __init__(self, metrics, output_type, source="rapl-sysfs", node_type=-1, weight=False, trainer_name="", filter="", pipeline_name="", spec=None, loose_node_type=True): + def __init__(self, metrics, output_type, source="rapl-sysfs", node_type=-1, weight=False, trainer_name="", filter="", pipeline_name="", machine_spec=None, loose_node_type=True): # target source of power metric to be predicted (e.g., rapl-sysfs, acpi) self.source = convert_enery_source(source) # type of node to select a model learned from similar nodes (default: -1, applied universal model learned by all node_type (TODO)) @@ -71,9 +71,9 @@ def __init__(self, metrics, output_type, source="rapl-sysfs", node_type=-1, weig # specific pipeline (default: empty, selecting default pipeline) self.pipeline_name = pipeline_name # spec of requesting node to determine node_type - self.spec = NodeTypeSpec() - if spec is not None: - self.spec = NodeTypeSpec(**spec) + self.machine_spec = NodeTypeSpec() + if machine_spec is not None: + self.machine_spec = NodeTypeSpec(**machine_spec) self.loose_node_type = loose_node_type # ModelListParams defines parameters for /best-models API @@ -194,13 +194,13 @@ def get_model(): pipeline_name = pipelineName[energy_source] valid_group_path = get_model_group_path(model_toppath, output_type, fg, energy_source, pipeline_name=pipelineName[energy_source]) node_type = req.node_type - if req.node_type == any_node_type and req.spec is not None and not req.spec.is_none() and pipeline_name in nodeCollection: - node_type, uncertainty, looseness = nodeCollection[pipeline_name].get_node_type(req.spec, loose_search=True) + if req.node_type == any_node_type and req.machine_spec is not None and not req.machine_spec.is_none() and pipeline_name in nodeCollection: + node_type, uncertainty, looseness = nodeCollection[pipeline_name].get_node_type(req.machine_spec, loose_search=True) else: uncertainty = 0 looseness = 0 if os.path.exists(valid_group_path): - best_candidate, response = select_best_model(req.spec, valid_group_path, filters, energy_source, req.pipeline_name, req.trainer_name, node_type, req.weight, loose_node_type=req.loose_node_type) + best_candidate, response = select_best_model(req.machine_spec, valid_group_path, filters, energy_source, req.pipeline_name, req.trainer_name, node_type, req.weight, loose_node_type=req.loose_node_type) if best_candidate is None: continue if node_type != any_node_type and best_model is not None and get_node_type_from_name(best_model['model_name']) == node_type: diff --git a/tests/model_select_test.py b/tests/model_select_test.py index 43144cb2..d6932160 100644 --- a/tests/model_select_test.py +++ b/tests/model_select_test.py @@ -31,7 +31,7 @@ def get_node_types(energy_source): def make_request_with_spec(metrics, output_type, node_type=-1, trainer_name="", energy_source='rapl-sysfs', spec=None): weight = False model_request = get_model_request_json(metrics, output_type, node_type, weight, trainer_name, energy_source) - model_request["spec"] = spec + model_request["machine_spec"] = spec response = requests.post(f'http://localhost:{MODEL_SERVER_PORT}/model', json=model_request) assert response.status_code == 200, response.text output_path = os.path.join(download_path, output_type.name)