Skip to content

Commit c0fabfb

Browse files
committed
rename score_set to score_split
Signed-off-by: Zhiyuan Chen <this@zyc.ai>
1 parent a5d55f9 commit c0fabfb

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

danling/runner/base_runner.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class BaseRunner(metaclass=RunnerMeta): # pylint: disable=too-many-public-metho
8989
Scores should be in the form of `{epoch: score}`.
9090
latest_score (float, property): Most recent score, should be in the form of `score`.
9191
best_score (float, property): Best score, should be in the form of `score`.
92-
score_set (Optional[str]): The subset to calculate the score.
92+
score_split (Optional[str]): The subset to calculate the score.
9393
If is `None`, will use the last set of the result.
9494
score_name (str): The metric name of score.
9595
Defaults to `"loss"`.
@@ -114,9 +114,9 @@ class BaseRunner(metaclass=RunnerMeta): # pylint: disable=too-many-public-metho
114114
}
115115
```
116116
117-
`scores` are dynamically extracted from `results` by `score_set` and `score_name`.
117+
`scores` are dynamically extracted from `results` by `score_split` and `score_name`.
118118
They represent the core metric that is used in comparing the performance against different models and settings.
119-
For the above `results`, If `score_set = "val"`, `score_name = "accuracy"`, then `scores = 0.9`.
119+
For the above `results`, If `score_split = "val"`, `score_name = "accuracy"`, then `scores = 0.9`.
120120
121121
Attributes: IO:
122122
dir (str, property): Directory of the run.
@@ -1076,13 +1076,13 @@ def scores(self) -> FlatDict | None:
10761076
r"""
10771077
All scores.
10781078
1079-
Scores are extracted from results by `score_set` and `runner.state.score_name`,
1080-
following `[r[score_set][self.state.score_name] for r in self.results]`.
1079+
Scores are extracted from results by `score_split` and `runner.state.score_name`,
1080+
following `[r[score_split][self.state.score_name] for r in self.results]`.
10811081
10821082
Scores are considered as the index of the performance of the model.
10831083
It is useful to determine the best model and the best hyper-parameters.
10841084
1085-
`score_set` is defined in `self.state.score_set`.
1085+
`score_split` is defined in `self.state.score_split`.
10861086
If it is not set, `DanLing` will use `val` or `validate` if they appear in the `latest_result`.
10871087
If `DanLing` still could not find, it will fall back to the second key in the `latest_result`
10881088
if it contains more that one element, or the first key.
@@ -1093,14 +1093,14 @@ def scores(self) -> FlatDict | None:
10931093
if not self.results:
10941094
return None
10951095
subsets = [i for i in self.latest_result.keys() if i not in IGNORED_SET_NAMES] # type: ignore
1096-
score_set = self.state.get("score_set")
1097-
if score_set is None and "val" in subsets:
1098-
score_set = "val"
1099-
if score_set is None and "validate" in subsets:
1100-
score_set = "validate"
1101-
if score_set is None:
1102-
score_set = subsets[1] if len(subsets) > 1 else subsets[0]
1103-
return FlatDict({k: v[score_set][self.state.score_name] for k, v in self.results.items()})
1096+
score_split = self.state.get("score_split")
1097+
if score_split is None and "val" in subsets:
1098+
score_split = "val"
1099+
if score_split is None and "validate" in subsets:
1100+
score_split = "validate"
1101+
if score_split is None:
1102+
score_split = subsets[1] if len(subsets) > 1 else subsets[0]
1103+
return FlatDict({k: v[score_split][self.state.score_name] for k, v in self.results.items()})
11041104

11051105
@property
11061106
def latest_score(self) -> float | None:

danling/runner/defaults.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"steps",
88
"epochs",
99
"results",
10-
"score_set",
10+
"score_split",
1111
"score",
1212
"log_interval",
1313
"save_interval",

danling/runner/state.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class RunnerState(NestedDict): # pylint: disable=too-many-instance-attributes
104104
step_end: Optional[int] = None
105105
epoch_end: Optional[int] = None
106106

107-
score_set: Optional[str] = None
107+
score_split: Optional[str] = None
108108
score_name: str = "loss"
109109

110110
project_root: str = "experiments"

demo/vision/torch_mnist.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class MNISTConfig(dl.Config):
1414
log = False
1515
tensorboard = False
1616
log_interval = 1000
17-
score_set = "val"
17+
score_split = "val"
1818
score_name = "loss"
1919
debug = False
2020
patience = 1

tests/runner/test_base_runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self):
2929
self.log_interval = 10
3030
self.train_iterations_per_epoch = 64
3131
self.val_iterations_per_epoch = 16
32-
self.score_set = "val"
32+
self.score_split = "val"
3333
self.score = "loss"
3434
self.conflict = 1
3535

tests/runner/test_torch_runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self):
2424
self.log = False
2525
self.tensorboard = False
2626
self.log_interval = 1000
27-
self.score_set = "val"
27+
self.score_split = "val"
2828
self.score_name = "loss"
2929

3030
def post(self):

0 commit comments

Comments
 (0)