Skip to content

Commit ed619ed

Browse files
authored
Merge pull request #249 from alex-jw-brooks/remove_ops_and_metric_files
Move default operations and metrics to variables
2 parents 6f2d212 + f4440d3 commit ed619ed

File tree

3 files changed

+11
-29
lines changed

3 files changed

+11
-29
lines changed

tuning/trainercontroller/callback.py

+11-26
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# https://spdx.dev/learn/handling-license-info/
1717

1818
# Standard
19-
from importlib import resources as impresources
2019
from typing import Dict, List, Union
2120
import inspect
2221
import os
@@ -34,7 +33,6 @@
3433
import yaml
3534

3635
# Local
37-
from tuning.trainercontroller import controllermetrics, operations
3836
from tuning.trainercontroller.control import Control, OperationAction, Rule
3937
from tuning.trainercontroller.controllermetrics import (
4038
handlers as default_metric_handlers,
@@ -63,6 +61,9 @@
6361
CONTROLLER_TRIGGERS_KEY = "triggers"
6462
CONTROLLER_OPERATIONS_KEY = OPERATIONS_KEY
6563

64+
# Default operations / metrics to register
65+
DEFAULT_OPERATIONS = {"operations": [{"name": "hfcontrols", "class": "HFControls"}]}
66+
DEFAULT_METRICS = {}
6667

6768
# pylint: disable=too-many-instance-attributes
6869
class TrainerControllerCallback(TrainerCallback):
@@ -102,23 +103,15 @@ def __init__(self, trainer_controller_config: Union[dict, str]):
102103
if OPERATIONS_KEY not in self.trainer_controller_config:
103104
self.trainer_controller_config[OPERATIONS_KEY] = []
104105

105-
# Initialize the list of metrics from default `metrics.yaml` in the \
106-
# controllermetric package. In addition, any metrics mentioned in \
107-
# the trainer controller config are added to this list.
108-
default_metrics_config_yaml = (
109-
impresources.files(controllermetrics) / "metrics.yaml"
110-
)
111-
with default_metrics_config_yaml.open("r") as f:
112-
default_metrics_config = yaml.safe_load(f)
113106
if (
114-
default_metrics_config is not None
115-
and CONTROLLER_METRICS_KEY in default_metrics_config
116-
and len(default_metrics_config[CONTROLLER_METRICS_KEY]) > 0
107+
DEFAULT_METRICS
108+
and CONTROLLER_METRICS_KEY in DEFAULT_METRICS
109+
and len(DEFAULT_METRICS[CONTROLLER_METRICS_KEY]) > 0
117110
):
118111
self_controller_metrics = self.trainer_controller_config[
119112
CONTROLLER_METRICS_KEY
120113
]
121-
default_controller_metrics: list[dict] = default_metrics_config[
114+
default_controller_metrics: list[dict] = DEFAULT_METRICS[
122115
CONTROLLER_METRICS_KEY
123116
]
124117
for metric_obj in default_controller_metrics:
@@ -131,21 +124,13 @@ def __init__(self, trainer_controller_config: Union[dict, str]):
131124
if not found:
132125
self_controller_metrics.append(metric_obj)
133126

134-
# Initialize the list of operations from default `operations.yaml` \
135-
# in the operations package. In addition, any operations mentioned \
136-
# in the trainer controller config are added to this list.
137-
default_operations_config_yaml = (
138-
impresources.files(operations) / "operations.yaml"
139-
)
140-
with default_operations_config_yaml.open("r") as f:
141-
default_operations_config = yaml.safe_load(f)
142127
if (
143-
default_operations_config is not None
144-
and OPERATIONS_KEY in default_operations_config
145-
and len(default_operations_config[OPERATIONS_KEY]) > 0
128+
DEFAULT_OPERATIONS
129+
and OPERATIONS_KEY in DEFAULT_OPERATIONS
130+
and len(DEFAULT_OPERATIONS[OPERATIONS_KEY]) > 0
146131
):
147132
self_controller_operations = self.trainer_controller_config[OPERATIONS_KEY]
148-
default_controller_operations: list[dict] = default_operations_config[
133+
default_controller_operations: list[dict] = DEFAULT_OPERATIONS[
149134
OPERATIONS_KEY
150135
]
151136
for op_obj in default_controller_operations:

tuning/trainercontroller/controllermetrics/metrics.yaml

Whitespace-only changes.

tuning/trainercontroller/operations/operations.yaml

-3
This file was deleted.

0 commit comments

Comments
 (0)