Skip to content

Commit

Permalink
Merge pull request #411 from sunya-ch/server-api-rebase-patch-1
Browse files Browse the repository at this point in the history
chore: change spec to machine_spec in server /model
  • Loading branch information
sthaha authored Aug 26, 2024
2 parents 9567ebe + f902773 commit f9a4e5b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/kepler_model/estimate/model_server_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
14 changes: 7 additions & 7 deletions src/kepler_model/server/model_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/model_select_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f9a4e5b

Please sign in to comment.